# Strange behavior of MachinePrecision

As we all know, Ramanujan's Constant equal to :

$$e^{\pi \sqrt{163}} = 262537412640768743 + 0.99999999999925\cdots$$

But when I tried to find it's fractional part using Mathematica, something wrong happened.

FractionalPart[Exp[Sqrt[163]Pi]]//N


It gives the wrong answer: -480.

I think it's a precision problem. I know //N means //N[#,MachinePrecision]&.

But precisions below 11 give $1.00000$ and over 12 give the right answer.

Only MachinePrecision gives the wrong answer.

Then I did another test.

Well, I think there're the same and it's true.

This makes me more puzzled.

• The bugs tag is only for confirmed bugs. Oct 28, 2017 at 9:10
• I get the same on 11.2.0 for Microsoft Windows (64-bit). Oct 28, 2017 at 9:16

The basic issue is that computations with machine numbers do not have any sort of precision control, so numeric cancellation can cause completely wrong answers when using them. On the other hand, extended precision numbers include precision tracking, so during the computation of N, internal numbers can have their precision raised to avoid numeric cancellation. This explains why:

N[FractionalPart[Exp[Sqrt[163]Pi]]]


-480.

is wrong and:

N[FractionalPart[Exp[Sqrt[163]Pi]], 20]


0.99999999999925007260

produces an extended precision number (not a machine number) correct to 20 places.

As for your second question about the difference between MachinePrecision and $MachinePrecision. Using MachinePrecision produces a machine number, while using $MachinePrecision produces an extended precision number with 16 digits of precision. For instance:

N[FractionalPart[Exp[Sqrt[163] Pi]], MachinePrecision] // MachineNumberQ
N[FractionalPart[Exp[Sqrt[163] Pi]], $MachinePrecision] // MachineNumberQ  True False • As a historical note: before version 5, N[expr,$MachinePrecision] did the same thing as N[expr, MachinePrecision]. Oct 31, 2017 at 6:01