]>
Commit | Line | Data |
---|---|---|
1eee94d3 GM |
1 | (* RealMath.mod implement the ISO RealMath specification. |
2 | ||
83ffe9cd | 3 | Copyright (C) 2003-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
4 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
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 RealMath ; | |
28 | ||
29 | IMPORT libm ; | |
30 | IMPORT cbuiltin ; | |
31 | ||
32 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sqrt)) sqrt (x: REAL): REAL; | |
33 | (* Returns the positive square root of x *) | |
34 | BEGIN | |
35 | RETURN cbuiltin.sqrt(x) | |
36 | END sqrt ; | |
37 | ||
38 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_exp)) exp (x: REAL): REAL; | |
39 | (* Returns the exponential of x *) | |
40 | BEGIN | |
41 | RETURN cbuiltin.exp(x) | |
42 | END exp ; | |
43 | ||
44 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_log)) ln (x: REAL): REAL; | |
45 | (* Returns the natural logarithm of x *) | |
46 | BEGIN | |
47 | RETURN cbuiltin.log(x) | |
48 | END ln ; | |
49 | ||
50 | (* The angle in all trigonometric functions is measured in radians *) | |
51 | ||
52 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_sin)) sin (x: REAL): REAL; | |
53 | (* Returns the sine of x *) | |
54 | BEGIN | |
55 | RETURN cbuiltin.sin(x) | |
56 | END sin ; | |
57 | ||
58 | PROCEDURE __ATTRIBUTE__ __BUILTIN__ ((__builtin_cos)) cos (x: REAL): REAL; | |
59 | (* Returns the cosine of x *) | |
60 | BEGIN | |
61 | RETURN cbuiltin.cos(x) | |
62 | END cos ; | |
63 | ||
64 | PROCEDURE tan (x: REAL): REAL; | |
65 | (* Returns the tangent of x *) | |
66 | BEGIN | |
67 | RETURN libm.tan(x) | |
68 | END tan ; | |
69 | ||
70 | PROCEDURE arcsin (x: REAL): REAL; | |
71 | (* Returns the arcsine of x *) | |
72 | BEGIN | |
73 | RETURN libm.asin(x) | |
74 | END arcsin ; | |
75 | ||
76 | PROCEDURE arccos (x: REAL): REAL; | |
77 | (* Returns the arccosine of x *) | |
78 | BEGIN | |
79 | RETURN libm.acos(x) | |
80 | END arccos ; | |
81 | ||
82 | PROCEDURE arctan (x: REAL): REAL; | |
83 | (* Returns the arctangent of x *) | |
84 | BEGIN | |
85 | RETURN libm.atan(x) | |
86 | END arctan ; | |
87 | ||
88 | PROCEDURE power (base, exponent: REAL): REAL; | |
89 | (* Returns the value of the number base raised to the power exponent *) | |
90 | BEGIN | |
91 | RETURN libm.pow(base, exponent) | |
92 | END power ; | |
93 | ||
94 | PROCEDURE round (x: REAL): INTEGER; | |
95 | (* Returns the value of x rounded to the nearest integer *) | |
96 | BEGIN | |
97 | RETURN TRUNC(x) (* hmm we could provide access to the GNU Modula-2 built-in *) | |
98 | END round ; | |
99 | ||
100 | PROCEDURE IsRMathException (): BOOLEAN; | |
101 | (* Returns TRUE if the current coroutine is in the exceptional execution state | |
102 | because of the raising of an exception in a routine from this module; otherwise | |
103 | returns FALSE. | |
104 | *) | |
105 | BEGIN | |
106 | RETURN FALSE | |
107 | END IsRMathException ; | |
108 | ||
109 | END RealMath. |