Remove complex and imaginary types?

Don Clugston dac at nospam.com.au
Tue Jan 8 04:43:09 PST 2008


Bill Baxter wrote:
> Georg Wrede wrote:
>> Don Clugston wrote:
>>> Suppose you're writing a generic function product(T)(T[]) which 
>>> returns T[0]*T[1]*T[2]*... What's the return type?
>>> Suppose T is idouble. Then if the number of elements in T is odd, the 
>>> return type should be idouble, but if it's even, the return type 
>>> should be double!
>>
>> I definitely don't pretend to understand any of that, but shouldn't it 
>> all follow the pertinent trails of mathematics?
>>
>> As in, case one, idouble; case two, double -- and the latter should 
>> probably be an idouble where one of the parts of the result De Facto 
>> makes it double, while still technically being an idouble.
>>
>> Any further calculation that wants to perceive a difference, might 
>> then start with checking whether the argument is "in practice a 
>> double, or really idouble".
> 
> The bottom line is that there really is no useful mathematics that can 
> be performed using only imaginary numbers.  If to do anything more than 
> add, subtract, or multiply by a (real!) scalar they become complex.  If 
> you have any imaginary numbers in a numerical code it means you're 
> working in the complex plane.  I don't think there is even a 
> mathematical symbol reserved for the set of pure imaginary numbers.  For 
> reals there's the double-barred R, for complex numbers there's 
> double-barred C, but there's no double barred "I" as far as I know.  It 
> just isn't useful, because, as Don says, its not closed under the common 
> mathematical operations.

Right. In practice, I've found that you always convert ireal to real whenever 
you want to do anything interesting.

100% of the benefits of ireal could be obtained by including a guaranteed 
optimisation that

complexA * realR * complex_literalB

becomes simply complex(-A.im*R*B.im, A.re*R*B.im)
when the literal B has a real part of zero.
(and similarly for division).

Note that if the literal is 1i, then R behaves exactly as an ireal. The *only* 
difference is that the programmer has to remember that it's imaginary (by 
multiplying by 1i) instead of the compiler remembering it in the type.




More information about the Digitalmars-d mailing list