In standard C++ the double values for 1. + 1.2*^-16 and 1. are not considered equal. But in Mathematica, I get the following:

With[{aux = 1 + 1.2*^-16}, 
 {{1 == aux, 1. == aux}, {1 < aux, 1. < aux}, {ArcSin[aux], ArcSin[1.]}}]


{{True, True}, {False, False}, {1.5708 - 2.10734*10^-8 I, 1.5708}}

Is there a parameter that I can set, to get the behaviour as in C++, i.e. strict floating point equality?

  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Feb 28 '16 at 13:42

See How to make the computer consider two numbers equal up to a certain precision and the linked SO answer for more details. This question is similar to the first one, except the OP here wants the tolerance to be $-\infty$, instead of greater.

Block[{Internal`$EqualTolerance = -∞},
 1 + $MachineEpsilon == 1.
1 + $MachineEpsilon == 1.
  • 2
    $\begingroup$ Perhaps this question should be considered a duplicate? $\endgroup$ – Michael E2 Feb 28 '16 at 14:36
  • 2
    $\begingroup$ For zero bits tolerance, Internal`$EqualTolerance should be -Infinity. A value of 0 leaves 1 bit tolerance. $\endgroup$ – Oleksandr R. Feb 28 '16 at 18:28
  • $\begingroup$ @OleksandrR. Thanks. I misremembered how it works. $\endgroup$ – Michael E2 Feb 28 '16 at 18:30

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.