Wht std.complex is needed?
Daniel Keep
daniel.keep.lists at gmail.com
Mon Apr 6 06:40:57 PDT 2009
Steven Schveighoffer wrote:
> On Mon, 06 Apr 2009 08:36:18 -0400, Don <nospam at nospam.com> wrote:
>
>> Sam Hu wrote:
>>> Thank you!
>>> Anothe silly question then:What's the disadvantage to have the
>>> built-in type of i-type?
>>> Regards,
>>> Sam
>>
>> It's a very nasty type. It supports *, but isn't closed under *.
>> Which is really annoying for generic programming.
>>
>> idouble x = 2i;
>> x *= x; // oops, this isn't imaginary. (BTW this currently compiles :o).
>
> This may be a dumb question, but aren't all real numbers also
> technically imaginary numbers with a 0i term? that is, I would expect
> the above to evaluate to:
>
> -4 + 0i
>
> Which I would view as an imaginary number. Am I completely wrong here?
You're thinking of "complex". -4 is real, 2i is imaginary, -4+2i is
complex.
Regarding Don's example, imaginary*imaginary always yields a real,
real*imaginary always yields an imaginary. It's the only builtin type I
know of that changes type under multiplication with itself.
-- Daniel
More information about the Digitalmars-d-learn
mailing list