Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: The question of equality,...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60571] Re: The question of equality,...
  • From: ted.ersek at tqci.net
  • Date: Tue, 20 Sep 2005 05:20:17 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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}


Instead do the following.  The result is zero if and only if the numbers
are the same.

In[5]:=   SetPrecision[x2-x1,Infinity]

Out[5]=   1/81129638414606681695789005144064

----------
   Ted Ersek



  • Prev by Date: init.m
  • Next by Date: Re: Differences between recursions and limit
  • Previous by thread: Re: The question of equality,...
  • Next by thread: Re: The question of equality,...