Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'some IEEE math' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
some IEEE math
Authored by: Arakageeta on Oct 09, '02 11:12:50AM

As many have already said, this problem is due to the conversion between a dec based number to a bin based number. Some numbers that can be represented in with finite digits in one base cannot be represented with finite digits in another.

For all floating point numbers, computers conform to the IEEE standard, so just note that there is more involved in coverting a floating point directly to a decimal. The format of the IEEE really isn't important for the following.

Here's a c++ program that takes the number .56 and dumps it's binary value to the screen (in Hex):

#include <iostream>
using namespace std;

int main()
double num = .56; // our number -- a 64-bit IEEE floating point
double *d_num = &num; // pointer to that number in memory
int first, second;
first = ((int*)d_num)[0]; // save the first 32bits of the floating point
second = ((int*)d_num)[1]; // save that last 32bits.
printf("%x%x", first, second); // print the integers in hex
return 0;

You'll get this on the screen: 3fe1eb851eb851ec

That is our 64 bit floating point number in hex.

NOW, go to this web address:

Paste the hex number we got into the top text field and let the conversions fly!
As you'll see, there's that 0.5600000000000001.

[ Reply to This | # ]