• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Floating point numbers

Recneps

Senior member
how are floating point numbers stored in a PC and why is it impossible to store .1 as .1 and not some slightly different number. Also what would be stored if .1 can be?
 
I just did a quick search, and this page seems to contain the information you want (link). As for why you can't store .1 as .1, it is a side affect of using the method described. Because only 22 bits are used to store the number, there can only be a certain degree of accuracy. However I don't know if .1 will cause a problem, I'm pretty sure .2 does. 🙂

Hopefully that gives you a little more insight. It's been a while since I've looked at this information so I'm not really in the position to explain it better.
 
.1 ( base 10 )= .0001100110011001100....( base 2). Since this infinitly repeating patteren must be truncated to the word length of the floating point number system being used it is impossible to accurately store .1 as a binary number.
 
The computer does not care what kind of number you give it, it simple does what it is instructed to do. Decimal numbers (floats) are first converted to scientific notation and normalized. The problem with decimals is accuracy. .1 base 10 is clearly a rational number as well as in binary (base 2). BUT, since it is NON-terminating that is where the problem lines! Let's say we truncate (cut off) at 4 digits, so we get .0001. This equals 0.0625! Not 0.1. If we go out 5 places, we get 0.00011 in base2 which equals 0.09375 (much better)!


Finally, at places we get 0.000110001 in base2 we get 0.095703125 (better still, but not quite).

You can keep on going, but you will never get exactly .1!
 
Back
Top