Can someone explain why (-i)**2 which should = -1 has a negative zero
imaginary part? The program below makes a distinction where there is no
mathematical difference. It also shows that integer +0 and integer -0
are identical.
complex :: j=(0,-1)
write (*,*) j**2
write (*,*) (-j)**2
write (*,*) (0,1)**2,+0,-0
end program
With ifort -standard-semantics version 16.0-1633 20160501 it writes
(-1.000000,-0.000000)
(-1.000000,-0.000000)
(-1.000000,0.000000) 0 0
With gfortran 6.1.1 20160602 it writes
( -1.00000000 , -0.00000000 )
( -1.00000000 , -0.00000000 )
( -1.00000000 , 0.00000000 ) 0 0
On Fri, 19 Aug 2016, Anton Shterenlikht wrote:
> Date: Fri, 19 Aug 2016 09:46:44 +0100
> From: Anton Shterenlikht <[log in to unmask]>
> Reply-To: Fortran 90 List <[log in to unmask]>
> To: [log in to unmask]
> Subject: Re: COMP-FORTRAN-90 Digest - 16 Aug 2016 to 17 Aug 2016 (#2016-29)
>
> Yes, and possibly the compiler version too,
> and possibly the platform, etc.
> For example on linux with ifort 16.0.2 20160204
> I don't need to specify any compiler options:
>
> implicit none
> complex :: z1 = (-4.0, -0.0), z2 = (-4.0, 0.0)
> write (*,*) log(z1), log(z2)
> write (*,*) sqrt(z1), sqrt(z2)
> write (*,*) exp(0.5 * log(z1)), exp(0.5 * log(z2))
> end
...
-- John Harper, School of Mathematics and Statistics
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail [log in to unmask] phone (+64)(4)463 5276 fax (+64)(4)463 5045
|