2

I would like to control how Equal[] works and allow a certain error associated with it. I would like numerical values which are, say, within one-thousandth of one another to be considered the same.

For example, I would like

1.001 == 1.00
(*True*) 

I've tried the following - but I'm worried this might not be possible.

SetPrecision[1.0000 == 1.0001, 2]
(* False *) 


SetAccuracy[1.0000 == 1.0001, 2]
(* False *) 

Block[{Internal`$EqualTolerance = Log10[2.^28]},
  Print[1.0001 == 1.000];
  ];
(* False *) 
Tomi
  • 4,366
  • 16
  • 31
  • `a = SetPrecision[1.01, 2]; b = SetPrecision[1.00, 2];

    a == bevaluates toTrueorSetPrecision[Hold[1.0000 == 1.0001], 2] // ReleaseHold`

    – Bob Hanlon May 18 '20 at 01:27
  • 4
    Try Block[{Internal`$EqualTolerance = Log10[2.^53/10^4]}, 1.0001 == 1.000] – Michael E2 May 18 '20 at 01:54
  • 1
    Or perhaps more precisely, Block[{Internal`$EqualTolerance = Log10[2.^53/Max[1.0001, 1.000]/10^4]}, 1.0001 == 1.000] – Michael E2 May 18 '20 at 02:02

0 Answers0