Best way to "convert" a real to ireal
Carsten Sørensen
cso at rift.dk
Thu Sep 13 04:20:19 PDT 2007
Hi,
With D's support for complex math I thought it would be fun to do a
Mandelbrot explorer.
It's all working fine but in the process of writing it, a few questions
popped into my head.
creal have .re and .im properties, but .im returns a real, not an ireal
as I would expect. Is there another property that will return the
imaginary part as an ireal? I can't seem to find the creal properties
documented anywhere.
Since .im returns a real I sometimes have to convert it back to an ireal.
This doesn't work, im is now zero.
---
creal c = 1.0 + 1.0i;
ireal im = cast(ireal)c.im;
---
Instead I'm doing:
---
creal c = 1.0 + 1.0i;
ireal im = c.im * 1.0i;
---
but this seems a bit clumsy... is there a better way? Or better yet, a
creal property that will actually retrieve the imaginary part as an ireal?
Thanks,
Carsten Sørensen
More information about the Digitalmars-d-learn
mailing list