[Numpy-discussion] abs for max negative integers - desired behavior?
David Cournapeau
cournape@gmail....
Wed Oct 12 03:46:23 CDT 2011
On Wed, Oct 12, 2011 at 9:18 AM, "V. Armando Solé" <sole@esrf.fr> wrote:
> From a pure user perspective, I would not expect the abs function to
> return a negative number. Returning +127 plus a warning the first time
> that happens seems to me a good compromise.
I guess the question is what's the common context to use small
integers in the first place. If it is to save memory, then upcasting
may not be the best solution. I may be wrong, but if you decide to use
those types in the first place, you need to know about overflows. Abs
is just one of them (dividing by -1 is another, although this one
actually raises an exception).
Detecting it may be costly, but this would need benchmarking.
That being said, without context, I don't find 127 a better solution than -128.
cheers,
David
More information about the NumPy-Discussion
mailing list