Re: Can someone please explain - real numbers
- From: "Sven Pran" <no.direct@xxxxxxxxxxxx>
- Date: Thu, 9 Nov 2006 10:52:24 +0100
"John Dough" <nobody@xxxxxxxxxxxxxxx> wrote in message
news:8855l2lt9g8r5b68gt8i77l3nktgg9prrl@xxxxxxxxxx
On Wed, 08 Nov 2006 20:51:34 GMT, Chris Cheney
<XXChris.CheneyXX@xxxxxxxxx> wrote:
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.
The FPU knows how to handle repeating fractions, regardless of their
base. The repeating portion is truncated (and rounded, if necessary)
at the last available digit of precision for any given float type. In
the case of "extended", the decimal portion terminates at the 18th
position.
I'm not sure what leads you to believe that 0.1 cannot be stored
precisely. Did you try it with code? I did...and it works fine.
I can store 0.1, and I get back 0.1
If you get back what you store, then by all accounts, it's precise.
Try
a := 0,1;
b := 0,0;
for i := 1 to 10
b := b + a;
if b = 1.0
then showmessage('b is equal to 1.0')
else showmessage('b is not equal to 1.0!');
You will almost certainly get the message that b is not equal to 1.0!
It does not matter whether you declare a and b as real, double or
extended.
The reason is that 0,1 cannot be stored precisely and therefore any
calculation involvinig this stored value is likely also to be (slightly)
inaccurate due to rounding errors.
But of course if you compare two different storages of 0.1 then
they will compare equal because the same inaccuracy will exist
for both.
Sven
.
- 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
- Re: Can someone please explain - real numbers
- From: Chris Cheney
- Re: Can someone please explain - real numbers
- From: John Dough
- Can someone please explain - real numbers
- Prev by Date: Re: What about this solution ?
- 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
|