Skip to content

Commit 047e2f5

Browse files
authoredMar 8, 2025··
Clarify logarithm discussion (#173)
[no important files changed]
1 parent bc3579a commit 047e2f5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎exercises/practice/rational-numbers/.docs/instructions.append.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
The exponentiation of rational numbers with a real number requires calculating number to the power of a non-integer, a functionality that is not natively available in WebAssembly.
44

5-
However, you can also express `x ^ y` as `x ^ y = exp(y * log(x))`.
5+
However, you can also express `x ^ y` as `x ^ y = exp(y * ln(x))`.
66

7-
And fortunately, one can use different series to calculate the exponential and the logarithm.
7+
And fortunately, one can use different series to calculate the exponential and the natural logarithm.
88

99
## Exponential function
1010

@@ -19,16 +19,16 @@ exp(x) ≃ 1 + x + x ^ 2 / 2! + x ^ 3 / 3! + x ^ 4 / 4! + ... + x ^ n / n!
1919
There are multiple ways to efficiently calculate a natural logarithm. One of them is a series based on an [Inverse Hyperbolic Tangent](https://en.wikipedia.org/wiki/Logarithm#Inverse_hyperbolic_tangent):
2020

2121
```
22-
log(x) / 2 ≃ y + y ^ 3 / 3 + y ^ 5 / 5 + ... + y ^ n / n where y = (x - 1) / (x + 1)
22+
ln(x) / 2 ≃ y + y ^ 3 / 3 + y ^ 5 / 5 + ... + y ^ n / n where y = (x - 1) / (x + 1)
2323
```
2424

2525
There is also another Taylor Series to calculate the natural logarithm:
2626

2727
```
28-
log(x) = (x - 1) - (x - 1) ^ 2 / 2 + (x - 1) ^ 3 / 3 - (x - 1) ^ 4 / 4 ... + (x - 1) ^ n / n
28+
ln(x) = (x - 1) - (x - 1) ^ 2 / 2 + (x - 1) ^ 3 / 3 - (x - 1) ^ 4 / 4 ... + (x - 1) ^ n / n
2929
```
3030

31-
It is only accurate between +/-1. However, `ln(x * 10 ^ n) = ln(x) + n * ln10`, with `ln10` being approximately `2.30258509`.
31+
It is only accurate for `x` between 0 and 2. However we can also use `ln(x) = - ln(1 / x)`
3232

3333
## Integer exponentiation
3434

0 commit comments

Comments
 (0)
Please sign in to comment.