I want to know how N[π, 30] == π works. The result is True. I wonder whether the exact number π is truncated to a $MachinePrecision number or N[π, 30] is extended to an exact number in a way similar to the output of this instruction N[Pi, 30] // FullForm (like stated here).

  • 1
    $\begingroup$ Look at the "Detail" of the docs for Equal: "Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits)..." (of the precision of the expreassion, which is the lowest precision present, i.e. 30 digits in your example). $\endgroup$
    – Michael E2
    Dec 26 '19 at 17:27
  • $\begingroup$ @MichaelE2 What is a bit puzzling is that SetPrecision[N[Pi, 30], 55] == Pi evaluates to True as well even though naïvely there appears to be a difference of not 7, but 25 digits. $\endgroup$
    – Szabolcs
    Dec 26 '19 at 17:29
  • $\begingroup$ @MichaelE2 Although SetPrecision[N[Pi, 30], 55] - Pi evaluates to somethign of the order $10^{-54}$. Freak accident? $\endgroup$
    – Szabolcs
    Dec 26 '19 at 17:30
  • $\begingroup$ @Szabolcs All the digits in N[Pi, 30] // FullForm are correct, and there are more than 55 of them. So it is equal to Pi to 55 digits. (The internal form of arbitrary precision carries extra guard digits. How many varies.) $\endgroup$
    – Michael E2
    Dec 26 '19 at 17:30
  • 2
    $\begingroup$ N[π,30] does not extend uniquely, so that's not a possibility. Such equality testing is performed at the smallest numeric precision of the input. $\endgroup$ Dec 26 '19 at 19:21

Your Answer

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

Browse other questions tagged or ask your own question.