[Scilab-users] Problems arising from truncation of %pi

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Jan 8 12:28:30 CET 2021


But, of course, we have

--> bitstring(3.141592653589793) == bitstring(%pi)
  ans  =

   T

which means that 3.141592653589793 and 
3.141592653589793115997963468544185161590576171875 have the same 
internal IEEE754 representation.

S.

Le 08/01/2021 à 12:20, Stéphane Mottelet a écrit :
> The nearest double-precision IEEE-754 binary floating-point number for 
> the decimal number PI
>
> 3.141592653589793 23846264338327950288419716939937510582097494459230 
> 78164 06286 ....
>
> is
>
> 3.141592653589793 115997963468544185161590576171875
>
> It can be shown this way: its internal base 2 representation is (I 
> added spaces to separate the sign, exponent and mantissa) is given in 
> Scilab by
>
> --> bitstring(%pi)
>  ans  =
>
>   "0 10000000000 1001001000011111101101010100010001000010110100011000"
>
> i.e. a positive number, with exponent 2^(1024-1023) = 1 and mantissa
>
> 1.1001001000011111101101010100010001000010110100011000
>
> i.e. the leading "1."  is implicit (normalized convention) and has to 
> be added. Hence, the final numer, after mutiplication by 2^exponent, is
>
> 11.001001000011111101101010100010001000010110100011000
>
> You won't be able to convert this back to decimal by using floating 
> point arithmetic. There is an efficient converter at 
> https://www.exploringbinary.com/binary-converter/ which gives the 
> actual result
>
> convert
>
>
> S.
>
> Le 08/01/2021 à 10:48, Jean-Yves Baudais a écrit :
>> Hello,
>>
>> ----- Original Message -----
>>> The function could be sinpi() or similar, with two arguments: the main
>>> argument x and an integer argument n, being its result equivalent to
>>>
>>> sin(x - n*pi)
>> So now the problem can be how these large numbers are obtained
>> --> a=1e16+1
>> --> a-1e16
>> of course equals zero.
>>
>>> where pi is the exact value of pi
>> Hum... What does "exact" mean in numerical calculus? (In symbolic one, it's simpler :-)
>>
>> --> format(25)
>> --> %pi
>> 3.141592653589793115998
>>
>> the 6 last digits are wrong (cf.https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/oeis.org/A000796) because of float64 format.
>>
>>> Probably it is not proper to refer to it as noise, since the difference
>>> is deterministic as can be demonstrated by using the function nearfloat()
>> Maybe noise is not the right word. But, the difference is fixed and %pi give all the time the same digit in format(25). It's a bit weird (up to my ignorance) to have these wrong deterministic digits... Hum, maybe I need to read "What Every Computer Scientist Should Know about Floating-Point Arithmetic", David Goldberg, ACM Computing Surveys, vol. 23, no  1, mars 1991 recommanded byhttps://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/en.wikipedia.org/wiki/IEEE_754
>>
>> --Jean-Yves
>>
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users
> -- 
> Stéphane Mottelet
> Ingénieur de recherche
> EA 4297 Transformations Intégrées de la Matière Renouvelable
> Département Génie des Procédés Industriels
> Sorbonne Universités - Université de Technologie de Compiègne
> CS 60319, 60203 Compiègne cedex
> Tel : +33(0)344234688
> http://www.utc.fr/~mottelet
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users

-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210108/ce88dd32/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: convert.png
Type: image/png
Size: 31552 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20210108/ce88dd32/attachment.png>


More information about the users mailing list