Re: Can someone please explain - real numbers
- From: Nicholas Sherlock <N.sherlock@xxxxxxxxx>
- Date: Wed, 08 Nov 2006 19:35:09 +1300
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
.
- Follow-Ups:
- Re: Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- References:
- Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- From: Paul W
- Can someone please explain - real numbers
- Prev by Date: Re: Can someone please explain - real numbers
- Next by Date: Re: Can someone please explain - real numbers
- Previous by thread: Re: Can someone please explain - real numbers
- Next by thread: Re: Can someone please explain - real numbers
- Index(es):
Relevant Pages
|