Floating-Point (BCD)

This is a discussion on Floating-Point (BCD) within the C Programming forums, part of the General Programming Boards category; Hi there! I'm trying to implement fp numbers that can be approximated in C with this structure: Code: struct fp ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    151

    Floating-Point (BCD)

    Hi there!

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

    Code:
    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:
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:56 AM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21