mirror of
https://github.com/sigmasternchen/gleam-community-maths
synced 2025-03-15 07:59:01 +00:00
Rename functions. Fix FFI
This commit is contained in:
parent
7c83c10a68
commit
e01373c0bf
7 changed files with 138 additions and 151 deletions
|
@ -110,13 +110,13 @@ fn do_gcd(x: Int, y: Int) -> Int {
|
||||||
/// import gleam_community/maths
|
/// import gleam_community/maths
|
||||||
///
|
///
|
||||||
/// pub fn example() {
|
/// pub fn example() {
|
||||||
/// maths.int_euclidean_modulo(15, 4)
|
/// maths.euclidean_modulo(15, 4)
|
||||||
/// |> should.equal(3)
|
/// |> should.equal(3)
|
||||||
///
|
///
|
||||||
/// maths.int_euclidean_modulo(-3, -2)
|
/// maths.euclidean_modulo(-3, -2)
|
||||||
/// |> should.equal(1)
|
/// |> should.equal(1)
|
||||||
///
|
///
|
||||||
/// maths.int_euclidean_modulo(5, 0)
|
/// maths.euclidean_modulo(5, 0)
|
||||||
/// |> should.equal(0)
|
/// |> should.equal(0)
|
||||||
/// }
|
/// }
|
||||||
/// </details>
|
/// </details>
|
||||||
|
@ -127,7 +127,7 @@ fn do_gcd(x: Int, y: Int) -> Int {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn int_euclidean_modulo(x: Int, y: Int) -> Int {
|
pub fn euclidean_modulo(x: Int, y: Int) -> Int {
|
||||||
case x % y, x, y {
|
case x % y, x, y {
|
||||||
_, 0, _ -> 0
|
_, 0, _ -> 0
|
||||||
_, _, 0 -> 0
|
_, _, 0 -> 0
|
||||||
|
@ -302,15 +302,15 @@ pub fn proper_divisors(n: Int) -> List(Int) {
|
||||||
///
|
///
|
||||||
/// pub fn example () {
|
/// pub fn example () {
|
||||||
/// []
|
/// []
|
||||||
/// |> maths.float_weighted_sum()
|
/// |> maths.weighted_sum()
|
||||||
/// |> should.equal(Ok(0.0))
|
/// |> should.equal(Ok(0.0))
|
||||||
///
|
///
|
||||||
/// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
/// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
||||||
/// |> maths.float_weighted_sum()
|
/// |> maths.weighted_sum()
|
||||||
/// |> should.equal(Ok(6.0))
|
/// |> should.equal(Ok(6.0))
|
||||||
///
|
///
|
||||||
/// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
/// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
||||||
/// |> maths.float_weighted_sum()
|
/// |> maths.weighted_sum()
|
||||||
/// |> should.equal(Ok(14.5))
|
/// |> should.equal(Ok(14.5))
|
||||||
/// }
|
/// }
|
||||||
/// </details>
|
/// </details>
|
||||||
|
@ -321,7 +321,7 @@ pub fn proper_divisors(n: Int) -> List(Int) {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
pub fn weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
||||||
case arr {
|
case arr {
|
||||||
[] -> Ok(0.0)
|
[] -> Ok(0.0)
|
||||||
_ -> {
|
_ -> {
|
||||||
|
@ -364,17 +364,17 @@ pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
||||||
///
|
///
|
||||||
/// pub fn example () {
|
/// pub fn example () {
|
||||||
/// []
|
/// []
|
||||||
/// |> maths.float_weighted_product()
|
/// |> maths.weighted_product()
|
||||||
/// |> should.equal(Ok(1.0))
|
/// |> should.equal(Ok(1.0))
|
||||||
///
|
///
|
||||||
/// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
/// [#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
||||||
/// |> maths.float_weighted_product()
|
/// |> maths.weighted_product()
|
||||||
/// |> should.equal(Ok(6.0))
|
/// |> should.equal(Ok(6.0))
|
||||||
///
|
///
|
||||||
/// let assert Ok(tolerance) = float.power(10.0, -6.0)
|
/// let assert Ok(tolerance) = float.power(10.0, -6.0)
|
||||||
/// let assert Ok(result) =
|
/// let assert Ok(result) =
|
||||||
/// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
/// [#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
||||||
/// |> maths.float_weighted_product()
|
/// |> maths.weighted_product()
|
||||||
/// result
|
/// result
|
||||||
/// |> maths.is_close(30.0, 0.0, tolerance)
|
/// |> maths.is_close(30.0, 0.0, tolerance)
|
||||||
/// |> should.be_true()
|
/// |> should.be_true()
|
||||||
|
@ -387,7 +387,7 @@ pub fn float_weighted_sum(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
pub fn weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil) {
|
||||||
case arr {
|
case arr {
|
||||||
[] -> Ok(1.0)
|
[] -> Ok(1.0)
|
||||||
_ -> {
|
_ -> {
|
||||||
|
@ -435,11 +435,11 @@ pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil)
|
||||||
///
|
///
|
||||||
/// pub fn example () {
|
/// pub fn example () {
|
||||||
/// []
|
/// []
|
||||||
/// |> maths.float_cumulative_sum()
|
/// |> maths.cumulative_sum()
|
||||||
/// |> should.equal([])
|
/// |> should.equal([])
|
||||||
///
|
///
|
||||||
/// [1.0, 2.0, 3.0]
|
/// [1.0, 2.0, 3.0]
|
||||||
/// |> maths.float_cumulative_sum()
|
/// |> maths.cumulative_sum()
|
||||||
/// |> should.equal([1.0, 3.0, 6.0])
|
/// |> should.equal([1.0, 3.0, 6.0])
|
||||||
/// }
|
/// }
|
||||||
/// </details>
|
/// </details>
|
||||||
|
@ -450,7 +450,7 @@ pub fn float_weighted_product(arr: List(#(Float, Float))) -> Result(Float, Nil)
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_cumulative_sum(arr: List(Float)) -> List(Float) {
|
pub fn cumulative_sum(arr: List(Float)) -> List(Float) {
|
||||||
case arr {
|
case arr {
|
||||||
[] -> []
|
[] -> []
|
||||||
_ -> list.scan(arr, 0.0, fn(acc, a) { a +. acc })
|
_ -> list.scan(arr, 0.0, fn(acc, a) { a +. acc })
|
||||||
|
@ -530,11 +530,11 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) {
|
||||||
///
|
///
|
||||||
/// pub fn example () {
|
/// pub fn example () {
|
||||||
/// []
|
/// []
|
||||||
/// |> maths.float_cumulative_product()
|
/// |> maths.cumulative_product()
|
||||||
/// |> should.equal([])
|
/// |> should.equal([])
|
||||||
///
|
///
|
||||||
/// [1.0, 2.0, 3.0]
|
/// [1.0, 2.0, 3.0]
|
||||||
/// |> maths.float_cumulative_product()
|
/// |> maths.cumulative_product()
|
||||||
/// |> should.equal([1.0, 2.0, 6.0])
|
/// |> should.equal([1.0, 2.0, 6.0])
|
||||||
/// }
|
/// }
|
||||||
/// </details>
|
/// </details>
|
||||||
|
@ -545,7 +545,7 @@ pub fn int_cumulative_sum(arr: List(Int)) -> List(Int) {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_cumulative_product(arr: List(Float)) -> List(Float) {
|
pub fn cumulative_product(arr: List(Float)) -> List(Float) {
|
||||||
case arr {
|
case arr {
|
||||||
[] -> []
|
[] -> []
|
||||||
_ -> list.scan(arr, 1.0, fn(acc, a) { a *. acc })
|
_ -> list.scan(arr, 1.0, fn(acc, a) { a *. acc })
|
||||||
|
@ -1792,15 +1792,15 @@ pub fn round_to_nearest(x: Float, p: Int) -> Float {
|
||||||
let xabs_truncated = truncate_float(xabs)
|
let xabs_truncated = truncate_float(xabs)
|
||||||
let remainder = xabs -. xabs_truncated
|
let remainder = xabs -. xabs_truncated
|
||||||
case remainder {
|
case remainder {
|
||||||
_ if remainder >. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p
|
_ if remainder >. 0.5 -> sign(x) *. truncate_float(xabs +. 1.0) /. p
|
||||||
_ if remainder == 0.5 -> {
|
_ if remainder == 0.5 -> {
|
||||||
let assert Ok(is_even) = int.modulo(float.truncate(xabs), 2)
|
let assert Ok(is_even) = int.modulo(float.truncate(xabs), 2)
|
||||||
case is_even == 0 {
|
case is_even == 0 {
|
||||||
True -> float_sign(x) *. xabs_truncated /. p
|
True -> sign(x) *. xabs_truncated /. p
|
||||||
False -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p
|
False -> sign(x) *. truncate_float(xabs +. 1.0) /. p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ -> float_sign(x) *. xabs_truncated /. p
|
_ -> sign(x) *. xabs_truncated /. p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1855,8 +1855,8 @@ pub fn round_ties_away(x: Float, p: Int) -> Float {
|
||||||
let xabs = float.absolute_value(x) *. p
|
let xabs = float.absolute_value(x) *. p
|
||||||
let remainder = xabs -. truncate_float(xabs)
|
let remainder = xabs -. truncate_float(xabs)
|
||||||
case remainder {
|
case remainder {
|
||||||
_ if remainder >=. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p
|
_ if remainder >=. 0.5 -> sign(x) *. truncate_float(xabs +. 1.0) /. p
|
||||||
_ -> float_sign(x) *. truncate_float(xabs) /. p
|
_ -> sign(x) *. truncate_float(xabs) /. p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1913,8 +1913,8 @@ pub fn round_ties_up(x: Float, p: Int) -> Float {
|
||||||
let remainder = xabs -. xabs_truncated
|
let remainder = xabs -. xabs_truncated
|
||||||
case remainder {
|
case remainder {
|
||||||
_ if remainder >=. 0.5 && x >=. 0.0 ->
|
_ if remainder >=. 0.5 && x >=. 0.0 ->
|
||||||
float_sign(x) *. truncate_float(xabs +. 1.0) /. p
|
sign(x) *. truncate_float(xabs +. 1.0) /. p
|
||||||
_ -> float_sign(x) *. xabs_truncated /. p
|
_ -> sign(x) *. xabs_truncated /. p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2109,10 +2109,10 @@ fn do_ceiling(a: Float) -> Float
|
||||||
/// import gleam_community/maths
|
/// import gleam_community/maths
|
||||||
///
|
///
|
||||||
/// pub fn example() {
|
/// pub fn example() {
|
||||||
/// maths.float_absolute_difference(-10.0, 10.0)
|
/// maths.absolute_difference(-10.0, 10.0)
|
||||||
/// |> should.equal(20.0)
|
/// |> should.equal(20.0)
|
||||||
///
|
///
|
||||||
/// maths.float_absolute_difference(0.0, -2.0)
|
/// maths.absolute_difference(0.0, -2.0)
|
||||||
/// |> should.equal(2.0)
|
/// |> should.equal(2.0)
|
||||||
/// }
|
/// }
|
||||||
/// </details>
|
/// </details>
|
||||||
|
@ -2123,9 +2123,8 @@ fn do_ceiling(a: Float) -> Float
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_absolute_difference(a: Float, b: Float) -> Float {
|
pub fn absolute_difference(a: Float, b: Float) -> Float {
|
||||||
a -. b
|
float.absolute_value(a -. b)
|
||||||
|> float.absolute_value()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <div style="text-align: right;">
|
/// <div style="text-align: right;">
|
||||||
|
@ -2165,8 +2164,7 @@ pub fn float_absolute_difference(a: Float, b: Float) -> Float {
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn int_absolute_difference(a: Int, b: Int) -> Int {
|
pub fn int_absolute_difference(a: Int, b: Int) -> Int {
|
||||||
a - b
|
int.absolute_value(a - b)
|
||||||
|> int.absolute_value()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <div style="text-align: right;">
|
/// <div style="text-align: right;">
|
||||||
|
@ -2185,12 +2183,12 @@ pub fn int_absolute_difference(a: Int, b: Int) -> Int {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_sign(x: Float) -> Float {
|
pub fn sign(x: Float) -> Float {
|
||||||
do_float_sign(x)
|
do_sign(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@target(erlang)
|
@external(javascript, "../maths.mjs", "sign")
|
||||||
fn do_float_sign(x: Float) -> Float {
|
fn do_sign(x: Float) -> Float {
|
||||||
case x {
|
case x {
|
||||||
_ if x <. 0.0 -> -1.0
|
_ if x <. 0.0 -> -1.0
|
||||||
_ if x >. 0.0 -> 1.0
|
_ if x >. 0.0 -> 1.0
|
||||||
|
@ -2198,10 +2196,6 @@ fn do_float_sign(x: Float) -> Float {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@target(javascript)
|
|
||||||
@external(javascript, "../maths.mjs", "sign")
|
|
||||||
fn do_float_sign(a: Float) -> Float
|
|
||||||
|
|
||||||
/// <div style="text-align: right;">
|
/// <div style="text-align: right;">
|
||||||
/// <a href="https://github.com/gleam-community/maths/issues">
|
/// <a href="https://github.com/gleam-community/maths/issues">
|
||||||
/// <small>Spot a typo? Open an issue!</small>
|
/// <small>Spot a typo? Open an issue!</small>
|
||||||
|
@ -2222,7 +2216,7 @@ pub fn int_sign(x: Int) -> Int {
|
||||||
do_int_sign(x)
|
do_int_sign(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@target(erlang)
|
@external(javascript, "../maths.mjs", "sign")
|
||||||
fn do_int_sign(x: Int) -> Int {
|
fn do_int_sign(x: Int) -> Int {
|
||||||
case x {
|
case x {
|
||||||
_ if x < 0 -> -1
|
_ if x < 0 -> -1
|
||||||
|
@ -2231,10 +2225,6 @@ fn do_int_sign(x: Int) -> Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@target(javascript)
|
|
||||||
@external(javascript, "../maths.mjs", "sign")
|
|
||||||
fn do_int_sign(a: Int) -> Int
|
|
||||||
|
|
||||||
/// <div style="text-align: right;">
|
/// <div style="text-align: right;">
|
||||||
/// <a href="https://github.com/gleam-community/maths/issues">
|
/// <a href="https://github.com/gleam-community/maths/issues">
|
||||||
/// <small>Spot a typo? Open an issue!</small>
|
/// <small>Spot a typo? Open an issue!</small>
|
||||||
|
@ -2250,14 +2240,14 @@ fn do_int_sign(a: Int) -> Int
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_copy_sign(x: Float, y: Float) -> Float {
|
pub fn copy_sign(x: Float, y: Float) -> Float {
|
||||||
case float_sign(x) == float_sign(y) {
|
case sign(x) == sign(y) {
|
||||||
// x and y have the same sign, just return x
|
// x and y have the same sign, just return x
|
||||||
True -> x
|
True -> x
|
||||||
// x and y have different signs:
|
// x and y have different signs:
|
||||||
// - x is positive and y is negative, then flip sign of x
|
// - x is positive and y is negative, then flip sign of x
|
||||||
// - x is negative and y is positive, then flip sign of x
|
// - x is negative and y is positive, then flip sign of x
|
||||||
False -> float_flip_sign(x)
|
False -> flip_sign(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2301,7 +2291,7 @@ pub fn int_copy_sign(x: Int, y: Int) -> Int {
|
||||||
/// </a>
|
/// </a>
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn float_flip_sign(x: Float) -> Float {
|
pub fn flip_sign(x: Float) -> Float {
|
||||||
-1.0 *. x
|
-1.0 *. x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4734,12 +4724,9 @@ pub fn braycurtis_distance_with_weights(
|
||||||
/// </div>
|
/// </div>
|
||||||
///
|
///
|
||||||
pub fn is_close(x: Float, y: Float, rtol: Float, atol: Float) -> Bool {
|
pub fn is_close(x: Float, y: Float, rtol: Float, atol: Float) -> Bool {
|
||||||
let x = float_absolute_difference(x, y)
|
let x = absolute_difference(x, y)
|
||||||
let y = atol +. rtol *. float.absolute_value(y)
|
let y = atol +. rtol *. float.absolute_value(y)
|
||||||
case x <=. y {
|
x <=. y
|
||||||
True -> True
|
|
||||||
False -> False
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <div style="text-align: right;">
|
/// <div style="text-align: right;">
|
||||||
|
@ -5196,7 +5183,7 @@ pub fn erf(x: Float) -> Float {
|
||||||
]
|
]
|
||||||
let p = 0.3275911
|
let p = 0.3275911
|
||||||
|
|
||||||
let sign = float_sign(x)
|
let sign = sign(x)
|
||||||
let x = float.absolute_value(x)
|
let x = float.absolute_value(x)
|
||||||
|
|
||||||
// Formula 7.1.26 given in Abramowitz and Stegun.
|
// Formula 7.1.26 given in Abramowitz and Stegun.
|
||||||
|
|
|
@ -22,35 +22,35 @@ pub fn int_gcd_test() {
|
||||||
|> should.equal(6)
|
|> should.equal(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_euclidean_modulo_test() {
|
pub fn euclidean_modulo_test() {
|
||||||
// Base Case: Positive x, Positive y
|
// Base Case: Positive x, Positive y
|
||||||
// Note that the truncated, floored, and euclidean
|
// Note that the truncated, floored, and euclidean
|
||||||
// definitions should agree for this base case
|
// definitions should agree for this base case
|
||||||
maths.int_euclidean_modulo(15, 4)
|
maths.euclidean_modulo(15, 4)
|
||||||
|> should.equal(3)
|
|> should.equal(3)
|
||||||
|
|
||||||
// Case: Positive x, Negative y
|
// Case: Positive x, Negative y
|
||||||
maths.int_euclidean_modulo(15, -4)
|
maths.euclidean_modulo(15, -4)
|
||||||
|> should.equal(3)
|
|> should.equal(3)
|
||||||
|
|
||||||
// Case: Negative x, Positive y
|
// Case: Negative x, Positive y
|
||||||
maths.int_euclidean_modulo(-15, 4)
|
maths.euclidean_modulo(-15, 4)
|
||||||
|> should.equal(1)
|
|> should.equal(1)
|
||||||
|
|
||||||
// Case: Negative x, Negative y
|
// Case: Negative x, Negative y
|
||||||
maths.int_euclidean_modulo(-15, -4)
|
maths.euclidean_modulo(-15, -4)
|
||||||
|> should.equal(1)
|
|> should.equal(1)
|
||||||
|
|
||||||
// Case: Positive x, Zero y
|
// Case: Positive x, Zero y
|
||||||
maths.int_euclidean_modulo(5, 0)
|
maths.euclidean_modulo(5, 0)
|
||||||
|> should.equal(0)
|
|> should.equal(0)
|
||||||
|
|
||||||
// Case: Zero x, Negative y
|
// Case: Zero x, Negative y
|
||||||
maths.int_euclidean_modulo(0, 5)
|
maths.euclidean_modulo(0, 5)
|
||||||
|> should.equal(0)
|
|> should.equal(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_lcm_test() {
|
pub fn lcm_test() {
|
||||||
maths.lcm(1, 1)
|
maths.lcm(1, 1)
|
||||||
|> should.equal(1)
|
|> should.equal(1)
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ pub fn int_lcm_test() {
|
||||||
|> should.equal(210)
|
|> should.equal(210)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_proper_divisors_test() {
|
pub fn proper_divisors_test() {
|
||||||
maths.proper_divisors(2)
|
maths.proper_divisors(2)
|
||||||
|> should.equal([1])
|
|> should.equal([1])
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ pub fn int_proper_divisors_test() {
|
||||||
|> should.equal([1, 2, 3, 6, 9])
|
|> should.equal([1, 2, 3, 6, 9])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_divisors_test() {
|
pub fn divisors_test() {
|
||||||
maths.divisors(2)
|
maths.divisors(2)
|
||||||
|> should.equal([1, 2])
|
|> should.equal([1, 2])
|
||||||
|
|
||||||
|
@ -98,19 +98,19 @@ pub fn int_divisors_test() {
|
||||||
|> should.equal([1, 2, 3, 6, 9, 18])
|
|> should.equal([1, 2, 3, 6, 9, 18])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_cumulative_sum_test() {
|
pub fn list_cumulative_sum_test() {
|
||||||
// An empty lists returns an empty list
|
// An empty lists returns an empty list
|
||||||
[]
|
[]
|
||||||
|> maths.float_cumulative_sum()
|
|> maths.cumulative_sum()
|
||||||
|> should.equal([])
|
|> should.equal([])
|
||||||
|
|
||||||
// Valid input returns a result
|
// Valid input returns a result
|
||||||
[1.0, 2.0, 3.0]
|
[1.0, 2.0, 3.0]
|
||||||
|> maths.float_cumulative_sum()
|
|> maths.cumulative_sum()
|
||||||
|> should.equal([1.0, 3.0, 6.0])
|
|> should.equal([1.0, 3.0, 6.0])
|
||||||
|
|
||||||
[-2.0, 4.0, 6.0]
|
[-2.0, 4.0, 6.0]
|
||||||
|> maths.float_cumulative_sum()
|
|> maths.cumulative_sum()
|
||||||
|> should.equal([-2.0, 2.0, 8.0])
|
|> should.equal([-2.0, 2.0, 8.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,19 +130,19 @@ pub fn int_list_cumulative_sum_test() {
|
||||||
|> should.equal([-2, 2, 8])
|
|> should.equal([-2, 2, 8])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_cumulative_product_test() {
|
pub fn list_cumulative_product_test() {
|
||||||
// An empty lists returns an empty list
|
// An empty lists returns an empty list
|
||||||
[]
|
[]
|
||||||
|> maths.float_cumulative_product()
|
|> maths.cumulative_product()
|
||||||
|> should.equal([])
|
|> should.equal([])
|
||||||
|
|
||||||
// Valid input returns a result
|
// Valid input returns a result
|
||||||
[1.0, 2.0, 3.0]
|
[1.0, 2.0, 3.0]
|
||||||
|> maths.float_cumulative_product()
|
|> maths.cumulative_product()
|
||||||
|> should.equal([1.0, 2.0, 6.0])
|
|> should.equal([1.0, 2.0, 6.0])
|
||||||
|
|
||||||
[-2.0, 4.0, 6.0]
|
[-2.0, 4.0, 6.0]
|
||||||
|> maths.float_cumulative_product()
|
|> maths.cumulative_product()
|
||||||
|> should.equal([-2.0, -8.0, -48.0])
|
|> should.equal([-2.0, -8.0, -48.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,42 +162,42 @@ pub fn int_list_cumulative_product_test() {
|
||||||
|> should.equal([-2, -8, -48])
|
|> should.equal([-2, -8, -48])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_weighted_product_test() {
|
pub fn weighted_product_test() {
|
||||||
[]
|
[]
|
||||||
|> maths.float_weighted_product()
|
|> maths.weighted_product()
|
||||||
|> should.equal(Ok(1.0))
|
|> should.equal(Ok(1.0))
|
||||||
|
|
||||||
[#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)]
|
[#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)]
|
||||||
|> maths.float_weighted_product()
|
|> maths.weighted_product()
|
||||||
|> should.equal(Ok(1.0))
|
|> should.equal(Ok(1.0))
|
||||||
|
|
||||||
[#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
[#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
||||||
|> maths.float_weighted_product()
|
|> maths.weighted_product()
|
||||||
|> should.equal(Ok(6.0))
|
|> should.equal(Ok(6.0))
|
||||||
|
|
||||||
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
||||||
let assert Ok(result) =
|
let assert Ok(result) =
|
||||||
[#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
[#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
||||||
|> maths.float_weighted_product()
|
|> maths.weighted_product()
|
||||||
result
|
result
|
||||||
|> maths.is_close(30.0, 0.0, tolerance)
|
|> maths.is_close(30.0, 0.0, tolerance)
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_weighted_sum_test() {
|
pub fn weighted_sum_test() {
|
||||||
[]
|
[]
|
||||||
|> maths.float_weighted_sum()
|
|> maths.weighted_sum()
|
||||||
|> should.equal(Ok(0.0))
|
|> should.equal(Ok(0.0))
|
||||||
|
|
||||||
[#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)]
|
[#(1.0, 0.0), #(2.0, 0.0), #(3.0, 0.0)]
|
||||||
|> maths.float_weighted_sum()
|
|> maths.weighted_sum()
|
||||||
|> should.equal(Ok(0.0))
|
|> should.equal(Ok(0.0))
|
||||||
|
|
||||||
[#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
[#(1.0, 1.0), #(2.0, 1.0), #(3.0, 1.0)]
|
||||||
|> maths.float_weighted_sum()
|
|> maths.weighted_sum()
|
||||||
|> should.equal(Ok(6.0))
|
|> should.equal(Ok(6.0))
|
||||||
|
|
||||||
[#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
[#(9.0, 0.5), #(10.0, 0.5), #(10.0, 0.5)]
|
||||||
|> maths.float_weighted_sum()
|
|> maths.weighted_sum()
|
||||||
|> should.equal(Ok(14.5))
|
|> should.equal(Ok(14.5))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import gleam/float
|
||||||
import gleam_community/maths
|
import gleam_community/maths
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
|
|
||||||
pub fn float_to_degree_test() {
|
pub fn to_degree_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
maths.radians_to_degrees(0.0)
|
maths.radians_to_degrees(0.0)
|
||||||
|> maths.is_close(0.0, 0.0, tol)
|
|> maths.is_close(0.0, 0.0, tol)
|
||||||
|
@ -13,7 +13,7 @@ pub fn float_to_degree_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_to_radian_test() {
|
pub fn to_radian_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
maths.degrees_to_radians(0.0)
|
maths.degrees_to_radians(0.0)
|
||||||
|> maths.is_close(0.0, 0.0, tol)
|
|> maths.is_close(0.0, 0.0, tol)
|
||||||
|
@ -24,7 +24,7 @@ pub fn float_to_radian_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_cartesian_to_polar_test() {
|
pub fn cartesian_to_polar_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Test: Cartesian (1, 0) -> Polar (1, 0)
|
// Test: Cartesian (1, 0) -> Polar (1, 0)
|
||||||
|
@ -68,7 +68,7 @@ pub fn float_cartesian_to_polar_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_polar_to_cartesian_test() {
|
pub fn polar_to_cartesian_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Test: Polar (1, 0) -> Cartesian (1, 0)
|
// Test: Polar (1, 0) -> Cartesian (1, 0)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import gleam/float
|
||||||
import gleam_community/maths
|
import gleam_community/maths
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
|
|
||||||
pub fn float_acos_test() {
|
pub fn acos_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -25,7 +25,7 @@ pub fn float_acos_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_acosh_test() {
|
pub fn acosh_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -40,7 +40,7 @@ pub fn float_acosh_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_asin_test() {
|
pub fn asin_test() {
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
maths.asin(0.0)
|
maths.asin(0.0)
|
||||||
|
@ -61,7 +61,7 @@ pub fn float_asin_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_asinh_test() {
|
pub fn asinh_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -74,7 +74,7 @@ pub fn float_asinh_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_atan_test() {
|
pub fn atan_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -135,7 +135,7 @@ pub fn math_atan2_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_atanh_test() {
|
pub fn atanh_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -164,7 +164,7 @@ pub fn float_atanh_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_cos_test() {
|
pub fn cos_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -181,7 +181,7 @@ pub fn float_cos_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_cosh_test() {
|
pub fn cosh_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -198,7 +198,7 @@ pub fn float_cosh_test() {
|
||||||
// runtime.
|
// runtime.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_sin_test() {
|
pub fn sin_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -215,7 +215,7 @@ pub fn float_sin_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_sinh_test() {
|
pub fn sinh_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -266,7 +266,7 @@ pub fn math_tanh_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_exponential_test() {
|
pub fn exponential_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -283,7 +283,7 @@ pub fn float_exponential_test() {
|
||||||
// runtime.
|
// runtime.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_natural_logarithm_test() {
|
pub fn natural_logarithm_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -301,7 +301,7 @@ pub fn float_natural_logarithm_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_logarithm_test() {
|
pub fn logarithm_test() {
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
maths.logarithm(10.0, 10.0)
|
maths.logarithm(10.0, 10.0)
|
||||||
|
@ -334,7 +334,7 @@ pub fn float_logarithm_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_logarithm_2_test() {
|
pub fn logarithm_2_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -355,7 +355,7 @@ pub fn float_logarithm_2_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_logarithm_10_test() {
|
pub fn logarithm_10_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -380,7 +380,7 @@ pub fn float_logarithm_10_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_nth_root_test() {
|
pub fn nth_root_test() {
|
||||||
maths.nth_root(9.0, 2)
|
maths.nth_root(9.0, 2)
|
||||||
|> should.equal(Ok(3.0))
|
|> should.equal(Ok(3.0))
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ pub fn float_nth_root_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_constants_test() {
|
pub fn constants_test() {
|
||||||
let assert Ok(tolerance) = float.power(10.0, -12.0)
|
let assert Ok(tolerance) = float.power(10.0, -12.0)
|
||||||
|
|
||||||
// Test that the constant is approximately equal to 2.7128...
|
// Test that the constant is approximately equal to 2.7128...
|
||||||
|
|
|
@ -3,7 +3,7 @@ import gleam/set
|
||||||
import gleam_community/maths
|
import gleam_community/maths
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
|
|
||||||
pub fn float_list_norm_test() {
|
pub fn list_norm_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// An empty lists returns 0.0
|
// An empty lists returns 0.0
|
||||||
|
@ -63,7 +63,7 @@ pub fn float_list_norm_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_norm_with_weights_test() {
|
pub fn list_norm_with_weights_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// An empty lists returns 0.0
|
// An empty lists returns 0.0
|
||||||
|
@ -95,7 +95,7 @@ pub fn float_list_norm_with_weights_test() {
|
||||||
|> should.be_true()
|
|> should.be_true()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_manhattan_test() {
|
pub fn list_manhattan_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Try with valid input (same as Minkowski distance with p = 1)
|
// Try with valid input (same as Minkowski distance with p = 1)
|
||||||
|
@ -135,7 +135,7 @@ pub fn float_list_manhattan_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_minkowski_test() {
|
pub fn list_minkowski_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Test order < 1
|
// Test order < 1
|
||||||
|
@ -209,7 +209,7 @@ pub fn float_list_minkowski_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_euclidean_test() {
|
pub fn list_euclidean_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Empty lists returns an error
|
// Empty lists returns an error
|
||||||
|
|
|
@ -3,7 +3,7 @@ import gleam/int
|
||||||
import gleam_community/maths
|
import gleam_community/maths
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
|
|
||||||
pub fn float_ceiling_test() {
|
pub fn ceiling_test() {
|
||||||
// Round 3. digit AFTER decimal point
|
// Round 3. digit AFTER decimal point
|
||||||
maths.round_up(12.0654, 3)
|
maths.round_up(12.0654, 3)
|
||||||
|> should.equal(12.066)
|
|> should.equal(12.066)
|
||||||
|
@ -33,7 +33,7 @@ pub fn float_ceiling_test() {
|
||||||
|> should.equal(1000.0)
|
|> should.equal(1000.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_floor_test() {
|
pub fn floor_test() {
|
||||||
// Round 3. digit AFTER decimal point
|
// Round 3. digit AFTER decimal point
|
||||||
maths.round_down(12.0654, 3)
|
maths.round_down(12.0654, 3)
|
||||||
|> should.equal(12.065)
|
|> should.equal(12.065)
|
||||||
|
@ -63,7 +63,7 @@ pub fn float_floor_test() {
|
||||||
|> should.equal(0.0)
|
|> should.equal(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_truncate_test() {
|
pub fn truncate_test() {
|
||||||
// Round 3. digit AFTER decimal point
|
// Round 3. digit AFTER decimal point
|
||||||
maths.round_to_zero(12.0654, 3)
|
maths.round_to_zero(12.0654, 3)
|
||||||
|> should.equal(12.065)
|
|> should.equal(12.065)
|
||||||
|
@ -373,41 +373,41 @@ pub fn math_round_ties_up_test() {
|
||||||
|> should.equal(0.0)
|
|> should.equal(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_absolute_difference_test() {
|
pub fn absolute_difference_test() {
|
||||||
maths.float_absolute_difference(20.0, 15.0)
|
maths.absolute_difference(20.0, 15.0)
|
||||||
|> should.equal(5.0)
|
|> should.equal(5.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(-20.0, -15.0)
|
maths.absolute_difference(-20.0, -15.0)
|
||||||
|> should.equal(5.0)
|
|> should.equal(5.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(20.0, -15.0)
|
maths.absolute_difference(20.0, -15.0)
|
||||||
|> should.equal(35.0)
|
|> should.equal(35.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(-20.0, 15.0)
|
maths.absolute_difference(-20.0, 15.0)
|
||||||
|> should.equal(35.0)
|
|> should.equal(35.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(0.0, 0.0)
|
maths.absolute_difference(0.0, 0.0)
|
||||||
|> should.equal(0.0)
|
|> should.equal(0.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(1.0, 2.0)
|
maths.absolute_difference(1.0, 2.0)
|
||||||
|> should.equal(1.0)
|
|> should.equal(1.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(2.0, 1.0)
|
maths.absolute_difference(2.0, 1.0)
|
||||||
|> should.equal(1.0)
|
|> should.equal(1.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(-1.0, 0.0)
|
maths.absolute_difference(-1.0, 0.0)
|
||||||
|> should.equal(1.0)
|
|> should.equal(1.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(0.0, -1.0)
|
maths.absolute_difference(0.0, -1.0)
|
||||||
|> should.equal(1.0)
|
|> should.equal(1.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(10.0, 20.0)
|
maths.absolute_difference(10.0, 20.0)
|
||||||
|> should.equal(10.0)
|
|> should.equal(10.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(-10.0, -20.0)
|
maths.absolute_difference(-10.0, -20.0)
|
||||||
|> should.equal(10.0)
|
|> should.equal(10.0)
|
||||||
|
|
||||||
maths.float_absolute_difference(-10.5, 10.5)
|
maths.absolute_difference(-10.5, 10.5)
|
||||||
|> should.equal(21.0)
|
|> should.equal(21.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,39 +425,39 @@ pub fn int_absolute_difference_test() {
|
||||||
|> should.equal(35)
|
|> should.equal(35)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_sign_test() {
|
pub fn sign_test() {
|
||||||
maths.float_sign(100.0)
|
maths.sign(100.0)
|
||||||
|> should.equal(1.0)
|
|> should.equal(1.0)
|
||||||
|
|
||||||
maths.float_sign(0.0)
|
maths.sign(0.0)
|
||||||
|> should.equal(0.0)
|
|> should.equal(0.0)
|
||||||
|
|
||||||
maths.float_sign(-100.0)
|
maths.sign(-100.0)
|
||||||
|> should.equal(-1.0)
|
|> should.equal(-1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_flip_sign_test() {
|
pub fn flip_sign_test() {
|
||||||
maths.float_flip_sign(100.0)
|
maths.flip_sign(100.0)
|
||||||
|> should.equal(-100.0)
|
|> should.equal(-100.0)
|
||||||
|
|
||||||
maths.float_flip_sign(0.0)
|
maths.flip_sign(0.0)
|
||||||
|> should.equal(-0.0)
|
|> should.equal(-0.0)
|
||||||
|
|
||||||
maths.float_flip_sign(-100.0)
|
maths.flip_sign(-100.0)
|
||||||
|> should.equal(100.0)
|
|> should.equal(100.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_copy_sign_test() {
|
pub fn copy_sign_test() {
|
||||||
maths.float_copy_sign(100.0, 10.0)
|
maths.copy_sign(100.0, 10.0)
|
||||||
|> should.equal(100.0)
|
|> should.equal(100.0)
|
||||||
|
|
||||||
maths.float_copy_sign(-100.0, 10.0)
|
maths.copy_sign(-100.0, 10.0)
|
||||||
|> should.equal(100.0)
|
|> should.equal(100.0)
|
||||||
|
|
||||||
maths.float_copy_sign(100.0, -10.0)
|
maths.copy_sign(100.0, -10.0)
|
||||||
|> should.equal(-100.0)
|
|> should.equal(-100.0)
|
||||||
|
|
||||||
maths.float_copy_sign(-100.0, -10.0)
|
maths.copy_sign(-100.0, -10.0)
|
||||||
|> should.equal(-100.0)
|
|> should.equal(-100.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ pub fn int_copy_sign_test() {
|
||||||
|> should.equal(-100)
|
|> should.equal(-100)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_minmax_test() {
|
pub fn minmax_test() {
|
||||||
maths.minmax(0.75, 0.5, float.compare)
|
maths.minmax(0.75, 0.5, float.compare)
|
||||||
|> should.equal(#(0.5, 0.75))
|
|> should.equal(#(0.5, 0.75))
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ pub fn int_minmax_test() {
|
||||||
|> should.equal(#(-75, 50))
|
|> should.equal(#(-75, 50))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_minimum_test() {
|
pub fn list_minimum_test() {
|
||||||
// An empty lists returns an error
|
// An empty lists returns an error
|
||||||
[]
|
[]
|
||||||
|> maths.list_minimum(float.compare)
|
|> maths.list_minimum(float.compare)
|
||||||
|
@ -549,7 +549,7 @@ pub fn int_list_minimum_test() {
|
||||||
|> should.equal(Ok(1))
|
|> should.equal(Ok(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_maximum_test() {
|
pub fn list_maximum_test() {
|
||||||
// An empty lists returns an error
|
// An empty lists returns an error
|
||||||
[]
|
[]
|
||||||
|> maths.list_maximum(float.compare)
|
|> maths.list_maximum(float.compare)
|
||||||
|
@ -573,7 +573,7 @@ pub fn int_list_maximum_test() {
|
||||||
|> should.equal(Ok(4))
|
|> should.equal(Ok(4))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_arg_maximum_test() {
|
pub fn list_arg_maximum_test() {
|
||||||
// An empty lists returns an error
|
// An empty lists returns an error
|
||||||
[]
|
[]
|
||||||
|> maths.arg_maximum(float.compare)
|
|> maths.arg_maximum(float.compare)
|
||||||
|
@ -597,7 +597,7 @@ pub fn int_list_arg_maximum_test() {
|
||||||
|> should.equal(Ok([0, 1]))
|
|> should.equal(Ok([0, 1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_arg_minimum_test() {
|
pub fn list_arg_minimum_test() {
|
||||||
// An empty lists returns an error
|
// An empty lists returns an error
|
||||||
[]
|
[]
|
||||||
|> maths.arg_minimum(float.compare)
|
|> maths.arg_minimum(float.compare)
|
||||||
|
@ -621,7 +621,7 @@ pub fn int_list_arg_minimum_test() {
|
||||||
|> should.equal(Ok([4]))
|
|> should.equal(Ok([4]))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_extrema_test() {
|
pub fn list_extrema_test() {
|
||||||
// An empty lists returns an error
|
// An empty lists returns an error
|
||||||
[]
|
[]
|
||||||
|> maths.extrema(float.compare)
|
|> maths.extrema(float.compare)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import gleam/yielder
|
||||||
import gleam_community/maths
|
import gleam_community/maths
|
||||||
import gleeunit/should
|
import gleeunit/should
|
||||||
|
|
||||||
pub fn float_list_linear_space_test() {
|
pub fn list_linear_space_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
|
@ -118,7 +118,7 @@ pub fn float_list_linear_space_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_logarithmic_space_test() {
|
pub fn list_logarithmic_space_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -203,7 +203,7 @@ pub fn float_list_logarithmic_space_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_geometric_space_test() {
|
pub fn list_geometric_space_test() {
|
||||||
let assert Ok(tol) = float.power(10.0, -6.0)
|
let assert Ok(tol) = float.power(10.0, -6.0)
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
// points, with known function values
|
// points, with known function values
|
||||||
|
@ -271,7 +271,7 @@ pub fn float_list_geometric_space_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_arange_test() {
|
pub fn list_arange_test() {
|
||||||
// Positive start, stop, step
|
// Positive start, stop, step
|
||||||
maths.arange(1.0, 5.0, 1.0)
|
maths.arange(1.0, 5.0, 1.0)
|
||||||
|> yielder.to_list()
|
|> yielder.to_list()
|
||||||
|
@ -311,7 +311,7 @@ pub fn float_list_arange_test() {
|
||||||
|> should.equal([-5.0, -4.0, -3.0, -2.0])
|
|> should.equal([-5.0, -4.0, -3.0, -2.0])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_exponential_space_test() {
|
pub fn list_exponential_space_test() {
|
||||||
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
|
@ -349,7 +349,7 @@ pub fn float_list_exponential_space_test() {
|
||||||
|> should.be_error()
|
|> should.be_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn float_list_symmetric_space_test() {
|
pub fn list_symmetric_space_test() {
|
||||||
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
let assert Ok(tolerance) = float.power(10.0, -6.0)
|
||||||
|
|
||||||
// Check that the function agrees, at some arbitrary input
|
// Check that the function agrees, at some arbitrary input
|
||||||
|
|
Loading…
Reference in a new issue