Yep, that is true and correct but does not seem to solve the issue. Indeed I now realize my post above was quite a bit off mark.
If we look at the Power function for instance:
public Complex Power(Complex exponent)
{
return (exponent * NaturalLogarithm()).Exponential();
}
This should return Zero when applied to number Zero, unless the exponent is Zero as well, in which case it should return NaN. At the moment it is returning NaN whichever the exponent.
To reproduce this is fairly simple:
static void Main(string[ args)
{
Console.WriteLine(Complex.Zero.Power(2).ToString());
Thread.Sleep(Timeout.Infinite);
}
By debug-stepping into the Power function, here is what happens:
1) NaturalLogarithm() correctly returns (re=-Infinity, im=0);
Then it goes to the * operator:
public static Complex operator *(Complex multiplicand, Complex multiplier)
{
return new Complex(multiplicand.real * multiplier.real - multiplicand.imag * multiplier.imag, multiplicand.real * multiplier.imag + multiplicand.imag * multiplier.real);
}
2) Here the * operator fails in calculating the imaginary party, bacause re=2*-Inf-0*0=-Inf is correct, but im=2*0+0*-Inf=NaN is not, and here we get the NaN.
In general, I guess the basic problem is the built-in double operators and the Math class cannot check the order of an infinite versus the order of an infinitesimal (what above I called checking for zero denominators and the like), so maybe here we have another instance of a special case (like when you check for IsReal or IsRealPositive on top of many functions).
Well, hope it is not too confused, anyway a very simple test like the above Complex.Zero.Power(2) is enough to show the problem.
To work around this, my program's code at the moment looks like:
if(value1.IsZero)
return Complex.Zero;
return value1.Power(value2);
-LV