[Issue 6560] Exponentiation operator ^^ doesn't work for complex numbers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 27 07:14:12 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6560
--- Comment #6 from bdsatish at gmail.com 2011-08-27 07:14:06 PDT ---
(In reply to comment #5)
I found a workaround for ^^, looks like this works:
import std.stdio;
import std.complex;
void main() {
auto x = Complex!real(1,2);
auto y = Complex!real(3,4);
writeln(x^^y);
}
> Please, show examples of the real problems, so Andrei & Walter will judge the
> situation.
Let's consider the same cases as mentioned in the "Semantics" section of:
http://www.digitalmars.com/d/2.0/cppcomplex.html
Well, unfortunately std.complex; in v2.051 is not up-to-date. I wanted to
verify whether the following identities hold:
* sqrt(conj(z)) == conj(sqrt(z)) whenever z takes on negative real values
* conj(log(z)) == log(conj(z)) whenever z takes on negative real values
I couldn't test the above because sqrt( ) and log( ) are not implemented for
complex numbers in 2.051. I do not know the situation in 2.055head. Could you
please verify this, if possible ?
However, I do have a testcase for this one:
* (1 - infinity*i)*i == (infinity + i) but not (infinity + NaN*i)
where i = sqrt(-1), the imaginary constant. The following demonstrates how a
"spurious NaN" is generated, as mentioned in the above link.
import std.stdio;
import std.complex;
union INFINITY {
float inf;
uint num;
};
union NOT_A_NUMBER {
float nan;
uint num;
};
void main() {
INFINITY posinf, neginf;
NOT_A_NUMBER nan;
posinf.num = 0x7F800000; // positive infinity
neginf.num = 0xFF800000; // negative infinity
nan.num = 0x7FC00000; // Not a Number
writefln("Positive infinity = %f", posinf.inf);
writefln("Negative infinity = %f", neginf.inf);
writefln("Not a number = %f", nan.nan);
Complex!float i = Complex!float(0.0f, 1.0f); // i
Complex!float p = Complex!float(1.0f, neginf.inf); // 1-inf*i
writefln("%f",p*i); // Must be (1-inf*i)*i = inf + 1i
}
The expected answer is (+inf, 1.0f) but the above prints "inf-nani".
I do not know how it was in D1, but in D2 the above produces mathematically
incorrect result. Again, I'm unaware how it is in C99/C++, etc. or is it always
like this.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list