MathGroup Archive 2004

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

Search the Archive

Re: bug in IntegerPart ?

  • To: mathgroup at
  • Subject: [mg47754] Re: bug in IntegerPart ?
  • From: Bill Rowe <readnewsciv at>
  • Date: Sun, 25 Apr 2004 05:13:26 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On 4/24/04 at 4:15 AM, lang.NO at (Dennis de Lang)

>Why does the following happen?

>In[1]:= (1.65 - 1.3)/0.007 
>Out[1]:= 50. 
>In[2]:= IntegerPart[%]
>Out[2]:= 49


>In[1]:= 0.35/0.007
>Out[1]:= 50.
>In[2]:= IntegerPart[%]
>Out[2]:= 50

This is a result of machine precision arithmetic. The issue arises becuase numbers like 0.35 do not have a finite binary expansion. So, the number that is used for such numbers will either be the closest binary number or a binary number that has been truncated compared to the true value.

So, what happens in the first example is 1.65 and 1.3 are converted to machine numbers. The difference between these two machine numbers is slightly less than .35 as demonstrated by:

Log[10, 35/100 - (1.65 - 1.3)]


You can get similar results for other combinations of machine numbers giving results near the threshold of a function such as IntegerPart
To reply via email subtract one hundred and four

  • Prev by Date: RE: bug in IntegerPart ?
  • Next by Date: RE: Problem With "Copy Input from Above"
  • Previous by thread: RE: bug in IntegerPart ?
  • Next by thread: Re: bug in IntegerPart ?