Re: Can someone please explain - real numbers
- From: Chris Cheney <XXChris.CheneyXX@xxxxxxxxx>
- Date: Wed, 08 Nov 2006 20:51:34 GMT
John Dough <nobody@xxxxxxxxxxxxxxx> wrote in
news:jat3l2lpfacc1i4fknftrhncqtjrto38lt@xxxxxxx:
On Wed, 08 Nov 2006 06:45:45 +0000, Paul W <noemail@xxxxxxxxx> wrote:
I always thought a computer would store something like 1/3
(0.33333...) simply as 0.33333... for as many decimal places it could
and then stopped. Is that not the case then?
Yes, that's exactly correct.
If you store 1/3 into an extended variable, it will store 0.3
(repeated down to 18 decimal places).
The only exception is if the last digit has to be rounded up, as in
the case of 2/3. It will store "0.666666666666666667". But this
isn't anything surprising, because it's something we all learned back
in grade 3.
Now there's one important thing to remember here. If you need to
store a fraction directly, then it's perfectly okay to check for
equality (as in your original example). A non-repeating fraction
will also work fine. But if you store a repeating fraction as a
result of a calculation, then you have to do one extra step before you
can accurately check it for equality.
Note that, for example, the simple decimal fraction 0.1 is the recurring
binary fraction 0.0001100110011001100110011001100110 (0110 recurring) and
cannot therefore be stored precisely as a single/double/extended/real.
.
- Follow-Ups:
- Re: Can someone please explain - real numbers
- From: John Dough
- 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
- Re: Can someone please explain - real numbers
- From: Nicholas Sherlock
- Re: Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- From: John Dough
- Can someone please explain - real numbers
- Prev by Date: What about this solution ?
- Next by Date: Re: What about this solution ?
- Previous by thread: Re: Can someone please explain - real numbers
- Next by thread: Re: Can someone please explain - real numbers
- Index(es):
Relevant Pages
|