Complex number expression fails

The standard says that the simple parenthesis formulation (x,y) can be used only if x and y are literal constants or parameter’s. Otherwise the cmplx() intrinsic function must be used:

a = cmplx( x, y )

Alternative way:

a%re = x
a%im = y

a = x + im * y
is closer to the usual mathematical notation a = x + i.y

Note however that it requires a complex-complex multiplication (i.e. 4 multiplications+2 additions), a cast real–>complex, and a complex addition (i.e. 2 additions), whereas cmplx(x,y) is a simple assignment. For an isolated instruction it doesn’t matter, but if enclosed in a time-consuming loop it can make a difference.

Finally, in your particular case there is also:
a = 1.1 + exp( (0.0,1.0) )
more generally exp( cmplx(0,arg) ) is equivalent to cmplx( cos(arg), sin(arg) )

3 Likes