Thread overview | |||||
---|---|---|---|---|---|
|
June 03, 2006 Wrapping Python's complex type | ||||
---|---|---|---|---|
| ||||
I'm trying to wrap Python's PyComplex type. It stores the real and imaginary parts as two doubles. D, of course, has complex numbers built-in. I would like to provide a member function like, e.g.: cdouble asComplex(); Which would take the two parts and combine them into a D cdouble. However, I can't seem to convert the two doubles into a cdouble. The .re and .im properties are read-only, and the following doesn't work: cdouble c; double a = 2.4, b = 3.8; c = a + cast(idouble)b; // c now equals 2.4 + 0i What am I missing? -Kirk McDonald |
June 04, 2006 Re: Wrapping Python's complex type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirk McDonald | Kirk McDonald wrote:
> I'm trying to wrap Python's PyComplex type. It stores the real and imaginary parts as two doubles. D, of course, has complex numbers built-in. I would like to provide a member function like, e.g.:
>
> cdouble asComplex();
>
> Which would take the two parts and combine them into a D cdouble. However, I can't seem to convert the two doubles into a cdouble. The .re and .im properties are read-only, and the following doesn't work:
>
> cdouble c;
> double a = 2.4, b = 3.8;
> c = a + cast(idouble)b;
> // c now equals 2.4 + 0i
>
> What am I missing?
c = a + b * 1i;
|
June 04, 2006 Re: Wrapping Python's complex type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | Burton Radons wrote:
> Kirk McDonald wrote:
>> What am I missing?
>
> c = a + b * 1i;
Ahhhh, of course. Thanks!
-Kirk McDonald
|
Copyright © 1999-2021 by the D Language Foundation