MathGroup Archive 2007

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

Search the Archive

Re: strange bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79193] Re: strange bug?
  • From: "David W.Cantrell" <DWCantrell at sigmaxi.net>
  • Date: Fri, 20 Jul 2007 03:37:21 -0400 (EDT)
  • References: <f7n4k9$24e$1@smc.vnet.net>

"Jeremy Price" <cfgauss at u.washington.edu> 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:
>
> >From In[415]:=4.9 48
>
> >From In[415]:=5. 49
>
> >From In[415]:=5.1 50
>
> >From In[415]:=5.2 51
>
> Any idea what's going on here or how to fix it?

Just change your increment from .1 to the precise value 1/10:

For[n = 1, n < 20, n = n + 1/10, Print[N[n], " ", IntegerPart[10*n]]]

David


  • Prev by Date: Re: Plot without Show
  • Next by Date: Re: annoying documentation in 6 (rant)
  • Previous by thread: Re: Question about Union
  • Next by thread: Re: strange bug?