Thread: Floating-Point (BCD)

  1. #1
    Registered User
    Join Date
    Oct 2004

    Floating-Point (BCD)

    Hi there!

    I'm trying to implement fp numbers that can be approximated in C with this structure:

    struct fp
         char            sign;          // 1 = negative
         unsigned short  exponent;      // 32768 = 10**0
         unsigned char   mantissa[8];   // Packed-BCD (16 digits)
    E.g. p [pi] would be stored as:
    fp.sign = 0;
    fp.exponent = 32768
    fp.mantissa = {0x31, 0x41, 0x59, 0x26, 0x53, 0x58, 0x97, 0x93};
    And what I would like to know is how to implement fast multiplication, division, and exponentiation functions.

    P.S. There isn't any FPU, in case you were wondering.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal places on Floating point number
    By manutdfan in forum C Programming
    Replies: 1
    Last Post: 10-29-2006, 12:56 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. floating point question
    By Eric Cheong in forum C Programming
    Replies: 8
    Last Post: 09-10-2004, 10:48 PM
  4. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM
  5. Replies: 2
    Last Post: 09-10-2001, 12:00 PM