[Cython] Status of C complex types (re-send)

Stefan Behnel stefan_ml at behnel.de
Mon Apr 6 19:04:10 CEST 2009


Hi,

please try to avoid top-posting.


Vic Kelson wrote:
> On Mon, Apr 6, 2009 at 12:19 PM, Lisandro Dalcin wrote:
> 
>> I would do this (at de module-level):
>>
>> import math
>> cdef double PI = math.pi
>>
>> of perhaps
>>
>> cdef double PI = 3.14...
>>
>> and just use "PI" on you cdef functions...
>>
> I did the first one. I just wanted to make sure that it was resolved at
> compile time.

Well, not really. The value will be resolved and assigned at *runtime*, or
rather module initialisation time. However, *using* the PI variable in your
code will not involve any Python API calls, as it's a plain C variable.

You can also take the value from math.h (cdef extern from ...), which will
avoid any loss in precision due to the type conversion.

Stefan


More information about the Cython-dev mailing list