Thread: Floating Point Bit Level Arithmetic

  1. #16
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by DanV2 View Post
    Right, like iMalc mentioned, the while loops are for normalizing the mantissa of the result. The fraction part of an IEEE Floating point number should be 23 bits with an implied 1 bit, so the while loops shift right or left as necessary to normalize the result.

    As for shifting the two FRAC values to the right, I'm not completely sure why we do, but the TA told us that it was necessary to truncate the values so that the result would fit into an integer. At least, that's what I remember from the explanation he gave.
    While it's obvious that you're trying to simulate the results of floating point division, there's no need to shift the two mantissas to the right. The thing that needs to be done tho' is right shifting the lesser of the two fractions in order to equalise them. After equalising, if numerator <= denominator, repeatedly multiply it by 10 until it becomes just greater than the denominator, specifically:
    Code:
    1 / 5
    frac1 = 1 (1.0 x 2^0 - binary)
    frac2 = 5 (1.01 x 2^2 - binary)
    frac1 >>= 2;    // equalise the magnitudes of the two fractions
    while (frac1 < frac2)
        frac1 *= 10;
    And no need to store the result of FRAC1 / FRAC2 in a float, as it can obtained thro' integer division and modulus.
    Last edited by itCbitC; 10-26-2010 at 01:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  2. Need help with floating point values
    By 69gto96z in forum C++ Programming
    Replies: 6
    Last Post: 07-18-2008, 07:01 AM
  3. String and Floating Point Conversion Help
    By dfghjk in forum C++ Programming
    Replies: 14
    Last Post: 05-04-2008, 12:11 PM
  4. bit level hacking?
    By CtrlAltKick in forum C Programming
    Replies: 5
    Last Post: 09-07-2002, 07:36 PM
  5. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM

Tags for this Thread