Re: Can someone please explain - real numbers



"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.

It's rather generous to see 'truncating' and say 'handling'.


I'm not sure what leads you to believe that 0.1 cannot be stored
precisely.

The simple fact that not _all_ the bits in it are preserved.


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.

It took some work, but here's a program that demonstrates the problem:

var X: Real;
begin
X:=0.2; { To start the recurring fraction immediately }
while True do begin
X:=16*X;
X:=X-3;
end;
end.

Sixteen times 0.2 equals 3.2, subtracting 3 should leave us with the
original 0.2. Ad infinitum. Right?

Not in finite precision. Looking at the finite bitstring above (minus
the first zero after the point to make it more regular), I'm shifting
it left four bits each time, then chopping off the bits that have
travelled to before the binary point. After a few iterations, the
roundoff error becomes visible. After 16 iterations, X had become 0.25
on my computer.

I think I'll try to convince Intel to recall all Pentium processors
again. There seems to be an FMUL bug in them, too.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Assembly Language - Mathematics WITHOUT maths coprocessor
    ... So I think my answer of 12.04119983 is a little more correct, as 40 bits can hold as many values as 12 decimal digits, plus just a little bit more. ... multiply by 2 ^ precision, you shift it left by precision. ... Convert fraction part to binary as if it were an integer. ... Divide fraction part by what step 4 effectively multiplied it by. ...
    (alt.lang.asm)
  • Re: large numbers - syms
    ... precision, or evalfwhich would use N digits for the precision. ... I do not know how you would invoke that Maple call from Matlab; ... Usually, though, it is better to keep the fraction form around as long ...
    (comp.soft-sys.matlab)
  • Re: Significant Digits
    ... digits, such 2554698.67281. ... as the fraction. ... have not been able to find any implementation limitations for the ... An interesting discussion about PostScript's precision: ...
    (comp.lang.postscript)
  • Applesoft FP storage
    ... How many bytes are used by Applesoft to store the above numbers? ... with the 6 unused bits in the fraction bytes, ... that FP in Applesoft is including precision that I don't ...
    (comp.sys.apple2.programmer)
  • Re: Can someone please explain - real numbers
    ... binary fraction 0.0001100110011001100110011001100110 and ... The FPU knows how to handle repeating fractions, ... at the last available digit of precision for any given float type. ... inaccurate due to rounding errors. ...
    (comp.lang.pascal.delphi.misc)