@@ -11,18 +11,17 @@ The library supports both targets: Erlang and JavaScript.
11
11
12
12
``` gleam
13
13
import gleam/float
14
+ import gleam/list
14
15
import gleam/yielder
15
16
import gleam_community/maths
16
17
import gleeunit/should
17
18
18
19
pub fn example() {
19
20
// Evaluate the sine function
20
21
let result = maths.sin(maths.pi())
21
-
22
22
// Set the relative and absolute tolerance
23
23
let assert Ok(absolute_tol) = float.power(10.0, -6.0)
24
24
let relative_tol = 0.0
25
-
26
25
// Check that the value is very close to 0.0
27
26
// That is, if 'result' is within +/- 10^(-6)
28
27
maths.is_close(result, 0.0, relative_tol, absolute_tol)
@@ -32,6 +31,10 @@ pub fn example() {
32
31
maths.gcd(54, 24)
33
32
|> should.equal(6)
34
33
34
+ // Determine if 999983 is a prime number
35
+ maths.is_prime(999_983)
36
+ |> should.equal(True)
37
+
35
38
// Find the minimum and maximum of a list
36
39
maths.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
37
40
|> should.equal(Ok(#(3.0, 50.0)))
@@ -46,9 +49,17 @@ pub fn example() {
46
49
|> yielder.to_list()
47
50
|> should.equal([[1, 2], [1, 3], [2, 3]])
48
51
49
- // Compute the Cosine Similarity between two (orthogonal) vectors
52
+ // Compute the Cosine Similarity between two (orthogonal) " vectors"
50
53
maths.cosine_similarity([#(-1.0, 1.0), #(1.0, 1.0), #(0.0, -1.0)])
51
54
|> should.equal(Ok(0.0))
55
+
56
+ // Generate a list of 3 logarithmically-spaced points over a specified
57
+ // interval, i.e., [10^1, 10^3]
58
+ let assert Ok(logspace) = maths.logarithmic_space(1.0, 3.0, 3, True, 10.0)
59
+ let pairs = logspace |> list.zip([10.0, 100.0, 1000.0])
60
+ pairs
61
+ |> list.all(fn(x) { x.0 == x.1 })
62
+ |> should.be_true()
52
63
}
53
64
54
65
```
0 commit comments