So one of the confusing things about == and sign() to me in Fortran is that when a processor distinguishes between +0 and -0 that x==0.0 returns true for x having either value, but that sign(1.0,x) will let you detect if signed zeros are distinguished or not. I did not look at the algorithm to see if a signed zero matters or not but since the test in the merge is x==0.0 it will be true for both +0 and -0, and thus always return 0.0. Is that what you want?
program demo_sign
implicit none
if(sign(1.0,-0.0)== -1.0)then
print *, 'this processor distinguishes +0 from -0'
else
print *, 'this processor does not distinguish +0 from -0'
endif
print *,'INTEGER:'
print *,'either way, 0==-0 is true!',0==-0
print *,'either way, 0=/-0 is false!',0/=-0
print *,sign(1,-0),sign(1,0)
print *,'REAL:'
print *,'either way, 0==-0 is true!',0.0==-0.0
print *,'either way, 0=/-0 is false!',0.0/=-0.0
print *,sign(1.0,-0.0),sign(1.0,0.0)
end program demo_sign
On a processor that distinguishes +0.0 and -0.0
this processor distinguishes +0 from -0
INTEGER:
either way, 0==-0 is true! T
either way, 0=/-0 is false! F
1 1
REAL:
either way, 0==-0 is true! T
either way, 0=/-0 is false! F
-1.00000000 1.00000000
PS:
I overloaded SIGN() so it would take a single value and act more like the ALGOL68 function. I wish the intrinsic took a single option in the first place