[Numpy-discussion] arange and floating point arguments

Joris De Ridder Joris.DeRidder@ster.kuleuven...
Fri Sep 14 07:07:25 CDT 2007


Might using

min(ceil((stop-start)/step), ceil((stop-start)/step-r))

with r = finfo(double).resolution instead of ceil((stop-start)/step)  
perhaps be useful?

Joris



On 14 Sep 2007, at 11:37, Ed Schofield 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


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the Numpy-discussion mailing list