https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117805

--- Comment #9 from mjr19 at cam dot ac.uk ---
(In reply to kargls from comment #6)

I agree that parts of the reasoning from J3 are a little surprising, but other
parts seem sound, and the conclusion is unambiguous.

(I also disagree with its claim that this matter is "easily" and "clearly"
answered in the current standard.)

> Use -Ofast or --fast-math if you want a possibly incorrect result
> fast.

The problem is I don't want possibly incorrect results. IEEE-754 does quite a
good job with real arithmetic, and I'd quite like to retain it for real
arithmetic.

Gfortran's extension of IEEE-754 to complex arithmetic is not so good.
Mathematicians tell us that the real line has two infinities, and IEEE-754
provides +Inf and -Inf. Mathematicians tell us that the extended complex plane
has a single point at infinity. All Fortrans (and most other languages) provide
us with about 2**66 of them, (+/-Inf, Any) and (Any, +/-Inf). They don't
compare as equal either.

IEEE-754 provides two real zeros. This leads to four zeros for complex numbers,
and sometimes some surprising results.

program zeros
  complex(kind(1d0))::zero,i
  i=(0d0,1d0)
  zero=(0d0,-0d0)
  write(*,*)'Zero=',zero
  write(*,*)'1*zero=',1d0*zero
  write(*,*)'i*zero=',i*zero
  zero=(-0d0,0d0)
  write(*,*)'Zero=',zero
  write(*,*)'1*zero=',1d0*zero
  write(*,*)'i*zero=',i*zero
end program zeros

 Zero=              (0.0000000000000000,-0.0000000000000000)
 1*zero=               (0.0000000000000000,0.0000000000000000)
 i*zero=               (0.0000000000000000,0.0000000000000000)
 Zero=              (-0.0000000000000000,0.0000000000000000)
 1*zero=              (-0.0000000000000000,0.0000000000000000)
 i*zero=              (-0.0000000000000000,0.0000000000000000)


Mathematically a modulus/argument representation of complex numbers would seem
at least as natural as a Cartesian one, at which point multiplication by one
would leave a value unchanged, and multiplication by i is simply a rotation, so
assuming (-0.0,0.0) means modulus zero, argument pi, then multiplication by i
should give (0.0,-0.0).

The answers which gfortran currently gives are correct and standard conformant.
But they are not uniquely correct and standard conformant. I do not see that
they are even "more" correct than some alternatives. If an alternative correct
answer can be obtained faster, why not? Afterall, the main reason that
computers rarely use the modulus/argument representation is that it makes
addition very slow.

Reply via email to