MathGroup Archive 1997

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

Search the Archive

RE: floor problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8131] RE: [mg8113] floor problems
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Fri, 15 Aug 1997 23:41:43 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Tom De Vires wrote:

|I had a very frustrating time trying to debug some work I was doing in
|Mathematica.
|
|Floor[(.7 67 10)]
|
|469
|
|Floor[(67 10 .7)]
|
|468
|

Consider the following:

In[1]:=     b=67*10*0.7
Out[1]=  469.

0.7 is a machine precision number rather than an exact number such as an
Integer or Rational.  Arithmetic involving machine precision numbers
gives machine precision (imprecise) results.  Now lets see how far the 
result
is from 469.

In[2]:=    error=469-b
Out[2]=  5.68434x10^-14

It turns out the result  (b)  is a tiny bit less than 469.  Hence the Floor 
of this
value is 468.

It turns out we do have an idea how much error there can be in such a
result.  You should always find the magnatude of the error from any machine
precision calculation is less than the value times $MachineEpsilon.
$MachineEpsilon is explained below.

In[3]:=    error<469 * $MachineEpsilon
Out[3]=  True

Sure enough the error is less than  (469)*$MacineEpsilon.


In[4]:=   ?$MachineEpsilon
Out[4]   $MachineEpsilon gives the smallest machine-precision number
               which can be added to 1.0 to give a result that is 
distinguishable
               from 1.0.

Now when the machine precision (imprecise) multiplication is computed in a
different order, the result is as close as you can get to 469.  It should be 
no
surprise that the Floor of this result is 469.

In[5]:=     a=0.7*67*10;
                469-a

Out[5]=  0.

However, I wouldn't read to much into the result above.  You will only have
things work out this good in special situations.

To read more about machine precision calculations in Mathematica goto:

http://www.wolfram.com/support/Math/Numerics/NumericalError.html


     Ted Ersek




  • Prev by Date: Re: Mathematica question
  • Next by Date: Limit a^n / n!
  • Previous by thread: Re: floor problems
  • Next by thread: Re: floor problems