[Numpy-discussion] Rationale for integer promotion rules

Antoine Pitrou solipsis at pitrou.net
Thu Jul 16 15:22:24 EDT 2015


On Thu, 16 Jul 2015 19:19:58 +0100
Robert Kern <robert.kern at gmail.com> wrote:
> On Thu, Jul 16, 2015 at 7:14 PM, Nathaniel Smith <njs at pobox.com> wrote:
> >
> > On Thu, Jul 16, 2015 at 9:18 AM, Antoine Pitrou <solipsis at pitrou.net>
> wrote:
> 
> > > while adding int8 and uint8 will give int16 as result
> > > (promoting to the smallest fitting type).
> >
> > I understand this to be a consequence of the previous rule (results
> > should match inputs) combined with the need to find a common input
> > type.
> 
> Specifically, when combining signed and unsigned ints, we need to find a
> signed int type that can simultaneously hold both of the *inputs*.

I'm not sure that would be necessary for e.g. addition (as long as you
run your code on a 2's complement machine). But thanks for the
explanation.

Regards

Antoine.





More information about the NumPy-Discussion mailing list