Skip to content

Commit 81b633b

Browse files
committed
Constants
1 parent 9f724b7 commit 81b633b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Math/Core.scope

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
namespace Math;
22

3+
/%
4+
The ratio of a circle's circumference to its diameter.
5+
%/
6+
const dec PI = 3.141592653589793;
7+
/%
8+
Euler's number. The base of the natural log.
9+
%/
10+
const dec E = 2.718281828459045;
11+
/%
12+
The result of @"log10" of @"E".
13+
%/
14+
const dec LOG10_E = 0.434294481903251;
15+
316
/%
417
@asm
518

@@ -142,8 +155,7 @@ func dec log10(dec x) {
142155
// Finally, return
143156
// log10(x) = ln(x) * log10(e) + b
144157

145-
// log10(e) = 0.434294481903251
146-
ret seriesSum * 0.434294481903251 + b;
158+
ret seriesSum * LOG10_E + b;
147159
}
148160

149161
/%
@@ -156,7 +168,7 @@ This function uses @"log10" to compute the natural log.
156168
%/
157169
func dec ln(dec x) {
158170
// ln(x) = log10(x) / log10(e)
159-
ret log10(x) / 0.434294481903251;
171+
ret log10(x) / LOG10_E;
160172
}
161173

162174
/%
@@ -187,9 +199,6 @@ func dec log(dec x, dec base) {
187199
Computes e ^ @"x".
188200
%/
189201
func dec exp(dec x) {
190-
// Temp until global constants
191-
dec E = 2.718281828459045;
192-
193202
// Special cases
194203

195204
if (x == -infinity) {

Math/Trig.scope

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ Computes the sine of @"x" (in radians).
1111
Please note that an input of @"PI" **will not** return exactly `0.0`.
1212
%/
1313
func dec sin(dec x) {
14-
// Temp until global constants
15-
dec PI = 3.141592653589793;
16-
1714
// Special cases
1815

1916
if (x == infinity) {
@@ -73,9 +70,6 @@ Computes the cosine of @"x" (in radians).
7370
Please note that an input of @"PI" **will not** return exactly `-1.0`.
7471
%/
7572
func dec cos(dec x) {
76-
// Temp until global constants
77-
dec PI = 3.141592653589793;
78-
7973
ret sin(x + PI / 2.0);
8074
}
8175

0 commit comments

Comments
 (0)