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.

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


.



Relevant Pages

  • Re: Is there a bigger data type in c than the double one?
    ... >> working with long doubles? ... As every binary fraction has a ... >> finite decimal fraction representation, ... > great precision because of the extended precision module, ...
    (comp.lang.c)
  • Re: Can someone please explain - real numbers
    ... binary fraction 0.0001100110011001100110011001100110 and ... at the last available digit of precision for any given float type. ... the decimal portion terminates at the 18th ... If you get back what you store, then by all accounts, it's precise. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Can someone please explain - real numbers
    ... binary fraction 0.0001100110011001100110011001100110 and ... at the last available digit of precision for any given float type. ... the decimal portion terminates at the 18th ... If you get back what you store, then by all accounts, it's precise. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Can someone please explain - real numbers
    ... (0110 recurring) and cannot ... The FPU knows how to handle repeating fractions, ... at the last available digit of precision for any given float type. ... {To start the recurring fraction immediately} ...
    (comp.lang.pascal.delphi.misc)
  • Re: accuracy
    ... imprecise but accurate or imprecise and inaccurate. ... its absolute precision is 1ms. ...
    (comp.lang.ada)