2010/5/24 Stefan Behnel <[email protected]>:
> luper rouch, 24.05.2010 00:07:
>> It seems there is a problem when attempting to access C members of an
>> extension type in special methods, such as __mul__ :
>
> Hi,
>
> you should avoid claiming to have found a bug just because you didn't read
> the documentation.
>
> http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods
>
Yes I certainly missed that in the docs, sorry. So, arithmetic
operators are some kind of static methods, is the following the right
way to implement them ?
def __mul__(op1, op2):
if isinstance(op1, Quaternion):
return from_c_obj((<Quaternion>op1).wrapped[0] * <float>op2)
else:
return from_c_obj((<Quaternion>op2).wrapped[0] * <float>op1)
And for intransitive operations like __div__ return NotImplemted in
the reversed case :
def __div__(op1, op2):
if isinstance(op1, Quaternion):
return from_c_obj((<Quaternion>op1).wrapped[0] / <float>op2)
else:
return NotImplemented
--
Lup
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev