Consider the following simple example involving the CMPLX function:
-- begin code --
implicit none
integer, parameter :: R4 = selected_real_kind( p=6, r=37, radix=2 )
integer, parameter :: R16 = selected_real_kind( p=33, r=4931, radix=2 )
real(kind=R16), parameter :: PI =
3.1415926535897932384626433832795028841971_r16
real(kind=R4), parameter :: FOO = 0.12345678901234567890_r4
complex(kind=kind(0d0)) :: c1
print *, "complex(kind=kind(0d0)) :: c1"
print *, new_line(""), "With c1 = cmplx( X=PI, Y=FOO ):"
c1 = cmplx( X=PI, Y=FOO )
print "(*(g0,z0))", "c1%re = ", c1%re, ", kind(c1%re) = ", kind(c1%re)
print "(*(g0,z0))", "c1%im = ", c1%im, ", kind(c1%im) = ", kind(c1%im)
print *, new_line(""), "With c1 = cmplx( X=real(PI,kind=kind(0.0)), Y=FOO ):"
c1 = cmplx( X=real(PI, kind=kind(0.0)), Y=FOO )
print "(*(g0,z0))", "c1%re = ", c1%re, ", kind(c1%re) = ", kind(c1%re)
print "(*(g0,z0))", "c1%im = ", c1%im, ", kind(c1%im) = ", kind(c1%im)
print *, new_line(""), "With c1 = cmplx( X=real(PI,kind=kind(0D0)), Y=FOO ):"
c1 = cmplx( X=real(PI, kind=kind(0D0)), Y=FOO )
print "(*(g0,z0))", "c1%re = ", c1%re, ", kind(c1%re) = ", kind(c1%re)
print "(*(g0,z0))", "c1%im = ", c1%im, ", kind(c1%im) = ", kind(c1%im)
print *, new_line(""), "With c1 = ( PI, FOO ):"
c1 = ( PI, FOO )
print "(*(g0,z0))", "c1%re = ", c1%re, ", kind(c1%re) = ", kind(c1%re)
print "(*(g0,z0))", "c1%im = ", c1%im, ", kind(c1%im) = ", kind(c1%im)
end
-- end code --
Upon compilation and execution of the program with a given processor,
the output is as follows:
-- begin output --
complex(kind=kind(0d0)) :: c1
With c1 = cmplx( X=PI, Y=FOO ):
c1%re = 400921FB60000000, kind(c1%re) = 8
c1%im = 3FBF9ADD40000000, kind(c1%im) = 8
With c1 = cmplx( X=real(PI,kind=kind(0.0)), Y=FOO ):
c1%re = 400921FB60000000, kind(c1%re) = 8
c1%im = 3FBF9ADD40000000, kind(c1%im) = 8
With c1 = cmplx( X=real(PI,kind=kind(0D0)), Y=FOO ):
c1%re = 400921FB60000000, kind(c1%re) = 8
c1%im = 3FBF9ADD40000000, kind(c1%im) = 8
With c1 = ( PI, FOO ):
c1%re = 400921FB54442D18, kind(c1%re) = 8
c1%im = 3FBF9ADD40000000, kind(c1%im) = 8
-- end output --
You will notice all three invocations of CMPLX function result in the
same output but which is different from that using the
complex-literal-constant.
Is this only as expected per the standard? Or is it an implementation
problem with the processor?
Thanks,
Vipul Parekh
|