Re: strange bug?
- To: mathgroup at smc.vnet.net
- Subject: [mg79186] Re: strange bug?
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Fri, 20 Jul 2007 03:33:34 -0400 (EDT)
On 7/19/07 at 3:31 AM, cfgauss at u.washington.edu (Jeremy Price) wrote: >I think I've found a bug in mathematica 5.2, >In[418]:= $Version >Out[418]= 5.2 for Microsoft Windows (June 20, 2005) >When I run, eg, >In[416]:= IntegerPart[10*5.1] >Out[416]= 51 >I get what I expect. But when I run the same thing in a loop, >For[n = 1, n < 20, n = n + .1, >Print[n, " ", IntegerPart[10*n]] >] >I get output like: <output snipped> >Any idea what's going on here or how to fix it? The reason you are getting these results is 0.1 can not be expressed as a floating point number exactly with a finite number of digits. This is the nature of floating point arithmetic aka machine precision numbers. It is totally independent of Mathematica. The only way to avoid this class of problem is to use exact numbers in Mathematica. -- To reply via email subtract one hundred and four