Dag Sverre Seljebotn wrote:
> I happen to routinely write (some complex integer expression)**2 in
> Python, and it is tedious to manually store the expression in a temporary
> etc. in Cython.
>
> I understand the reasons this is disabled from the FAQ; are there any
> reasons I can't create a Cython-specific utility code implementation of
> integer power though? The powers are usually very small here so I'm
> thinking just a for-loop with O(log n) multiplications...

Fine with me, see

http://trac.cython.org/cython_trac/ticket/127


> Or if the power is a smallish literal (my **2 an **3), I suppose just
> inline the multiplication operations...

For constant expressions, that would even be part of the constant folding
transformation. There are two problems here:

1) IIRC, the error is currently raised too early in the code, before
running into constant folding, so even

    cdef int someval = 3**2

doesn't work.

2) it would be weird to have an operator work in some cases and not in
others. For example, you don't know the size of a "long" at translation
time, so you can't know if

    cdef long someval = 65536**2

overflows or not. So, where would you draw the line?

If you can come up with a sensible utility function that handles the
different C compile time and runtime overflow cases nicely, I'm all for
it.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to