Debian Codegraph @

doc/src/intrinsics/numeric/cmplx.md

raw
1 # cmplx(x [, [, kind]]): Convert to Complex
2
3 Conversion to complex type.
4
5 ## Declaration
6
7 ### Syntax
8
9 ```fortran
10 retval = cmplx(x, y)
11 #define CMPLX(x, y)
12 ```
13
14 `cmplx(x, y)` is one of the intrinsic present in ASR.
15
16 ### Arguments
17
18 `x` the input value must be of integer, real, or complex.
19 `y` the optional input value must be of type integer or real. It should be only
20 present in case `x` is not complex.
21 `kind` the optional input value of integer expression type for initialisation
22 indicating the kind parameter of the result.
23
24 ### Return values
25
26 The return value is of complex type, with a kind defined by input `kind` type
27 specified. If the `kind` is not specified, the return value is of default `kind`
28 `complex` type.
29
30 ## Description
31
32 **cmplx(x, [, y [, kind]])** converts the input value to complex representation:
33
34 `x` to real component of complex number.
35 if `y` is present, it is converted to the imaginary component.
36
37 If `y` is not present, the imaginary component is set to 0.0.
38
39 If `x` is complex then `y` must not be present.
40
41 For `x` complex input value, the result is calculated using mathematical formula:
42
43 $x + iy$
44
45 $i$ the imaginary part is the result.
46
47 ## Types
48
49 Supported argument types are integer, real, or complex.
50
51 ```c
52 #define _Imaginary_I (I)
53 #define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y)))
54 #define CMPLXF(x, y) ((float complex)((float)(x) + _Imaginary_I * (float)(y)))
55 #define CMPLXL(x, y) ((long double complex)((long double)(x) + \
56 _Imaginary_I * (long double)(y)))
57 ```
58
59 ## Examples
60
61 ```fortran
62 program intrinsics_cmplx
63 implicit none
64 print *, cmplx(1.0, -3.0)
65 end program
66 ```
67
68 **Result:**
69
70 ```
71 1 - 3i
72 ```
73
74 ## See Also
75