I was taking the log of a complex number, \log(-1/z). The imaginary part of z is 0 and the real part is positive. Let’s say z = (1.0, 0.0). The logarithm evaluates to two different numbers (\pm i\pi) depending on whether the imaginary part of -1/z is 0.0 or -0.0, as explained in the docs. In this case, 1/z evaluates to (1.0,0.0), which means that -1/z is (-1.0,-0.0).
Given that 1/(1.0,-0.0) evaluates to (1.0, 0.0), I was expecting that 1/(1.0, 0.0) evaluate to (1.0, -0.0). The numbers 0.0 and -0.0 are equal, but they are not equivalent (on my processor), as seen by the different branch choices for their logarithms triggered by \pm0.0i and of course by the different outputs of ieee_is_negative(0.0) and ieee_is_negative(-0.0).
This leads directly to the two seemingly conflicting relations
as seen in the following test example.
program test
use, intrinsic :: iso_fortran_env, only: real64
implicit none
complex(real64) :: z = 5.0_real64
complex(real64) :: wz, wzstar
wz = 1/z
wzstar = conjg(wz)
print*, "z: ", z
print*, "1/z: wz = ", wz
print*, "1/z*: wzstar = ", wzstar
! -- logarithm comparisons
print*, "log(-wz) = -log(-1/wz) ? ::", log(-wz) .eq. -log(-1/wz)
print*, "log(-wzstar) = -log(-1/wzstar) ? ::", log(-wzstar) .eq. -log(-1/wzstar)
end program test
---
Output
z: (1.0000000000000000,0.0000000000000000)
1/z: wz = (1.0000000000000000,0.0000000000000000)
1/z*: wzstar = (1.0000000000000000,-0.0000000000000000)
wz .eq. 1/z :: T
wz .eq. wzstar :: T
log(-wz) = -log(-1/wz) ? :: F
log(-wzstar) = -log(-1/wzstar) ? :: T
The last equality test is True because the imaginary part of wzstar is -0.0, which becomes 0.0 when wzstar gets inverted, but the one before it is False because the imaginary part of wz is 0.0 and does not become -0.0 when inverted.
Why does 1/z not acquire a negative sign on its imaginary part ? Could this be compiler (GCC v. 14.2.1) specific? Maybe this was an intentional decision made some time ago — maybe it’s quite subtle. Any insight is greatly appreciated.