1 (* ShortComplexMath.mod implements access to the ShortComplex intrincics.
3 Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
27 IMPLEMENTATION MODULE ShortComplexMath
;
32 (* Returns the length of z *)
34 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_cabsf
)) abs (z
: SHORTCOMPLEX
): SHORTREAL
;
36 RETURN cbuiltin.
cabsf (z
)
40 (* Returns the angle that z subtends to the positive real axis *)
42 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_cargf
)) arg (z
: SHORTCOMPLEX
): SHORTREAL
;
44 RETURN cbuiltin.
cargf (z
)
48 (* Returns the complex conjugate of z *)
50 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_conjf
)) conj (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
52 RETURN cbuiltin.
conjf (z
)
56 (* Returns the value of the number base raised to the power exponent *)
58 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_cpowerf
)) power (base
: SHORTCOMPLEX
; exponent
: SHORTREAL
): SHORTCOMPLEX
;
60 RETURN cbuiltin.
cpowf (base
, exponent
)
64 (* Returns the principal square root of z *)
66 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_csqrtf
)) sqrt (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
68 RETURN cbuiltin.
csqrtf (z
)
72 (* Returns the complex exponential of z *)
74 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_cexpf
)) exp (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
76 RETURN cbuiltin.
cexpf (z
)
80 (* Returns the principal value of the natural logarithm of z *)
82 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_clnf
)) ln (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
84 RETURN cbuiltin.
clogf (z
)
88 (* Returns the sine of z *)
90 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_csinf
)) sin (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
92 RETURN cbuiltin.
csinf (z
)
96 (* Returns the cosine of z *)
98 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_ccosf
)) cos (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
100 RETURN cbuiltin.
ccosf (z
)
104 (* Returns the tangent of z *)
106 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_ctanf
)) tan (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
108 RETURN cbuiltin.
ctanf (z
)
112 (* Returns the arcsine of z *)
114 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_carcsinf
)) arcsin (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
116 RETURN cbuiltin.
casinf (z
)
120 (* Returns the arccosine of z *)
122 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_carccosf
)) arccos (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
124 RETURN cbuiltin.
cacosf (z
)
128 (* Returns the arctangent of z *)
130 PROCEDURE __ATTRIBUTE__
__BUILTIN__ ((__builtin_carctanf
)) arctan (z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
132 RETURN cbuiltin.
catanf (z
)
136 (* Returns the complex number with the specified polar coordinates *)
138 PROCEDURE polarToComplex (abs
, arg
: SHORTREAL
): SHORTCOMPLEX
;
140 RETURN CMPLX (abs
*cbuiltin.
cosf(arg
), abs
*cbuiltin.
sinf(arg
))
144 (* Returns the scalar product of scalar with z *)
146 PROCEDURE scalarMult (scalar
: SHORTREAL
; z
: SHORTCOMPLEX
): SHORTCOMPLEX
;
148 RETURN CMPLX (RE(z
)*scalar
, IM(z
)*scalar
)
152 (* Returns TRUE if the current coroutine is in the exceptional
153 execution state because of the raising of an exception in a
154 routine from this module; otherwise returns FALSE.
157 PROCEDURE IsCMathException (): BOOLEAN;
159 (* --fixme-- we should really attempt to catch sigfpe in these procedures *)
161 END IsCMathException
;
164 END ShortComplexMath.