Re: The question of equality,...

*To*: mathgroup at smc.vnet.net*Subject*: [mg60601] Re: The question of equality,...*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Wed, 21 Sep 2005 03:20:45 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 9/20/05 at 5:20 AM, ted.ersek at tqci.net wrote: >Terry Snow wanted to know how to tell if two arbitrary precision >numbers are the same even including the bits that are not known >reliably. Consider the following: >In[1]:= $Pre=InputForm; >In[2]:= x1=N[1/10,18] >Out[2]= 0.100000000000000000000000000005049`18 >In[3]:= x2=x1+10^-32 >Out[3]= 0.100000000000000000000000000005059`18 >Others suggested using RealDigits, but it seems RealDigits doesn't >tell us about digits that may be wrong. >In[4]:= RealDigits[x1] >Out[4]= {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, >0} RealDigits works fine *if* you compare binary digits, i.e., In[1]:= x1 = 1.; x2 = x1 + 10^-$MachinePrecision; In[3]:= RealDigits[x1] == RealDigits[x2] Out[3]= True In[4]:= RealDigits[x1, 2] == RealDigits[x2, 2] Out[4]= False Note, I didn't use your particular example since on my system In[5]:= x1 = N[1/10, 18] Out[5]= 0.1`18. In[6]:= x2 = x1 + 10^(-32) Out[6]= 0.1`18. In[11]:= SetPrecision[x2 - x1, Infinity] Out[11]= 0 That is the two numbers of your example are identical on my system. -- To reply via email subtract one hundred and four