| 1 |
(* LongComplexMath.mod implement the ISO LongComplexMath specification. |
| 2 |
|
| 3 |
Copyright (C) 2009-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 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) |
| 11 |
any later version. |
| 12 |
|
| 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. |
| 17 |
|
| 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. |
| 21 |
|
| 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/>. *) |
| 26 |
|
| 27 |
IMPLEMENTATION MODULE LongComplexMath ; |
| 28 |
|
| 29 |
IMPORT cbuiltin ; |
| 30 |
|
| 31 |
|
| 32 |
(* Returns the length of z *) |
| 33 |
|
| 34 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cabsl)) abs (z: LONGCOMPLEX): LONGREAL; |
| 35 |
BEGIN |
| 36 |
RETURN cbuiltin.cabsl (z) |
| 37 |
END abs ; |
| 38 |
|
| 39 |
|
| 40 |
(* Returns the angle that z subtends to the positive real axis *) |
| 41 |
|
| 42 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cargl)) arg (z: LONGCOMPLEX): LONGREAL; |
| 43 |
BEGIN |
| 44 |
RETURN cbuiltin.cargl (z) |
| 45 |
END arg ; |
| 46 |
|
| 47 |
|
| 48 |
(* Returns the complex conjugate of z *) |
| 49 |
|
| 50 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_conjl)) conj (z: LONGCOMPLEX): LONGCOMPLEX; |
| 51 |
BEGIN |
| 52 |
RETURN cbuiltin.conjl (z) |
| 53 |
END conj ; |
| 54 |
|
| 55 |
|
| 56 |
(* Returns the value of the number base raised to the power exponent *) |
| 57 |
|
| 58 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cpowerl)) power (base: LONGCOMPLEX; exponent: LONGREAL): LONGCOMPLEX; |
| 59 |
BEGIN |
| 60 |
RETURN cbuiltin.cpowl (base, exponent) |
| 61 |
END power ; |
| 62 |
|
| 63 |
|
| 64 |
(* Returns the principal square root of z *) |
| 65 |
|
| 66 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_csqrtl)) sqrt (z: LONGCOMPLEX): LONGCOMPLEX; |
| 67 |
BEGIN |
| 68 |
RETURN cbuiltin.csqrtl (z) |
| 69 |
END sqrt ; |
| 70 |
|
| 71 |
|
| 72 |
(* Returns the complex exponential of z *) |
| 73 |
|
| 74 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cexpl)) exp (z: LONGCOMPLEX): LONGCOMPLEX; |
| 75 |
BEGIN |
| 76 |
RETURN cbuiltin.cexpl (z) |
| 77 |
END exp ; |
| 78 |
|
| 79 |
|
| 80 |
(* Returns the principal value of the natural logarithm of z *) |
| 81 |
|
| 82 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_clnl)) ln (z: LONGCOMPLEX): LONGCOMPLEX; |
| 83 |
BEGIN |
| 84 |
RETURN cbuiltin.clogl (z) |
| 85 |
END ln ; |
| 86 |
|
| 87 |
|
| 88 |
(* Returns the sine of z *) |
| 89 |
|
| 90 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_csinl)) sin (z: LONGCOMPLEX): LONGCOMPLEX; |
| 91 |
BEGIN |
| 92 |
RETURN cbuiltin.csinl (z) |
| 93 |
END sin ; |
| 94 |
|
| 95 |
|
| 96 |
(* Returns the cosine of z *) |
| 97 |
|
| 98 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_ccosl)) cos (z: LONGCOMPLEX): LONGCOMPLEX; |
| 99 |
BEGIN |
| 100 |
RETURN cbuiltin.ccosl (z) |
| 101 |
END cos ; |
| 102 |
|
| 103 |
|
| 104 |
(* Returns the tangent of z *) |
| 105 |
|
| 106 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_ctanl)) tan (z: LONGCOMPLEX): LONGCOMPLEX; |
| 107 |
BEGIN |
| 108 |
RETURN cbuiltin.ctanl (z) |
| 109 |
END tan ; |
| 110 |
|
| 111 |
|
| 112 |
(* Returns the arcsine of z *) |
| 113 |
|
| 114 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_carcsinl)) arcsin (z: LONGCOMPLEX): LONGCOMPLEX; |
| 115 |
BEGIN |
| 116 |
RETURN cbuiltin.casinl (z) |
| 117 |
END arcsin ; |
| 118 |
|
| 119 |
|
| 120 |
(* Returns the arccosine of z *) |
| 121 |
|
| 122 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_carccosl)) arccos (z: LONGCOMPLEX): LONGCOMPLEX; |
| 123 |
BEGIN |
| 124 |
RETURN cbuiltin.cacosl (z) |
| 125 |
END arccos ; |
| 126 |
|
| 127 |
|
| 128 |
(* Returns the arctangent of z *) |
| 129 |
|
| 130 |
PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_carctanl)) arctan (z: LONGCOMPLEX): LONGCOMPLEX; |
| 131 |
BEGIN |
| 132 |
RETURN cbuiltin.catanl (z) |
| 133 |
END arctan ; |
| 134 |
|
| 135 |
|
| 136 |
(* Returns the complex number with the specified polar coordinates *) |
| 137 |
|
| 138 |
PROCEDURE polarToComplex (abs, arg: LONGREAL): LONGCOMPLEX; |
| 139 |
BEGIN |
| 140 |
RETURN CMPLX (abs*cbuiltin.cosl(arg), abs*cbuiltin.sinl(arg)) |
| 141 |
END polarToComplex ; |
| 142 |
|
| 143 |
|
| 144 |
(* Returns the scalar product of scalar with z *) |
| 145 |
|
| 146 |
PROCEDURE scalarMult (scalar: LONGREAL; z: LONGCOMPLEX): LONGCOMPLEX; |
| 147 |
BEGIN |
| 148 |
RETURN CMPLX (RE(z)*scalar, IM(z)*scalar) |
| 149 |
END scalarMult ; |
| 150 |
|
| 151 |
|
| 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. |
| 155 |
*) |
| 156 |
|
| 157 |
PROCEDURE IsCMathException (): BOOLEAN; |
| 158 |
BEGIN |
| 159 |
(* --fixme-- we should really attempt to catch sigfpe in these procedures *) |
| 160 |
RETURN( FALSE ) |
| 161 |
END IsCMathException ; |
| 162 |
|
| 163 |
|
| 164 |
END LongComplexMath. |