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 by 
https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/en.wikipedia.org/wiki/IEEE_754

--Jean-Yves

_______________________________________________
users mailing list
users@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@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to