Skip to main content
edited tags
Link
Tweeted twitter.com/StackMma/status/806967483823493122
Source Link
RonH
  • 291
  • 1
  • 9

Bug in floating-point number comparisons near $MachineEpsilon?

I stumbled over the following weird behavior when comparing floating-point numbers close to 1.0:

qq = 1.0 + 60.0 $MachineEpsilon;

and then

qq > 1.0

yields False. However,

qq - 1

yields

1.33227*10^-14

which is far above $MachineEpsilon = 2.22045*10^-16 (the smallest number eps satisfying (1.0 + eps > 1.0)==True when using 8-byte floating point numbers). Changing the first command to

qq = 1.0 + 65.0 $MachineEpsilon;

Leads to the expected behavior of (qq > 1.0) == True.

I'm running Mathematica 10.4.0.0 under Windows on an Intel i5.

Ron