1 (* Library module defined by the International Standard
2 Information technology - programming languages
3 BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language.
5 Copyright ISO/IEC (International Organization for Standardization
6 and International Electrotechnical Commission) 1996-2021.
8 It may be freely copied for the purpose of implementation (see page
9 707 of the Information technology - Programming languages Part 1:
10 Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *)
12 DEFINITION MODULE ComplexMath
;
14 (* Mathematical functions for the type COMPLEX *)
18 one
= CMPLX (1.0, 0.0);
19 zero
= CMPLX (0.0, 0.0);
21 PROCEDURE __BUILTIN__
abs (z
: COMPLEX
): REAL;
22 (* Returns the length of z *)
24 PROCEDURE __BUILTIN__
arg (z
: COMPLEX
): REAL;
25 (* Returns the angle that z subtends to the positive real axis *)
27 PROCEDURE __BUILTIN__
conj (z
: COMPLEX
): COMPLEX
;
28 (* Returns the complex conjugate of z *)
30 PROCEDURE __BUILTIN__
power (base
: COMPLEX
; exponent
: REAL): COMPLEX
;
31 (* Returns the value of the number base raised to the power exponent *)
33 PROCEDURE __BUILTIN__
sqrt (z
: COMPLEX
): COMPLEX
;
34 (* Returns the principal square root of z *)
36 PROCEDURE __BUILTIN__
exp (z
: COMPLEX
): COMPLEX
;
37 (* Returns the complex exponential of z *)
39 PROCEDURE __BUILTIN__
ln (z
: COMPLEX
): COMPLEX
;
40 (* Returns the principal value of the natural logarithm of z *)
42 PROCEDURE __BUILTIN__
sin (z
: COMPLEX
): COMPLEX
;
43 (* Returns the sine of z *)
45 PROCEDURE __BUILTIN__
cos (z
: COMPLEX
): COMPLEX
;
46 (* Returns the cosine of z *)
48 PROCEDURE __BUILTIN__
tan (z
: COMPLEX
): COMPLEX
;
49 (* Returns the tangent of z *)
51 PROCEDURE __BUILTIN__
arcsin (z
: COMPLEX
): COMPLEX
;
52 (* Returns the arcsine of z *)
54 PROCEDURE __BUILTIN__
arccos (z
: COMPLEX
): COMPLEX
;
55 (* Returns the arccosine of z *)
57 PROCEDURE __BUILTIN__
arctan (z
: COMPLEX
): COMPLEX
;
58 (* Returns the arctangent of z *)
60 PROCEDURE polarToComplex (abs
, arg
: REAL): COMPLEX
;
61 (* Returns the complex number with the specified polar coordinates *)
63 PROCEDURE scalarMult (scalar
: REAL; z
: COMPLEX
): COMPLEX
;
64 (* Returns the scalar product of scalar with z *)
66 PROCEDURE IsCMathException (): BOOLEAN;
67 (* Returns TRUE if the current coroutine is in the exceptional
68 execution state because of the raising of an exception in a
69 routine from this module; otherwise returns FALSE.