[Numpy-discussion] arange and floating point arguments

Anne Archibald peridot.faceted@gmail....
Fri Sep 14 13:35:14 CDT 2007


On 14/09/2007, Charles R Harris <charlesr.harris@gmail.com> wrote:

> Since none of the numbers are  exactly represented in IEEE floating point,
> this sort of oddity is expected.  If you look at the exact values, (.4 +
> .2)/.1 > 6 and .6/.1 < 6 . That said, I would expect something like
> ceil(interval/delta - relatively_really_small_number) would generally return
> the expected result. Matlab probably plays these sort of games. The downside
> is encouraging bad programming habits. In this case, the programmer should
> be using linspace..

There is actually a context in which floating-point arange makes
sense: when you want evenly-spaced points and don't much care how many
there are. No reason to play games in this context of course; the
question is how to reduce user astonishment.

Anne


More information about the Numpy-discussion mailing list