[Numpy-discussion] (no subject)

Jonathan Helmus jjhelmus at gmail.com
Thu Sep 18 13:14:51 EDT 2014


On 09/18/2014 12:01 PM, Chris Barker wrote:
> Well,
>
> First of all, numpy and the python math module have a number of 
> differences when it comes to handling these kind of special cases -- 
> and I think that:
>
> 1) numpy needs to do what makes the most sense for numpy and NOT 
> mirror the math lib.
>
> 2) the use-cases of the math lib and numpy are different, so they 
> maybe _should_ have different handling of this kind of thing.
>
> 3) I'm not sure that the core devs think these kinds of issues are 
> "wrong" 'enough to break backward compatibility in subtle ways.
>
> But it's a fun topic in any case, and maybe numpy's behavior could be 
> improved.
>
>     My vote is that NumPy is correct here. I see no reason why
>     >>> float('inf') / 1
>     and
>     >>> float('inf') // 1
>
>     should return different results.
>
>
> Well, one argument is that "floor division" is supposed to return an 
> integer value, and that inf is NOT an integer value. The integral part 
> of infinity doesn't exist and thus is Not a Number.
>

But nan is not an integer value either:

 >>> float('inf') // 1
nan
 >>> int(float('inf') // 1)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ValueError: cannot convert float NaN to integer

Perhaps float('inf') // 1 should raise a ValueError directly since there 
is no proper way perform the floor division on infinity.

     - Jonathan Helmus

> You also get some weird edge cases around the mod operator.
>
> -Chris
>
> -- 
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov <mailto:Chris.Barker at noaa.gov>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140918/eb355f6b/attachment.html>


More information about the NumPy-Discussion mailing list