MathGroup Archive 1997

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

Search the Archive

Re: floor problems

  • To: mathgroup at
  • Subject: [mg8140] Re: [mg8113] floor problems
  • From: seanross at
  • Date: Fri, 15 Aug 1997 23:41:51 -0400
  • Sender: owner-wri-mathgroup at

Tom wrote:
> Hello Mathematica users.
> I had a very frustrating time trying to debug some work I was doing in
> Mathematica.  I finally pared it down to a problem with the Floor
> function, and I have illustrated my concern below.  I am using M 3.0 and
> a Mac computer.  Does anyone have any advice or could you tell me if I
> am doing something wrong?
> Floor[(.7 67 10)]
> 469
> Floor[(67 10 .7)]
> 468
> Sincerely,
> Tom De Vries
> --
> Vermilion Home Education Program
> Tom De Vries
> 11003 - 132 st.
> Edmonton, AB
> Canada
> T5M 1E4
> Phone:  (403)451-5822
> Fax:      (403)454-0173
> email:     tom.devries at
> email:     toad at

Your only "error" is in assuming that all numbers have infinite
precision.  Since .7*670=469 and you are using default precision
numbers, which is 16 digits, then we can say that (.7+/-10^-16)
To perform mixed integer and real multiplication, Mma must do some kind
of conversion from integer to real.  My guess is that in one formulation
it does the integer multiply first, then converts to real and in the
other it does two integer conversions to real and then multiplies and
this makes one result ever so slightly less than 469.  You can see all
the digits by using FullForm.

The whole point of this is that you use a function like Floor when you
are absolutely sure that the part of the number you don't want will
always be greater than an integer.  If the number is supposed to be an
integer, then round-off will give you unstable results.  I recommend
using Round in this case.  You may want to consider a little error
trapping routine to check if Abs[Round[x]-x] is less than 10^-15 to
avoid this kind of error.

  • Prev by Date: Notebooks in the background
  • Next by Date: Re: floor problems
  • Previous by thread: Notebooks in the background
  • Next by thread: Re: floor problems