std.complex MAY I REMIND YOU?

Janice Caron caron800 at googlemail.com
Fri Feb 22 09:33:12 PST 2008


On 22/02/2008, S <S at s.com> wrote:
> http://www.digitalmars.com/d/2.0/cppcomplex.html

Hmm... On that on that web page. It says:

"A streamline goes astray when the complex functions SQRT and LOG are
implemented, as is necessary in Fortran and in libraries currently
distributed with C/C++ compilers, in a way that disregards the sign of
0.0 in IEEE 754 arithmetic and consequently violates identities like
SQRT( CONJ( Z ) ) = CONJ( SQRT( Z ) ) and LOG( CONJ( Z ) ) = CONJ(
LOG( Z ) ) whenever the COMPLEX variable Z takes negative real
values."

The thing is, every complex number has /two/ square roots, not one.
(If y is a square root of x, then so is -y). As soon as you invent
some arbitrary way of choosing one of them over the other, then the
identity ceases to be an identity.

Likewise, every complex number has an infinite number of logarithms.
(If y is a log of x, then so is y+2*pi*k*i, for all integers k).
Again, the moment you decide that log can only return one value, then
why be surprised when the identity no longer holds?

The function CONJ() turns x+iy into x-iy, so /obviously/, if y is
zero, then conj leaves a complex number unchanged. That little "cheat"
of using the "sign of zero" to decide which of the multivalues is the
primary one is just that - a cheat. Mathematical zero has no sign.



More information about the Digitalmars-d mailing list