Re: Can someone please explain - real numbers



Paul W wrote:
Thanks for all the replies.

Clearly I know nothing about how a computer stores "real" numbers.
Even after all this time!

It just amazes me that telling a computer to store a value of 2.21
(effectively 2.210000000 recurring) it decides to store a value like
2.211189899324 (or whatever). I thought the whole point of computers
is they were accurate for this sort of thing.

So I can use extended (is that spot on then?), but then what on earth
is the point of "real" numbers if they're not accurate?

The reason that you cannot get an exact representation of decimal numbers as a floating point type is that some decimal numbers require an infinite amount of binary digits to represent. It's the same way that 1/3 is 0.333333 (and so on) in decimal - there is no exact way to represent the number in decimal. Since we don't want to use an infinite amount of storage space to hold our numbers, we must store a certain number of binary digits and throw away the rest. This is why you don't get exactly 2.21 stored in your floating point value, no matter what precision you choose. Higher precision values are more accurate, but some numbers simply cannot be exactly represented in floating point.

I recommend:

http://docs.sun.com/source/806-3568/ncg_goldberg.html

If you are interested in learning more. They can explain it much better than I can.

Cheers,
Nicholas Sherlock

--
http://www.sherlocksoftware.org
.



Relevant Pages

  • Re: Rounding of the double
    ... actually, it doesn't store it in hex, it stores it in binary, with an implied high-order ... Floating point always seems to come as ... In my numerical analysis course, the professor spent 6 weeks telling us how to do ... The theory of numerical analysis assumes essentially infinite precision. ...
    (microsoft.public.vc.mfc)
  • Re: Can someone please explain - real numbers
    ... It just amazes me that telling a computer to store a value of 2.21 ... number of binary digits and throw away the rest. ... get exactly 2.21 stored in your floating point value, ... Higher precision values are more accurate, ...
    (comp.lang.pascal.delphi.misc)
  • Floating point load-store behaviour.
    ... I am trying to predict the behaviour of floating point load and store ... -> Is that particular bit getting flipped coz of rounding or something ...
    (comp.lang.c)
  • Floating point load-store behaviour.
    ... I am trying to predict the behaviour of floating point load and store ... -> Is that particular bit getting flipped coz of rounding or something ...
    (comp.arch)
  • Re: Float comparison
    ... real number one-third, let alone store it anywhere. ... If it handed the floating point numbers 1.0 and 3.0 to a divide routine, ...
    (comp.lang.c)