Ask Your Question

Revision history [back]

The fact that f(n) shows 5.000000000000000 is just a printing artifact, there is no rounding, you can check that f(n) is equal to n and different from 5:

sage: n == f(n)
True

Even n itself is represented as 5.000000000000000, not =5.0000000000000001:

sage: n=5.0000000000000001
sage: n
5.000000000000000
sage: n-5
1.110223024625157e-16

The fact that f(n) shows 5.000000000000000 is just a printing artifact, there is no rounding, you can check that f(n) is equal to n and different from 5:

sage: n == f(n)
True

Even n itself is represented as 5.000000000000000, not =5.00000000000000015.0000000000000001:

sage: n=5.0000000000000001
sage: n
5.000000000000000
sage: n-5
1.110223024625157e-16

EDIT Here is a way to print more digits of n

sage: n.str(truncate=False)
'5.000000000000000111'

You might be scary with the two additional 1 at the end. This is because internally, numbers are represented in binary, and you proposed a number which is exact in base 10, but not in base 2, hence some rounding (not only in the printing, but also in the representation of n in the machine).

You can get the exact value of the rounded n as follows:

sage: n.exact_rational()
45035996273704961/9007199254740992

And even see its internal representation:

sage: n.sign_mantissa_exponent()
(1, 90071992547409922, -54)

And check

sage: 90071992547409922*2^(-54)
45035996273704961/9007199254740992

You can print the non-truncated expression of n as follows: