7

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.]}}]

returns

{{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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
datahaki
  • 173
  • 6
  • 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!
    –  Feb 28 '16 at 13:42

1 Answers1

7

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.
(*
  False
  True
*)
Michael E2
  • 235,386
  • 17
  • 334
  • 747