Search code examples
piscilab

What is the value of %pi in Scilab?


In the Scilab documentation %pi is described as:

%pi returns the floating-point number nearest the value of π.

But what exactly is that number? Is it processor dependent?

By using "format()" in the Scilab console you can only show up to 25 digits.


Solution

  • As the Scilab article on %eps indicates, the floating point relative accuracy is not processor dependent: it is 2^(-52), because Scilab uses IEEE 754 double-precision binary floating-point format. According to Exploring Binary, the double-precision approximation to pi is

    1.1001001000011111101101010100010001000010110100011 x 2^1
    

    which is exactly

    3.141592653589793115997963468544185161590576171875
    

    Most of these digits are useless, as the actual decimal expansion of pi begins with

    3.14159265358979323846... 
    

    The relative error is about 3.9e-17, within the promised 2^(-52) = 2.2e-16.