I'm confused by the following trivial code:
{Range[0, 1, .1][[8]]} === {.7}
gives True
MemberQ[{.7}, .7]
gives True
, but
MemberQ[{Range[0, 1, .1][[8]]}, .7]
gives False
. Huh? What am I missing?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'm confused by the following trivial code:
{Range[0, 1, .1][[8]]} === {.7}
gives True
MemberQ[{.7}, .7]
gives True
, but
MemberQ[{Range[0, 1, .1][[8]]}, .7]
gives False
. Huh? What am I missing?
{Range[0, 1, .1][[8]], .7} // InputForm
ought to be enlightening. Moral lesson is that you don't do such pattern matches on inexact numbers. $\endgroup$ – J. M.'s ennui♦ Aug 6 '17 at 12:53Internal`$SameQTolerance
(orInternal`$EqualTolerance
if you had used==
). See e.g. this. $\endgroup$ – J. M.'s ennui♦ Aug 6 '17 at 12:59