Skip to content

Commit 9d99a47

Browse files
committed
update README
1 parent d619c53 commit 9d99a47

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ The library supports both targets: Erlang and JavaScript.
1111

1212
```gleam
1313
import gleam/float
14+
import gleam/list
1415
import gleam/yielder
1516
import gleam_community/maths
1617
import gleeunit/should
1718
1819
pub fn example() {
1920
// Evaluate the sine function
2021
let result = maths.sin(maths.pi())
21-
2222
// Set the relative and absolute tolerance
2323
let assert Ok(absolute_tol) = float.power(10.0, -6.0)
2424
let relative_tol = 0.0
25-
2625
// Check that the value is very close to 0.0
2726
// That is, if 'result' is within +/- 10^(-6)
2827
maths.is_close(result, 0.0, relative_tol, absolute_tol)
@@ -32,6 +31,10 @@ pub fn example() {
3231
maths.gcd(54, 24)
3332
|> should.equal(6)
3433
34+
// Determine if 999983 is a prime number
35+
maths.is_prime(999_983)
36+
|> should.equal(True)
37+
3538
// Find the minimum and maximum of a list
3639
maths.extrema([10.0, 3.0, 50.0, 20.0, 3.0], float.compare)
3740
|> should.equal(Ok(#(3.0, 50.0)))
@@ -46,9 +49,17 @@ pub fn example() {
4649
|> yielder.to_list()
4750
|> should.equal([[1, 2], [1, 3], [2, 3]])
4851
49-
// Compute the Cosine Similarity between two (orthogonal) vectors
52+
// Compute the Cosine Similarity between two (orthogonal) "vectors"
5053
maths.cosine_similarity([#(-1.0, 1.0), #(1.0, 1.0), #(0.0, -1.0)])
5154
|> 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()
5263
}
5364
5465
```

0 commit comments

Comments
 (0)