[Pyrex] Integer exponentiation returns a double
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Feb 21 00:10:20 UTC 2007
didier deshommes wrote:
> Robert
> Bradshaw found that when a and b are cdef'ed as integers, the result
> of a**b is a double.
Pyrex's philosophy is that when operating on two things
both defined as C data types, the operation that should
be done is the one that makes the most sense from a
C point of view. In the case of **, this means translating
it into a call to the C pow() function.
Since C doesn't provide any integer-only power operation,
the only alternative would be to convert them to Python
ints and return a Python int or long. Since that's an
expensive thing to do, I think it's better if the programmer
needs to be explicit about it.
To avoid misleading people into creating bugs, it might
be better to disallow ** on C ints altogether, although
that would be surprising in another way, since C ints are
normally promoted to floats automatically wherever
appropriate.
--
Greg
More information about the Pyrex
mailing list