@@ -14,29 +14,33 @@ The result of @"log10" of @"E".
14
14
const dec LOG10_E = 0.434294481903251;
15
15
16
16
/%
17
- @asm
17
+ @approx: This function uses the @"pow" function to compute the answer. This function
18
+ is not 100% accurate but will provide a very good approximation.
19
+
20
+ Computes the square root of @"radicant".
18
21
19
- Returns the square root of @"x".
20
- Uses the `sqrtsd` assembly instruction.
22
+ Use @"root" if you want an arbitrary index.
21
23
%/
22
- func dec sqrt(dec x) {
23
- dec o = 0.0;
24
- assembly {
25
- vlist_get rdi, $x$
26
- movq xmm0, rdi
27
- sqrtsd xmm0, xmm0
28
- movq rdi, xmm0
29
- vlist_set $o$
30
- }
31
- ret o;
24
+ func dec sqrt(dec radicant) {
25
+ ret pow(radicant, 0.5);
26
+ }
27
+
28
+ /%
29
+ @approx: This function uses the @"pow" function to compute the answer. This function
30
+ is not 100% accurate but will provide a very good approximation.
31
+
32
+ Computes the @"index"th root of @"radicant".
33
+
34
+ Use @"sqrt" for an index of `2`.
35
+ %/
36
+ func dec root(dec index, dec radicant) {
37
+ ret pow(radicant, 1.0 / index);
32
38
}
33
39
34
40
/%
35
41
@complexity: O(log(@"exponent"))
36
42
37
43
Computes the power of @"base" (decimal) to @"exponent" (integer).
38
-
39
- This function uses the divide-and-conquer algorithm.
40
44
%/
41
45
func dec powInt(dec base, int exponent) {
42
46
// Special cases
@@ -80,8 +84,6 @@ func dec powInt(dec base, int exponent) {
80
84
@todo: Add support for negative bases.
81
85
82
86
Computes @"base" ^ @"exponent".
83
-
84
- This function uses @"exp" and @"ln" to compute the power.
85
87
%/
86
88
func dec pow(dec base, dec exponent) {
87
89
// log10(base ^ exponent) = log10(base) * exponent
@@ -163,8 +165,6 @@ func dec log10(dec x) {
163
165
is not 100% accurate but will provide a very good approximation.
164
166
165
167
Computes the natural log (log base e) of @"x".
166
-
167
- This function uses @"log10" to compute the natural log.
168
168
%/
169
169
func dec ln(dec x) {
170
170
// ln(x) = log10(x) / log10(e)
@@ -179,8 +179,6 @@ Computes the log of @"x" with an arbitrary base, @"base".
179
179
180
180
Use @"log10" for a base of `10`.
181
181
Use @"ln" for a base of `e`.
182
-
183
- This function uses two calls to @"log10" to compute the result.
184
182
%/
185
183
func dec log(dec x, dec base) {
186
184
if (base <= 0.0) {
@@ -196,7 +194,7 @@ func dec log(dec x, dec base) {
196
194
@approx: This function uses the Taylor series expansion of exp. This function
197
195
is not 100% accurate but will provide a very good approximation.
198
196
199
- Computes e ^ @"x".
197
+ Computes e ^ @"x" or exp(@"x") .
200
198
%/
201
199
func dec exp(dec x) {
202
200
// Special cases
0 commit comments