Is there a “normal” EqualQ function in Mathematica?

后端 未结 7 662
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 03:49

On the documentation page for Equal we read that

Approximate numbers with machine precision or higher are considered equal if they d

7条回答
  •  悲&欢浪女
    2020-12-24 04:32

    Try this:

    realEqual[a_, b_] := SameQ @@ RealDigits[{a, b}, 2, Automatic]
    

    The choice of base 2 is crucial to ensure that you are comparing the internal representations.

    In[54]:= realEqual[1.0000000000000021, 1.0000000000000021]
    Out[54]= True
    
    In[55]:= realEqual[1.0000000000000021, 1.0000000000000022]
    Out[55]= False
    
    In[56]:= realEqual[
               1.000000000000000000000000000000000000000000000000000000000000000022
             , 1.000000000000000000000000000000000000000000000000000000000000000023
             ]
    Out[56]= False
    

提交回复
热议问题