6
$\begingroup$

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

enter image description here

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.

enter image description here

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

This makes me more puzzled.

$\endgroup$
2
  • $\begingroup$ The bugs tag is only for confirmed bugs. $\endgroup$ – aardvark2012 Oct 28 '17 at 9:10
  • $\begingroup$ I get the same on 11.2.0 for Microsoft Windows (64-bit). $\endgroup$ – aardvark2012 Oct 28 '17 at 9:16
10
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ As a historical note: before version 5, N[expr, $MachinePrecision] did the same thing as N[expr, MachinePrecision]. $\endgroup$ – J. M.'s ennui Oct 31 '17 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.