Skip to content

Commit

Permalink
Update: stdlib v0.28 & gleam v0.28.3
Browse files Browse the repository at this point in the history
  • Loading branch information
NicklasXYZ committed Apr 22, 2023
1 parent 50f5c28 commit cd1f8e6
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: erlef/setup-beam@v1
with:
otp-version: "25.0"
gleam-version: "0.26.1"
gleam-version: "0.28.3"
- uses: actions/[email protected]
with:
node-version: "16.18.1"
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "A basic maths library"
repository = { type = "github", user = "gleam-community", repo = "maths" }

[dependencies]
gleam_stdlib = "~> 0.25"
gleam_stdlib = "~> 0.28"

[dev-dependencies]
gleeunit = "~> 0.7"
6 changes: 3 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.25.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "AD0F89928E0B919C8F8EDF640484633B28DBF88630A9E6AE504617A3E3E5B9A2" },
{ name = "gleeunit", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A1170754BF54F5DD6E9EF392FB1DC612528B007CCBE41B52F0C5453254708490" },
{ name = "gleam_stdlib", version = "0.28.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "73F0A89FADE5022CBEF6D6C3551F9ADCE7054AFCE0CB1DC4C6D5AB4CA62D0111" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
]

[requirements]
gleam_stdlib = "~> 0.25"
gleam_stdlib = "~> 0.28"
gleeunit = "~> 0.7"
26 changes: 13 additions & 13 deletions src/gleam_community/maths/float.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ pub fn round(
) -> Result(Float, String) {
case digits {
option.Some(a) -> {
assert Ok(p) = power(10.0, int.to_float(a))
let assert Ok(p) = power(10.0, int.to_float(a))
// Round the given input x using at the specified digit
do_round(p, x, mode)
}
Expand Down Expand Up @@ -444,7 +444,7 @@ fn round_to_nearest(p: Float, x: Float) -> Float {
case remainder {
_ if remainder >. 0.5 -> sign(x) *. truncate_float(xabs +. 1.0) /. p
_ if remainder == 0.5 -> {
assert Ok(is_even) = int.modulo(to_int(xabs), 2)
let assert Ok(is_even) = int.modulo(to_int(xabs), 2)
case is_even == 0 {
True -> sign(x) *. xabs_truncated /. p
False -> sign(x) *. truncate_float(xabs +. 1.0) /. p
Expand Down Expand Up @@ -1158,8 +1158,8 @@ pub fn logarithm(x: Float, base: option.Option(Float)) -> Result(Float, String)
case a >. 0.0 && a != 1.0 {
True -> {
// Apply the "change of base formula"
assert Ok(numerator) = logarithm_10(x)
assert Ok(denominator) = logarithm_10(a)
let assert Ok(numerator) = logarithm_10(x)
let assert Ok(denominator) = logarithm_10(a)
numerator /. denominator
|> Ok
}
Expand Down Expand Up @@ -1480,7 +1480,7 @@ pub fn square_root(x: Float) -> Result(Float, String) {
"Invalid input argument: x < 0."
|> Error
False -> {
assert Ok(result) = power(x, 1.0 /. 2.0)
let assert Ok(result) = power(x, 1.0 /. 2.0)
result
|> Ok
}
Expand Down Expand Up @@ -1532,7 +1532,7 @@ pub fn cube_root(x: Float) -> Result(Float, String) {
"Invalid input argument: x < 0."
|> Error
False -> {
assert Ok(result) = power(x, 1.0 /. 3.0)
let assert Ok(result) = power(x, 1.0 /. 3.0)
result
|> Ok
}
Expand Down Expand Up @@ -1589,7 +1589,7 @@ pub fn nth_root(x: Float, n: Int) -> Result(Float, String) {
False ->
case n >= 1 {
True -> {
assert Ok(result) = power(x, 1.0 /. int.to_float(n))
let assert Ok(result) = power(x, 1.0 /. int.to_float(n))
result
|> Ok
}
Expand Down Expand Up @@ -1634,9 +1634,9 @@ pub fn nth_root(x: Float, n: Int) -> Result(Float, String) {
/// </div>
///
pub fn hypotenuse(x: Float, y: Float) -> Float {
assert Ok(term1) = power(x, 2.0)
assert Ok(term2) = power(y, 2.0)
assert Ok(h) = square_root(term1 +. term2)
let assert Ok(term1) = power(x, 2.0)
let assert Ok(term2) = power(y, 2.0)
let assert Ok(h) = square_root(term1 +. term2)
h
}

Expand Down Expand Up @@ -2192,8 +2192,8 @@ fn gamma_lanczos(x: Float) -> Float {
},
)
let t: Float = z +. lanczos_g +. 0.5
assert Ok(v1) = power(2.0 *. pi(), 0.5)
assert Ok(v2) = power(t, z +. 0.5)
let assert Ok(v1) = power(2.0 *. pi(), 0.5)
let assert Ok(v2) = power(t, z +. 0.5)
v1 *. v2 *. exponential(-1.0 *. t) *. x
}
}
Expand All @@ -2219,7 +2219,7 @@ fn gamma_lanczos(x: Float) -> Float {
pub fn incomplete_gamma(a: Float, x: Float) -> Result(Float, String) {
case a >. 0.0 && x >=. 0.0 {
True -> {
assert Ok(v) = power(x, a)
let assert Ok(v) = power(x, a)
v *. exponential(-1.0 *. x) *. incomplete_gamma_sum(
a,
x,
Expand Down
56 changes: 28 additions & 28 deletions src/gleam_community/maths/float_list.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import gleam/iterator
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
///
/// [1.0, 1.0, 1.0]
/// |> float_list.norm(1.0)
Expand Down Expand Up @@ -107,11 +107,11 @@ pub fn norm(arr: List(Float), p: Float) -> Float {
|> list.fold(
0.0,
fn(acc: Float, a: Float) -> Float {
assert Ok(result) = floatx.power(float.absolute_value(a), p)
let assert Ok(result) = floatx.power(float.absolute_value(a), p)
result +. acc
},
)
assert Ok(result) = floatx.power(agg, 1.0 /. p)
let assert Ok(result) = floatx.power(agg, 1.0 /. p)
result
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn norm(arr: List(Float), p: Float) -> Float {
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
///
/// // Empty lists returns 0.0
/// float_list.minkowski_distance([], [], 1.0)
Expand All @@ -155,7 +155,7 @@ pub fn norm(arr: List(Float), p: Float) -> Float {
/// float_list.minkowski_distance([0.0, 0.0], [0.0, 0.0], -1.0)
/// |> should.be_error()
///
/// assert Ok(result) = float_list.minkowski_distance([0.0, 0.0], [1.0, 2.0], 1.0)
/// let assert Ok(result) = float_list.minkowski_distance([0.0, 0.0], [1.0, 2.0], 1.0)
/// result
/// |> floatx.is_close(3.0, 0.0, tol)
/// |> should.be_true()
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn minkowski_distance(
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
///
/// // Empty lists returns 0.0
/// float_list.euclidean_distance([], [])
Expand All @@ -227,7 +227,7 @@ pub fn minkowski_distance(
/// float_list.euclidean_distance([], [1.0])
/// |> should.be_error()
///
/// assert Ok(result) = float_list.euclidean_distance([0.0, 0.0], [1.0, 2.0])
/// let assert Ok(result) = float_list.euclidean_distance([0.0, 0.0], [1.0, 2.0])
/// result
/// |> floatx.is_close(2.23606797749979, 0.0, tol)
/// |> should.be_true()
Expand Down Expand Up @@ -269,7 +269,7 @@ pub fn euclidean_distance(
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
///
/// // Empty lists returns 0.0
/// float_list.manhatten_distance([], [])
Expand All @@ -279,7 +279,7 @@ pub fn euclidean_distance(
/// float_list.manhatten_distance([], [1.0])
/// |> should.be_error()
///
/// assert Ok(result) = float_list.manhatten_distance([0.0, 0.0], [1.0, 2.0])
/// let assert Ok(result) = float_list.manhatten_distance([0.0, 0.0], [1.0, 2.0])
/// result
/// |> floatx.is_close(3.0, 0.0, tol)
/// |> should.be_true()
Expand Down Expand Up @@ -315,9 +315,9 @@ pub fn manhatten_distance(
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// assert Ok(linspace) = float_list.linear_space(10.0, 50.0, 5, True)
/// assert Ok(result) =
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(linspace) = float_list.linear_space(10.0, 50.0, 5, True)
/// let assert Ok(result) =
/// float_list.all_close(linspace, [10.0, 20.0, 30.0, 40.0, 50.0], 0.0, tol)
/// result
/// |> list.all(fn(x) { x == True })
Expand Down Expand Up @@ -390,9 +390,9 @@ pub fn linear_space(
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// assert Ok(logspace) = float_list.logarithmic_space(1.0, 3.0, 3, True, 10.0)
/// assert Ok(result) =
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(logspace) = float_list.logarithmic_space(1.0, 3.0, 3, True, 10.0)
/// let assert Ok(result) =
/// float_list.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
/// result
/// |> list.all(fn(x) { x == True })
Expand All @@ -419,10 +419,10 @@ pub fn logarithmic_space(
) -> Result(List(Float), String) {
case num > 0 {
True -> {
assert Ok(linspace) = linear_space(start, stop, num, endpoint)
let assert Ok(linspace) = linear_space(start, stop, num, endpoint)
linspace
|> list.map(fn(i: Float) -> Float {
assert Ok(result) = floatx.power(base, i)
let assert Ok(result) = floatx.power(base, i)
result
})
|> Ok
Expand Down Expand Up @@ -450,9 +450,9 @@ pub fn logarithmic_space(
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// assert Ok(tol) = floatx.power(-10.0, -6.0)
/// assert Ok(logspace) = float_list.geometric_space(10.0, 1000.0, 3, True)
/// assert Ok(result) =
/// let assert Ok(tol) = floatx.power(-10.0, -6.0)
/// let assert Ok(logspace) = float_list.geometric_space(10.0, 1000.0, 3, True)
/// let assert Ok(result) =
/// float_list.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol)
/// result
/// |> list.all(fn(x) { x == True })
Expand Down Expand Up @@ -490,8 +490,8 @@ pub fn geometric_space(
False ->
case num > 0 {
True -> {
assert Ok(log_start) = floatx.logarithm_10(start)
assert Ok(log_stop) = floatx.logarithm_10(stop)
let assert Ok(log_start) = floatx.logarithm_10(start)
let assert Ok(log_stop) = floatx.logarithm_10(stop)
logarithmic_space(log_start, log_stop, num, endpoint, 10.0)
}
False ->
Expand Down Expand Up @@ -791,7 +791,7 @@ pub fn maximum(arr: List(Float)) -> Result(Float, String) {
"Invalid input argument: The list is empty."
|> Error
_ -> {
assert Ok(val0) = list.at(arr, 0)
let assert Ok(val0) = list.at(arr, 0)
arr
|> list.fold(
val0,
Expand Down Expand Up @@ -846,7 +846,7 @@ pub fn minimum(arr: List(Float)) -> Result(Float, String) {
"Invalid input argument: The list is empty."
|> Error
_ -> {
assert Ok(val0) = list.at(arr, 0)
let assert Ok(val0) = list.at(arr, 0)
arr
|> list.fold(
val0,
Expand Down Expand Up @@ -901,7 +901,7 @@ pub fn arg_maximum(arr: List(Float)) -> Result(List(Int), String) {
"Invalid input argument: The list is empty."
|> Error
_ -> {
assert Ok(max) =
let assert Ok(max) =
arr
|> maximum()
arr
Expand Down Expand Up @@ -961,7 +961,7 @@ pub fn arg_minimum(arr: List(Float)) -> Result(List(Int), String) {
"Invalid input argument: The list is empty."
|> Error
_ -> {
assert Ok(min) =
let assert Ok(min) =
arr
|> minimum()
arr
Expand Down Expand Up @@ -1021,8 +1021,8 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) {
"Invalid input argument: The list is empty."
|> Error
_ -> {
assert Ok(val_max) = list.at(arr, 0)
assert Ok(val_min) = list.at(arr, 0)
let assert Ok(val_max) = list.at(arr, 0)
let assert Ok(val_min) = list.at(arr, 0)
arr
|> list.fold(
#(val_min, val_max),
Expand Down
12 changes: 6 additions & 6 deletions src/gleam_community/maths/int.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ pub fn permutation(n: Int, k: Int) -> Result(Int, String) {
1
|> Ok
False -> {
assert Ok(v1) = factorial(n)
assert Ok(v2) = factorial(n - k)
let assert Ok(v1) = factorial(n)
let assert Ok(v2) = factorial(n - k)
v1 / v2
|> Ok
}
Expand Down Expand Up @@ -520,9 +520,9 @@ pub fn absolute_difference(a: Int, b: Int) -> Int {
/// </div>
///
pub fn is_power(x: Int, y: Int) -> Bool {
assert Ok(value) =
let assert Ok(value) =
floatx.logarithm(int.to_float(x), option.Some(int.to_float(y)))
assert Ok(truncated) = floatx.truncate(value, option.Some(0))
let assert Ok(truncated) = floatx.truncate(value, option.Some(0))
let rem = value -. truncated
rem == 0.0
}
Expand Down Expand Up @@ -654,7 +654,7 @@ pub fn divisors(n: Int) -> List(Int) {

pub fn find_divisors(n: Int) -> List(Int) {
let nabs: Float = float.absolute_value(to_float(n))
assert Ok(sqrt_result) = floatx.square_root(nabs)
let assert Ok(sqrt_result) = floatx.square_root(nabs)
let max: Int = floatx.to_int(sqrt_result) + 1
list.range(2, max)
|> list.fold(
Expand Down Expand Up @@ -713,7 +713,7 @@ pub fn do_gcd(x: Int, y: Int) -> Int {
case x == 0 {
True -> y
False -> {
assert Ok(z) = int.modulo(y, x)
let assert Ok(z) = int.modulo(y, x)
do_gcd(z, x)
}
}
Expand Down
Loading

0 comments on commit cd1f8e6

Please sign in to comment.