Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:

- uses: erlef/setup-beam@v1
with:
otp-version: "26.2"
gleam-version: "1.4.1"
otp-version: "27.0"
gleam-version: "1.8.0"

- uses: actions/setup-node@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:

- uses: erlef/setup-beam@v1
with:
otp-version: "26.2"
gleam-version: "1.4.1"
otp-version: "27.0"
gleam-version: "1.8.0"

- uses: actions/setup-node@v3
with:
Expand Down
8 changes: 4 additions & 4 deletions src/gleam_community/maths.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn divisors(n: Int) -> List(Int) {
fn find_divisors(n: Int) -> set.Set(Int) {
let nabs = float.absolute_value(int.to_float(n))
// Usage of let assert: 'nabs' is non-negative so no error should occur. The function
// 'float.squre_root' will only return an error in case a non-negative value is given as input.
// 'float.square_root' will only return an error in case a negative value is given as input.
let assert Ok(sqrt_result) = float.square_root(nabs)
let max = float.round(sqrt_result) + 1

Expand Down Expand Up @@ -241,7 +241,7 @@ fn do_find_divisors(n: Int, max: Int, acc: set.Set(Int), i: Int) -> set.Set(Int)
/// </div>
///
/// The function returns all the positive divisors of an integer, excluding the
/// number iteself.
/// number itself.
///
/// <details>
/// <summary>Example:</summary>
Expand Down Expand Up @@ -735,7 +735,7 @@ pub fn polar_to_cartesian(r: Float, theta: Float) -> #(Float, Float) {
pub fn cartesian_to_polar(x: Float, y: Float) -> #(Float, Float) {
// Calculate 'r' and 'theta'
// Usage of let assert: a sum of squares is always non-negative so no error should occur, i.e.,
// the function 'float.squre_root' will only return an error in case a non-negative value is given
// the function 'float.square_root' will only return an error in case a negative value is given
// as input.
let assert Ok(r) = float.square_root(x *. x +. y *. y)
let theta = atan2(y, x)
Expand Down Expand Up @@ -1706,7 +1706,7 @@ pub fn tau() -> Float {
pub fn golden_ratio() -> Float {
// Calculate the golden ratio: (1 + sqrt(5)) / 2
// Usage of let assert: A positive number '5' is given a input so no error should occur, i.e.,
// the function 'float.squre_root' will only return an error in case a non-negative value is
// the function 'float.square_root' will only return an error in case a negative value is
// given as input.
let assert Ok(sqrt5) = float.square_root(5.0)
{ 1.0 +. sqrt5 } /. 2.0
Expand Down
51 changes: 34 additions & 17 deletions test/gleam_community/elementary_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ pub fn natural_logarithm_test() {
let assert Ok(tol) = float.power(10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
maths.natural_logarithm(1.0)
|> should.equal(Ok(0.0))
let assert Ok(result) = maths.natural_logarithm(1.0)
result
|> maths.is_close(0.0, 0.0, tol)
|> should.be_true()

let assert Ok(result) = maths.natural_logarithm(0.5)
result
Expand All @@ -302,17 +304,24 @@ pub fn natural_logarithm_test() {
}

pub fn logarithm_test() {
let assert Ok(tol) = float.power(10.0, -6.0)

// Check that the function agrees, at some arbitrary input
// points, with known function values
maths.logarithm(10.0, 10.0)
|> should.equal(Ok(1.0))

maths.logarithm(10.0, 100.0)
|> should.equal(Ok(0.5))
let assert Ok(result) = maths.logarithm(10.0, 10.0)
result
|> maths.is_close(1.0, 0.0, tol)
|> should.be_true()

maths.logarithm(1.0, 0.25)
|> should.equal(Ok(0.0))
let assert Ok(result) = maths.logarithm(10.0, 100.0)
result
|> maths.is_close(0.5, 0.0, tol)
|> should.be_true()

let assert Ok(result) = maths.logarithm(1.0, 0.25)
result
|> maths.is_close(0.0, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
// outside its domain
maths.logarithm(1.0, 1.0)
Expand All @@ -324,11 +333,15 @@ pub fn logarithm_test() {
maths.logarithm(-1.0, 1.0)
|> should.be_error()

maths.logarithm(1.0, 10.0)
|> should.equal(Ok(0.0))
let assert Ok(result) = maths.logarithm(1.0, 10.0)
result
|> maths.is_close(0.0, 0.0, tol)
|> should.be_true()

maths.logarithm(maths.e(), maths.e())
|> should.equal(Ok(1.0))
let assert Ok(result) = maths.logarithm(maths.e(), maths.e())
result
|> maths.is_close(1.0, 0.0, tol)
|> should.be_true()

maths.logarithm(-1.0, 2.0)
|> should.be_error()
Expand All @@ -338,11 +351,15 @@ pub fn logarithm_2_test() {
let assert Ok(tol) = float.power(10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
maths.logarithm_2(1.0)
|> should.equal(Ok(0.0))
let assert Ok(result) = maths.logarithm_2(1.0)
result
|> maths.is_close(0.0, 0.0, tol)
|> should.be_true()

maths.logarithm_2(2.0)
|> should.equal(Ok(1.0))
let assert Ok(result) = maths.logarithm_2(2.0)
result
|> maths.is_close(1.0, 0.0, tol)
|> should.be_true()

let assert Ok(result) = maths.logarithm_2(5.0)
result
Expand Down