[Scilab-users] Strange floating point issue below %eps

Samuel Gougeon sgougeon at free.fr
Sat Sep 23 12:48:42 CEST 2017


Hello,

Le 19/09/2017 à 11:16, Pinçon Bruno a écrit :
> Le 18/09/2017 à 20:54, Samuel Gougeon a écrit :
>>
>> Now comes the issue:
>> In (A), the relative difference 1/2^53 is too small (< %eps) to be 
>> recorded and to change the number. OK.
>> Since 1 / (2^53 +2) is even smaller than 1 / (2^53), it should nor 
>> make a difference. Yet, it does:
>>
>> --> (2^53 + 2^1) + 1 == (2^53 + 2^1)
>>  ans  =
>>   F
>>
>> How is this possible ??!
>>
>
> Hi all,
>
>    no issue here but simply the round to even rule. Every real number
>   should be approximated by the nearest floating point number but in 
> case of
>   a number exactly between 2 successive floats the one with an even end
>   digit win. You can see this rule as a mean to approximate those 
> ambiguous cases,
>   one in two down and one in two up, but has more subtle features in 
> it such
>   (it is explained in Knuth I).
>
>
>   OK that2^53 + 2^1 is exactly represented
>   (it is a double float number). When computing :
>
>           x = (2^53 + 2^1) + 1
>
>   it is not a float but is exactly at the same distance between the 
> two floats :
>
> 2^53 + 2^1   and 2^53 + 2^2  but this last one ends with a even digit (0)
>   so :
>          fl( (2^53 + 2^1) + 1) = 2^53 + 2^2
>
>   hth
>  Bruno

Thank you Bruno for this explanation and confirmation!
Up to before, i was naively considering that all what is smaller than %eps
is ignored. But it is not the case. This rounding rule has some somewhat
puzzling side effects, since as initially illustrated, it leads to sometimes
take into account some relative quantities smaller than some other ones that
are ignored...

So, i guess that whether this algorithm has been chosen, it shall have more
advantages than this kind of pitfall.

Afterwards, i had a look to the Scilab %eps and number_properties help 
pages:
https://help.scilab.org/docs/6.0.0/en_US/percenteps.html
https://help.scilab.org/docs/6.0.0/en_US/number_properties.html
The IEEE 754 standard is quoted. Digging about it, for instance in
https://en.wikipedia.org/wiki/IEEE_754
https://fr.wikipedia.org/wiki/IEEE_754
is very instructive. There is a whole section about rounding methodS.

Le 19/09/2017 à 12:08, antoine monmayrant a écrit :
 > PS: Samuel, do you think you could close the bug by pointing to this 
"round to even" rule?

I am keeping open and updating the report. IMO the posted %eps 
"exception" would deserve being documented as an example, either in the 
%eps or the number_properties page. Moreover, cross-references are 
missing between both pages. Finally, an external pointer to IEEE 754 
would be welcome.
I will propose a revision.

Again thanks for your answers.
Best regards
Samuel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170923/61475cde/attachment.htm>


More information about the users mailing list