librelist archives

Very strange artihmetic

Very strange artihmetic

From:
Date:
2011-10-09 @ 08:34
```Hi all,

The class below implements some tests :

class
ESSAIS_REAL_32

insert
PLATFORM

create
make

feature

Cent : REAL_32 is 100.0

feature

make is
local
x : REAL_32
do
print("Cent = " + Cent.out + "%N%N")

x := Minimum_real_32 + Cent
print("      m = " + Minimum_real_32.out + "%N")
print("m + 100 = " +  x.out + "%N%N")

if
x ~= Minimum_real_32
then
print("(m + 100) ~= m : Oh! Oh!%N")
end

print("(m + 100) - m = " + (x - Minimum_real_32).to_string_format(128) + "%N")
end

end -- class ESSAIS_REAL_32

The results are :

Cent = 100.000000

m = -340282346638528859811704183484516925440.000000
m + 100 = -340282346638528859811704183484516925440.000000

(m + 100) ~= m : Oh! Oh!
(m + 100) - m = 0.0000000000000 etc 0000

What do you think about these tests ?

Regards.

Christophe
```

Re: [libertyeiffel] Very strange artihmetic

From:
Date:
2011-10-09 @ 08:56
```2011/10/9 <christophe.haro@free.fr>
>
> What do you think about these tests ?
>

Nothing unbelievable. 100 is so far below the radar of the large
floating-point number as not to blip a single bit.

Remember that a floating point is above all a mantissa, and fractional part
that represents the most significant part of the number.

The order of magnitude I found that started making any difference for your
operation is 100000000000000000000000000000000.0 (internally,
100000003318135351409612647563264.000000) :-)

As for ~= the magnitude was one zero more!

Floating point should not be used if you need accuracy. That's the rule
number one in banks :-)

Cheers,

http://t.co/LxkBu44e Cyril Adrian - fix #16: remove dependency from cpp to
runner

Retweet