[Numpy-discussion] arange and floating point arguments

lorenzo bolla lbolla at gmail.com
Fri Sep 14 05:46:49 EDT 2007


this is really annoying.
Matlab handles the "ceil" weirdness quite well, though.

--------------------------------------------------------------

>> ceil(0.6/0.1)

ans =

     6

>> ceil((0.4+0.2)/0.1)

ans =

     7

>> 0:0.1:0.6

ans =

                         0    1.000000000000000e-001
2.000000000000000e-001    3.000000000000000e-001    4.000000000000000e-001
5.000000000000000e-001    6.000000000000000e-001

>> 0:0.1:(0.4+0.2)

ans =

                         0    1.000000000000000e-001
2.000000000000000e-001    3.000000000000000e-001    4.000000000000001e-001
5.000000000000001e-001    6.000000000000001e-001


>> length(0:0.1:0.6) == length(0:0.1:(0.4+0.2))

ans =

     1

--------------------------------------------------------------

hth,

L.



On 9/14/07, Ed Schofield <edschofield at gmail.com> wrote:
>
> Hi everyone,
>
> This was reported yesterday as a bug in Debian's numpy package:
>
> >>> len(numpy.arange(0, 0.6, 0.1)) == len(numpy.arange(0, 0.4+0.2, 0.1))
> False
>
> The cause is this:
>
> >>> ceil((0.4+0.2)/0.1)
> 7.0
>
> >>> ceil(0.6/0.1)
> 6.0
>
> which holds for both numpy's and the standard library's ceil().
>
> Using arange in this way is a fundamentally unreliable thing to do,
> but is there anything we want to do about this? Should numpy emit a
> warning when using arange with floating point values when
> (stop-start)/step is close to an integer?
>
> -- Ed
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070914/fc4f6fb0/attachment.html>


More information about the NumPy-Discussion mailing list