]>
Commit | Line | Data |
---|---|---|
1 | (* LongMath.mod implement the ISO LongMath specification. | |
2 | ||
3 | Copyright (C) 2023-2024 Free Software Foundation, Inc. | |
4 | Contributed by Gaius Mulley <gaiusmod2@gmail.com>. | |
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 ShortMath ; | |
28 | ||
29 | IMPORT libm ; | |
30 | IMPORT cbuiltin ; | |
31 | ||
32 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sqrtf)) sqrt (x: SHORTREAL): SHORTREAL; | |
33 | (* Returns the positive square root of x *) | |
34 | BEGIN | |
35 | RETURN cbuiltin.sqrtf (x) | |
36 | END sqrt ; | |
37 | ||
38 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_expf)) exp (x: SHORTREAL): SHORTREAL; | |
39 | (* Returns the exponential of x *) | |
40 | BEGIN | |
41 | RETURN cbuiltin.expf (x) | |
42 | END exp ; | |
43 | ||
44 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_logf)) ln (x: SHORTREAL): SHORTREAL; | |
45 | (* Returns the natural logarithm of x *) | |
46 | BEGIN | |
47 | RETURN cbuiltin.logf (x) | |
48 | END ln ; | |
49 | ||
50 | (* The angle in all trigonometric functions is measured in radians *) | |
51 | ||
52 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sinf)) sin (x: SHORTREAL): SHORTREAL; | |
53 | (* Returns the sine of x *) | |
54 | BEGIN | |
55 | RETURN cbuiltin.sinf (x) | |
56 | END sin ; | |
57 | ||
58 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cosf)) cos (x: SHORTREAL): SHORTREAL; | |
59 | (* Returns the cosine of x *) | |
60 | BEGIN | |
61 | RETURN cbuiltin.cosf (x) | |
62 | END cos ; | |
63 | ||
64 | PROCEDURE tan (x: SHORTREAL): SHORTREAL; | |
65 | (* Returns the tangent of x *) | |
66 | BEGIN | |
67 | RETURN libm.tanf (x) | |
68 | END tan ; | |
69 | ||
70 | PROCEDURE arcsin (x: SHORTREAL): SHORTREAL; | |
71 | (* Returns the arcsine of x *) | |
72 | BEGIN | |
73 | RETURN libm.asinf (x) | |
74 | END arcsin ; | |
75 | ||
76 | PROCEDURE arccos (x: SHORTREAL): SHORTREAL; | |
77 | (* Returns the arccosine of x *) | |
78 | BEGIN | |
79 | RETURN libm.acosf (x) | |
80 | END arccos ; | |
81 | ||
82 | PROCEDURE arctan (x: SHORTREAL): SHORTREAL; | |
83 | (* Returns the arctangent of x *) | |
84 | BEGIN | |
85 | RETURN libm.atanf (x) | |
86 | END arctan ; | |
87 | ||
88 | PROCEDURE power (base, exponent: SHORTREAL): SHORTREAL; | |
89 | (* Returns the value of the number base raised to the power exponent *) | |
90 | BEGIN | |
91 | RETURN libm.powf (base, exponent) | |
92 | END power ; | |
93 | ||
94 | PROCEDURE round (x: SHORTREAL) : INTEGER; | |
95 | (* Returns the value of x rounded to the nearest integer *) | |
96 | BEGIN | |
97 | RETURN TRUNC (x) | |
98 | END round ; | |
99 | ||
100 | PROCEDURE IsRMathException (): BOOLEAN; | |
101 | (* Returns TRUE if the current coroutine is in the | |
102 | exceptional execution state because of the raising | |
103 | of an exception in a routine from this module; otherwise | |
104 | returns FALSE. | |
105 | *) | |
106 | BEGIN | |
107 | RETURN FALSE | |
108 | END IsRMathException ; | |
109 | ||
110 | END ShortMath. |