Work on float/float_list module funcs

This commit is contained in:
NicklasXYZ 2023-01-08 21:28:57 +01:00
parent c373c11aba
commit 20d2a01f31
7 changed files with 861 additions and 669 deletions

View file

@ -22,7 +22,7 @@ pub fn main() {
// Find the greatest common divisor
intx.gcd(54, 24)
// Returns Int: 6
// Returns Int: 6
// Find the minimum and maximum of a list
float_list.extrema([10.0, 3.0, 50.0, 20.0, 3.0])

File diff suppressed because it is too large Load diff

View file

@ -28,22 +28,22 @@
////
//// * **Distances, sums and products**
//// * [`sum`](#sum)
//// * [`prod`](#prod)
//// * [`product`](#product)
//// * [`norm`](#norm)
//// * [`cumsum`](#cumsum)
//// * [`cumprod`](#cumprod)
//// * [`cumulative_sum`](#cumulative_sum)
//// * [`cumulative_product`](#cumulative_product)
//// * **Ranges and intervals**
//// * [`linspace`](#linspace)
//// * [`logspace`](#linspace)
//// * [`geomspace`](#linspace)
//// * [`linear_space`](#linear_space)
//// * [`logarithm_space`](#logarithm_space)
//// * [`geometric_space`](#geometric_space)
//// * **Misc. mathematical functions**
//// * [`amax`](#amax)
//// * [`amin`](#amin)
//// * [`argmax`](#argmax)
//// * [`argmin`](#argmin)
//// * [`maximum`](#maximum)
//// * [`minimum`](#minimum)
//// * [`extrema`](#extrema)
//// * [`argmax`](#arg_maximum)
//// * [`argmin`](#arg_minimum)
//// * **Tests**
//// * [`allclose`](#allclose)
//// * [`all_close`](#all_close)
//// * **Misc. functions**
//// * [`trim`](#trim)
@ -51,10 +51,11 @@ import gleam/list
import gleam/int
import gleam/float
import gleam/pair
import gleam/option
import gleam_community/maths/float as floatx
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -67,7 +68,7 @@ import gleam_community/maths/float as floatx
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
///
@ -80,30 +81,29 @@ import gleam_community/maths/float as floatx
/// </a>
/// </div>
///
pub fn linspace(
pub fn linear_space(
start: Float,
stop: Float,
num: Int,
endpoint: option.Option,
retstep: option.Option,
endpoint: option.Option(Bool),
) -> List(Float) {
todo
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
///
/// Return numbers spaced evenly on a log scale.
/// Return numbers spaced evenly on a logarrithmic scale.
/// In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop.
///
/// <details>
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
///
@ -116,19 +116,18 @@ pub fn linspace(
/// </a>
/// </div>
///
pub fn logspace(
pub fn logarithm_space(
start: Float,
stop: Float,
num: Int,
endpoint: option.Option,
retstep: option.Option,
endpoint: option.Option(Bool),
base: Int,
) -> List(Float) {
todo
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -140,7 +139,7 @@ pub fn logspace(
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
///
@ -153,18 +152,17 @@ pub fn logspace(
/// </a>
/// </div>
///
pub fn geomspace(
pub fn geometric_space(
start: Float,
stop: Float,
num: Int,
endpoint: option.Option,
retstep: option.Option,
endpoint: option.Option(Bool),
) -> List(Float) {
todo
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -182,17 +180,17 @@ pub fn geomspace(
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty list returns an error
/// []
/// |> stats.sum()
/// |> float_list.sum()
/// |> should.equal(0.)
///
/// // Valid input returns a result
/// [1., 2., 3.]
/// |> stats.sum()
/// |> float_list.sum()
/// |> should.equal(6.)
/// }
/// </details>
@ -213,7 +211,7 @@ pub fn sum(arr: List(Float)) -> Float {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -231,17 +229,17 @@ pub fn sum(arr: List(Float)) -> Float {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty list returns an error
/// []
/// |> stats.sum()
/// |> float_list.sum()
/// |> should.equal(0.)
///
/// // Valid input returns a result
/// [1., 2., 3.]
/// |> stats.prod()
/// |> float_list.product()
/// |> should.equal(6.)
/// }
/// </details>
@ -252,7 +250,7 @@ pub fn sum(arr: List(Float)) -> Float {
/// </a>
/// </div>
///
pub fn prod(arr: List(Float)) -> Float {
pub fn product(arr: List(Float)) -> Float {
case arr {
[] -> 0.0
_ ->
@ -262,7 +260,7 @@ pub fn prod(arr: List(Float)) -> Float {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -280,18 +278,17 @@ pub fn prod(arr: List(Float)) -> Float {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty list returns an error
/// []
/// |> stats.sum()
/// |> should.equal(0.)
/// |> float_list.cumulative_sum()
/// |> should.equal([])
///
/// // Valid input returns a result
/// [1., 2., 3.]
/// |> stats.sum()
/// |> should.equal(6.)
/// [1.0, 2.0, 3.0]
/// |> float_list.cumulative_sum()
/// |> should.equal([1.0, 3.0, 6.0])
/// }
/// </details>
///
@ -301,12 +298,12 @@ pub fn prod(arr: List(Float)) -> Float {
/// </a>
/// </div>
///
pub fn cumsum(arr: List(Float)) -> List(Float) {
pub fn cumulative_sum(arr: List(Float)) -> List(Float) {
todo
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -324,18 +321,18 @@ pub fn cumsum(arr: List(Float)) -> List(Float) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty list returns an error
/// []
/// |> stats.sum()
/// |> float_list.sum()
/// |> should.equal(0.)
///
/// // Valid input returns a result
/// [1., 2., 3.]
/// |> stats.prod()
/// |> should.equal(6.)
/// [1.0, 2.0, 3.0]
/// |> float_list.cumulative_product()
/// |> should.equal([1.0, 2.0, 6.0])
/// }
/// </details>
///
@ -345,12 +342,12 @@ pub fn cumsum(arr: List(Float)) -> List(Float) {
/// </a>
/// </div>
///
pub fn cumprod(arr: List(Float)) -> List(Float) {
pub fn cumumlative_product(arr: List(Float)) -> List(Float) {
todo
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -360,7 +357,7 @@ pub fn cumprod(arr: List(Float)) -> List(Float) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
///
@ -378,7 +375,7 @@ pub fn norm(xarr: List(Float), yarr: List(Float), p: Int) -> List(Float) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -389,17 +386,17 @@ pub fn norm(xarr: List(Float), yarr: List(Float), p: Int) -> List(Float) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty lists returns an error
/// []
/// |> stats.amax()
/// |> float_list.maximum()
/// |> should.be_error()
///
/// // Valid input returns a result
/// [4., 4., 3., 2., 1.]
/// |> stats.amax()
/// |> float_list.maximum()
/// |> should.equal(Ok(4.))
/// }
/// </details>
@ -410,7 +407,7 @@ pub fn norm(xarr: List(Float), yarr: List(Float), p: Int) -> List(Float) {
/// </a>
/// </div>
///
pub fn amax(arr: List(Float)) -> Result(Float, String) {
pub fn maximum(arr: List(Float)) -> Result(Float, String) {
case arr {
[] ->
"Invalid input argument: The list is empty."
@ -433,7 +430,7 @@ pub fn amax(arr: List(Float)) -> Result(Float, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -444,17 +441,17 @@ pub fn amax(arr: List(Float)) -> Result(Float, String) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty lists returns an error
/// []
/// |> stats.amin()
/// |> float_list.minimum()
/// |> should.be_error()
///
/// // Valid input returns a result
/// [4., 4., 3., 2., 1.]
/// |> stats.amin()
/// |> float_list.minimum()
/// |> should.equal(Ok(1.))
/// }
/// </details>
@ -465,7 +462,7 @@ pub fn amax(arr: List(Float)) -> Result(Float, String) {
/// </a>
/// </div>
///
pub fn amin(arr: List(Float)) -> Result(Float, String) {
pub fn minimum(arr: List(Float)) -> Result(Float, String) {
case arr {
[] ->
"Invalid input argument: The list is empty."
@ -488,7 +485,7 @@ pub fn amin(arr: List(Float)) -> Result(Float, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -499,17 +496,17 @@ pub fn amin(arr: List(Float)) -> Result(Float, String) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty lists returns an error
/// []
/// |> stats.argmax()
/// |> float_list.arg_maximum()
/// |> should.be_error()
///
/// // Valid input returns a result
/// [4., 4., 3., 2., 1.]
/// |> stats.argmax()
/// |> float_list.arg_maximum()
/// |> should.equal(Ok([0, 1]))
/// }
/// </details>
@ -520,7 +517,7 @@ pub fn amin(arr: List(Float)) -> Result(Float, String) {
/// </a>
/// </div>
///
pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
pub fn arg_maximum(arr: List(Float)) -> Result(List(Int), String) {
case arr {
[] ->
"Invalid input argument: The list is empty."
@ -528,7 +525,7 @@ pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
_ -> {
assert Ok(max) =
arr
|> amax()
|> maximum()
arr
|> list.index_map(fn(index: Int, a: Float) -> Int {
case a -. max {
@ -548,7 +545,7 @@ pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -559,17 +556,17 @@ pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty lists returns an error
/// []
/// |> stats.argmin()
/// |> float_list.arg_minimum()
/// |> should.be_error()
///
/// // Valid input returns a result
/// [4., 4., 3., 2., 1.]
/// |> stats.argmin()
/// |> float_list.arg_minimum()
/// |> should.equal(Ok([4]))
/// }
/// </details>
@ -580,7 +577,7 @@ pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
/// </a>
/// </div>
///
pub fn argmin(arr: List(Float)) -> Result(List(Int), String) {
pub fn arg_mininmum(arr: List(Float)) -> Result(List(Int), String) {
case arr {
[] ->
"Invalid input argument: The list is empty."
@ -588,7 +585,7 @@ pub fn argmin(arr: List(Float)) -> Result(List(Int), String) {
_ -> {
assert Ok(min) =
arr
|> amin()
|> minimum()
arr
|> list.index_map(fn(index: Int, a: Float) -> Int {
case a -. min {
@ -608,7 +605,7 @@ pub fn argmin(arr: List(Float)) -> Result(List(Int), String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -619,17 +616,17 @@ pub fn argmin(arr: List(Float)) -> Result(List(Int), String) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// // An empty lists returns an error
/// []
/// |> stats.amin()
/// |> float_list.extrema()
/// |> should.be_error()
///
/// // Valid input returns a result
/// [4., 4., 3., 2., 1.]
/// |> stats.amin()
/// |> float_list.extrema()
/// |> should.equal(Ok(1.))
/// }
/// </details>
@ -645,7 +642,7 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -657,7 +654,8 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) {
/// <summary>Example:</summary>
///
/// import gleeunit/should
/// import gleam_stats/stats
/// import gleam/list
/// import gleam_community/maths/float_list
///
/// pub fn example () {
/// let val: Float = 99.
@ -668,7 +666,7 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) {
/// // if 'val' is within 1 percent of 'ref_val' +/- 0.1
/// let rtol: Float = 0.01
/// let atol: Float = 0.10
/// stats.allclose(xarr, yarr, rtol, atol)
/// float_list.all_close(xarr, yarr, rtol, atol)
/// |> fn(zarr: Result(List(Bool), String)) -> Result(Bool, Nil) {
/// case zarr {
/// Ok(arr) ->
@ -688,7 +686,7 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) {
/// </a>
/// </div>
///
pub fn allclose(
pub fn all_close(
xarr: List(Float),
yarr: List(Float),
rtol: Float,
@ -703,7 +701,7 @@ pub fn allclose(
True ->
list.zip(xarr, yarr)
|> list.map(fn(z: #(Float, Float)) -> Bool {
floatx.isclose(pair.first(z), pair.second(z), rtol, atol)
floatx.is_close(pair.first(z), pair.second(z), rtol, atol)
})
|> Ok
}

View file

@ -65,7 +65,7 @@ import gleam/int
import gleam/float
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -101,7 +101,7 @@ pub fn min(x: Int, y: Int) -> Int {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -137,7 +137,7 @@ pub fn max(x: Int, y: Int) -> Int {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -170,7 +170,7 @@ pub fn minmax(x: Int, y: Int) -> #(Int, Int) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -207,7 +207,7 @@ if javascript {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -224,7 +224,7 @@ pub fn flipsign(x: Int) -> Int {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -301,7 +301,7 @@ pub fn combination(n: Int, k: Int) -> Result(Int, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -362,7 +362,7 @@ pub fn factorial(n) -> Result(Int, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -431,7 +431,7 @@ pub fn permutation(n: Int, k: Int) -> Result(Int, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>

View file

@ -39,7 +39,7 @@ import gleam/pair
import gleam_community/maths/int as intx
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -99,7 +99,7 @@ pub fn argmin(arr: List(Float)) -> Result(List(Int), String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -159,7 +159,7 @@ pub fn argmax(arr: List(Float)) -> Result(List(Int), String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -214,7 +214,7 @@ pub fn amax(arr: List(Float)) -> Result(Float, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>
@ -269,7 +269,7 @@ pub fn amin(arr: List(Float)) -> Result(Float, String) {
}
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>

View file

@ -34,7 +34,7 @@ import gleam/int
import gleam/float
/// <div style="text-align: right;">
/// <a href="https://github.com/nicklasxyz/gleam_stats/issues">
/// <a href="https://github.com/gleam-community/maths/issues">
/// <small>Spot a typo? Open an issue!</small>
/// </a>
/// </div>

View file

@ -10,17 +10,17 @@ pub fn main() {
}
pub fn float_acos_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
assert Ok(result) = floatx.acos(1.0)
result
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
assert Ok(result) = floatx.acos(0.5)
result
|> floatx.isclose(1.047197, 0.0, tol)
|> floatx.is_close(1.047197, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
@ -33,12 +33,12 @@ pub fn float_acos_test() {
}
pub fn float_acosh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
assert Ok(result) = floatx.acosh(1.0)
result
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
@ -53,10 +53,10 @@ pub fn float_asin_test() {
floatx.asin(0.0)
|> should.equal(Ok(0.0))
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
assert Ok(result) = floatx.asin(0.5)
result
|> floatx.isclose(0.523598, 0.0, tol)
|> floatx.is_close(0.523598, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
@ -69,91 +69,91 @@ pub fn float_asin_test() {
}
pub fn float_asinh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.asinh(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.asinh(0.5)
|> floatx.isclose(0.481211, 0.0, tol)
|> floatx.is_close(0.481211, 0.0, tol)
|> should.be_true()
}
pub fn float_atan_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.atan(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.atan(0.5)
|> floatx.isclose(0.463647, 0.0, tol)
|> floatx.is_close(0.463647, 0.0, tol)
|> should.be_true()
}
pub fn math_atan2_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.atan2(0.0, 0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.atan2(0.0, 1.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
// Check atan2(y=1.0, x=0.5)
// Should be equal to atan(y / x) for any x > 0 and any y
let result = floatx.atan(1.0 /. 0.5)
floatx.atan2(1.0, 0.5)
|> floatx.isclose(result, 0.0, tol)
|> floatx.is_close(result, 0.0, tol)
|> should.be_true()
// Check atan2(y=2.0, x=-1.5)
// Should be equal to pi + atan(y / x) for any x < 0 and y >= 0
let result = floatx.pi() +. floatx.atan(2.0 /. -1.5)
floatx.atan2(2.0, -1.5)
|> floatx.isclose(result, 0.0, tol)
|> floatx.is_close(result, 0.0, tol)
|> should.be_true()
// Check atan2(y=-2.0, x=-1.5)
// Should be equal to atan(y / x) - pi for any x < 0 and y < 0
let result = floatx.atan(-2.0 /. -1.5) -. floatx.pi()
floatx.atan2(-2.0, -1.5)
|> floatx.isclose(result, 0.0, tol)
|> floatx.is_close(result, 0.0, tol)
|> should.be_true()
// Check atan2(y=1.5, x=0.0)
// Should be equal to pi/2 for x = 0 and any y > 0
let result = floatx.pi() /. 2.0
floatx.atan2(1.5, 0.0)
|> floatx.isclose(result, 0.0, tol)
|> floatx.is_close(result, 0.0, tol)
|> should.be_true()
// Check atan2(y=-1.5, x=0.0)
// Should be equal to -pi/2 for x = 0 and any y < 0
let result = -1.0 *. floatx.pi() /. 2.0
floatx.atan2(-1.5, 0.0)
|> floatx.isclose(result, 0.0, tol)
|> floatx.is_close(result, 0.0, tol)
|> should.be_true()
}
pub fn float_atanh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
assert Ok(result) = floatx.atanh(0.0)
result
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
assert Ok(result) = floatx.atanh(0.5)
result
|> floatx.isclose(0.549306, 0.0, tol)
|> floatx.is_close(0.549306, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
@ -172,32 +172,32 @@ pub fn float_atanh_test() {
}
pub fn float_cos_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.cos(0.0)
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
floatx.cos(floatx.pi())
|> floatx.isclose(-1.0, 0.0, tol)
|> floatx.is_close(-1.0, 0.0, tol)
|> should.be_true()
floatx.cos(0.5)
|> floatx.isclose(0.877582, 0.0, tol)
|> floatx.is_close(0.877582, 0.0, tol)
|> should.be_true()
}
pub fn float_cosh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.cosh(0.0)
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
floatx.cosh(0.5)
|> floatx.isclose(1.127625, 0.0, tol)
|> floatx.is_close(1.127625, 0.0, tol)
|> should.be_true()
// An (overflow) error might occur when given an input
// value that will result in a too large output value
@ -205,16 +205,16 @@ pub fn float_cosh_test() {
// runtime.
}
pub fn float_exp_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
pub fn float_exponential_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.exp(0.0)
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
floatx.exp(0.5)
|> floatx.isclose(1.648721, 0.0, tol)
|> floatx.is_close(1.648721, 0.0, tol)
|> should.be_true()
// An (overflow) error might occur when given an input
// value that will result in a too large output value
@ -222,205 +222,233 @@ pub fn float_exp_test() {
// runtime.
}
pub fn float_log_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
pub fn float_natural_logarithm_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.log(1.0)
floatx.natural_logarithm(1.0)
|> should.equal(Ok(0.0))
assert Ok(result) = floatx.log(0.5)
assert Ok(result) = floatx.natural_logarithm(0.5)
result
|> floatx.isclose(-0.693147, 0.0, tol)
|> floatx.is_close(-0.693147, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
// outside its domain
floatx.log(-1.0)
floatx.natural_logarithm(-1.0)
|> should.be_error()
}
pub fn floatx_log10_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
pub fn float_logarithm_10_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
assert Ok(result) = floatx.log10(1.0)
assert Ok(result) = floatx.logarithm_10(1.0)
result
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
assert Ok(result) = floatx.log10(10.0)
assert Ok(result) = floatx.logarithm_10(10.0)
result
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
assert Ok(result) = floatx.log10(50.0)
assert Ok(result) = floatx.logarithm_10(50.0)
result
|> floatx.isclose(1.698970, 0.0, tol)
|> floatx.is_close(1.698970, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
// outside its domain
floatx.log10(-1.0)
floatx.logarithm_10(-1.0)
|> should.be_error()
}
pub fn floatx_log2_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
pub fn float_logarithm_2_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.log2(1.0)
floatx.logarithm_2(1.0)
|> should.equal(Ok(0.0))
floatx.log2(2.0)
floatx.logarithm_2(2.0)
|> should.equal(Ok(1.0))
assert Ok(result) = floatx.log2(5.0)
assert Ok(result) = floatx.logarithm_2(5.0)
result
|> floatx.isclose(2.321928, 0.0, tol)
|> floatx.is_close(2.321928, 0.0, tol)
|> should.be_true()
// Check that we get an error when the function is evaluated
// outside its domain
floatx.log2(-1.0)
floatx.logarithm_2(-1.0)
|> should.be_error()
}
pub fn floatx_logb_test() {
pub fn float_logarithm_test() {
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.logb(10.0, 10.0)
floatx.logarithm(10.0, option.Some(10.0))
|> should.equal(Ok(1.0))
floatx.logb(10.0, 100.0)
floatx.logarithm(10.0, option.Some(100.0))
|> should.equal(Ok(0.5))
floatx.logb(1.0, 0.25)
floatx.logarithm(1.0, option.Some(0.25))
|> should.equal(Ok(0.0))
// Check that we get an error when the function is evaluated
// outside its domain
floatx.logb(1.0, 1.0)
floatx.logarithm(1.0, option.Some(1.0))
|> should.be_error()
floatx.logb(10.0, 1.0)
floatx.logarithm(10.0, option.Some(1.0))
|> should.be_error()
floatx.logb(-1.0, 1.0)
floatx.logarithm(-1.0, option.Some(1.0))
|> should.be_error()
floatx.logarithm(1.0, option.Some(10.0))
|> should.equal(Ok(0.0))
floatx.logarithm(floatx.e(), option.Some(floatx.e()))
|> should.equal(Ok(1.0))
floatx.logarithm(-1.0, option.Some(2.0))
|> should.be_error()
}
pub fn float_pow_test() {
floatx.pow(2.0, 2.0)
pub fn float_power_test() {
floatx.power(2.0, 2.0)
|> should.equal(Ok(4.0))
floatx.pow(-5.0, 3.0)
floatx.power(-5.0, 3.0)
|> should.equal(Ok(-125.0))
floatx.pow(10.5, 0.0)
floatx.power(10.5, 0.0)
|> should.equal(Ok(1.0))
floatx.pow(16.0, 0.5)
floatx.power(16.0, 0.5)
|> should.equal(Ok(4.0))
floatx.pow(2.0, -1.0)
floatx.power(2.0, -1.0)
|> should.equal(Ok(0.5))
floatx.pow(2.0, -1.0)
floatx.power(2.0, -1.0)
|> should.equal(Ok(0.5))
// floatx.pow(-1.0, 0.5) is equivalent to float.square_root(-1.0)
// floatx.power(-1.0, 0.5) is equivalent to float.square_root(-1.0)
// and should return an error as an imaginary number would otherwise
// have to be returned
floatx.pow(-1.0, 0.5)
floatx.power(-1.0, 0.5)
|> should.be_error()
// Check another case with a negative base and fractional exponent
floatx.pow(-1.5, 1.5)
floatx.power(-1.5, 1.5)
|> should.be_error()
// floatx.pow(0.0, -1.0) is equivalent to 1. /. 0 and is expected
// floatx.power(0.0, -1.0) is equivalent to 1. /. 0 and is expected
// to be an error
floatx.pow(0.0, -1.0)
floatx.power(0.0, -1.0)
|> should.be_error()
// Check that a negative base and exponent is fine as long as the
// exponent is not fractional
floatx.pow(-2.0, -1.0)
floatx.power(-2.0, -1.0)
|> should.equal(Ok(-0.5))
}
pub fn float_sqrt_test() {
floatx.sqrt(1.0)
pub fn float_square_root_test() {
floatx.square_root(1.0)
|> should.equal(Ok(1.0))
floatx.sqrt(9.0)
floatx.square_root(9.0)
|> should.equal(Ok(3.0))
// An error should be returned as an imaginary number would otherwise
// have to be returned
floatx.sqrt(-1.0)
floatx.square_root(-1.0)
|> should.be_error()
}
pub fn float_cbrt_test() {
floatx.cbrt(1.0)
pub fn float_cube_root_test() {
floatx.cube_root(1.0)
|> should.equal(Ok(1.0))
floatx.cbrt(27.0)
floatx.cube_root(27.0)
|> should.equal(Ok(3.0))
// An error should be returned as an imaginary number would otherwise
// have to be returned
floatx.cbrt(-1.0)
floatx.cube_root(-1.0)
|> should.be_error()
}
pub fn float_hypot_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
pub fn float_nth_root_test() {
floatx.nth_root(9.0, 2)
|> should.equal(Ok(3.0))
floatx.hypot(0.0, 0.0)
floatx.nth_root(27.0, 3)
|> should.equal(Ok(3.0))
floatx.nth_root(1.0, 4)
|> should.equal(Ok(1.0))
floatx.nth_root(256.0, 4)
|> should.equal(Ok(4.0))
// An error should be returned as an imaginary number would otherwise
// have to be returned
floatx.nth_root(-1.0, 4)
|> should.be_error()
}
pub fn float_hypotenuse_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
floatx.hypotenuse(0.0, 0.0)
|> should.equal(0.0)
floatx.hypot(1.0, 0.0)
floatx.hypotenuse(1.0, 0.0)
|> should.equal(1.0)
floatx.hypot(0.0, 1.0)
floatx.hypotenuse(0.0, 1.0)
|> should.equal(1.0)
let result = floatx.hypot(11.0, 22.0)
let result = floatx.hypotenuse(11.0, 22.0)
result
|> floatx.isclose(24.596747, 0.0, tol)
|> floatx.is_close(24.596747, 0.0, tol)
|> should.be_true()
}
pub fn float_sin_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.sin(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.sin(0.5 *. floatx.pi())
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
floatx.sin(0.5)
|> floatx.isclose(0.479425, 0.0, tol)
|> floatx.is_close(0.479425, 0.0, tol)
|> should.be_true()
}
pub fn float_sinh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.sinh(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.sinh(0.5)
|> floatx.isclose(0.521095, 0.0, tol)
|> floatx.is_close(0.521095, 0.0, tol)
|> should.be_true()
// An (overflow) error might occur when given an input
// value that will result in a too large output value
@ -429,66 +457,66 @@ pub fn float_sinh_test() {
}
pub fn math_tan_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.tan(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.tan(0.5)
|> floatx.isclose(0.546302, 0.0, tol)
|> floatx.is_close(0.546302, 0.0, tol)
|> should.be_true()
}
pub fn math_tanh_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
assert Ok(tol) = floatx.power(-10.0, -6.0)
// Check that the function agrees, at some arbitrary input
// points, with known function values
floatx.tanh(0.0)
|> floatx.isclose(0.0, 0.0, tol)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.tanh(25.0)
|> floatx.isclose(1.0, 0.0, tol)
|> floatx.is_close(1.0, 0.0, tol)
|> should.be_true()
floatx.tanh(-25.0)
|> floatx.isclose(-1.0, 0.0, tol)
|> floatx.is_close(-1.0, 0.0, tol)
|> should.be_true()
floatx.tanh(0.5)
|> floatx.isclose(0.462117, 0.0, tol)
|> floatx.is_close(0.462117, 0.0, tol)
|> should.be_true()
}
pub fn float_rad2deg_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
floatx.rad2deg(0.0)
|> floatx.isclose(0.0, 0.0, tol)
pub fn float_to_degree_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
floatx.to_degree(0.0)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.rad2deg(2.0 *. floatx.pi())
|> floatx.isclose(360.0, 0.0, tol)
floatx.to_degree(2.0 *. floatx.pi())
|> floatx.is_close(360.0, 0.0, tol)
|> should.be_true()
}
pub fn float_deg2rads_test() {
assert Ok(tol) = floatx.pow(-10.0, -6.0)
floatx.deg2rad(0.0)
|> floatx.isclose(0.0, 0.0, tol)
pub fn float_to_radian_test() {
assert Ok(tol) = floatx.power(-10.0, -6.0)
floatx.to_radian(0.0)
|> floatx.is_close(0.0, 0.0, tol)
|> should.be_true()
floatx.deg2rad(360.0)
|> floatx.isclose(2.0 *. floatx.pi(), 0.0, tol)
floatx.to_radian(360.0)
|> floatx.is_close(2.0 *. floatx.pi(), 0.0, tol)
|> should.be_true()
}
pub fn float_ceil_test() {
floatx.ceil(0.1)
pub fn float_ceiling_test() {
floatx.ceiling(0.1)
|> should.equal(1.0)
floatx.ceil(0.9)
floatx.ceiling(0.9)
|> should.equal(1.0)
}
@ -500,31 +528,31 @@ pub fn float_floor_test() {
|> should.equal(0.0)
}
pub fn float_min_test() {
floatx.min(0.75, 0.5)
pub fn float_minimum_test() {
floatx.minimum(0.75, 0.5)
|> should.equal(0.5)
floatx.min(0.5, 0.75)
floatx.minimum(0.5, 0.75)
|> should.equal(0.5)
floatx.min(-0.75, 0.5)
floatx.minimum(-0.75, 0.5)
|> should.equal(-0.75)
floatx.min(-0.75, 0.5)
floatx.minimum(-0.75, 0.5)
|> should.equal(-0.75)
}
pub fn float_max_test() {
floatx.max(0.75, 0.5)
pub fn float_maximum_test() {
floatx.maximum(0.75, 0.5)
|> should.equal(0.75)
floatx.max(0.5, 0.75)
floatx.maximum(0.5, 0.75)
|> should.equal(0.75)
floatx.max(-0.75, 0.5)
floatx.maximum(-0.75, 0.5)
|> should.equal(0.5)
floatx.max(-0.75, 0.5)
floatx.maximum(-0.75, 0.5)
|> should.equal(0.5)
}
@ -542,38 +570,38 @@ pub fn float_minmax_test() {
|> should.equal(#(-0.75, 0.5))
}
pub fn float_sign_test() {
floatx.sign(100.0)
|> should.equal(1.0)
// pub fn float_sign_test() {
// floatx.sign(100.0)
// |> should.equal(1.0)
floatx.sign(0.0)
|> should.equal(0.0)
// floatx.sign(0.0)
// |> should.equal(0.0)
floatx.sign(-100.0)
|> should.equal(-1.0)
// floatx.sign(-100.0)
// |> should.equal(-1.0)
// }
// pub fn float_flipsign_test() {
// floatx.flipsign(100.0)
// |> should.equal(-100.0)
// floatx.flipsign(0.0)
// |> should.equal(-0.0)
// floatx.flipsign(-100.0)
// |> should.equal(100.0)
// }
pub fn float_beta_function_test() {
io.debug("TODO: Implement tests for 'float.beta'.")
}
pub fn float_flipsign_test() {
floatx.flipsign(100.0)
|> should.equal(-100.0)
floatx.flipsign(0.0)
|> should.equal(-0.0)
floatx.flipsign(-100.0)
|> should.equal(100.0)
pub fn float_error_function_test() {
io.debug("TODO: Implement tests for 'float.erf'.")
}
pub fn float_beta_test() {
io.debug("TODO: Implement tests for 'floatx.beta'.")
}
pub fn float_erf_test() {
io.debug("TODO: Implement tests for 'floatx.erf'.")
}
pub fn float_gamma_test() {
io.debug("TODO: Implement tests for 'floatx.gamma'.")
pub fn float_gamma_function_test() {
io.debug("TODO: Implement tests for 'float.gamma'.")
}
pub fn math_round_to_nearest_test() {
@ -620,6 +648,7 @@ pub fn math_round_up_test() {
}
pub fn math_round_down_test() {
// Try with positive values
floatx.round(0.45, option.Some(0), option.Some("Down"))
|> should.equal(Ok(0.0))
@ -637,6 +666,25 @@ pub fn math_round_down_test() {
floatx.round(0.5050, option.Some(2), option.Some("Down"))
|> should.equal(Ok(0.50))
// Try with negative values
floatx.round(-0.45, option.Some(0), option.Some("Down"))
|> should.equal(Ok(-1.0))
floatx.round(-0.50, option.Some(0), option.Some("Down"))
|> should.equal(Ok(-1.0))
floatx.round(-0.45, option.Some(1), option.Some("Down"))
|> should.equal(Ok(-0.5))
floatx.round(-0.50, option.Some(1), option.Some("Down"))
|> should.equal(Ok(-0.50))
floatx.round(-0.4550, option.Some(2), option.Some("Down"))
|> should.equal(Ok(-0.46))
floatx.round(-0.5050, option.Some(2), option.Some("Down"))
|> should.equal(Ok(-0.51))
}
pub fn math_round_to_zero_test() {
@ -705,60 +753,71 @@ pub fn math_round_ties_up_test() {
|> should.equal(Ok(3.0))
}
pub fn float_gammainc_test() {
pub fn float_incomplete_gamma_function_test() {
// Invalid input gives an error
// 1st arg is invalid
floatx.gammainc(-1.0, 1.0)
floatx.incomplete_gamma(-1.0, 1.0)
|> should.be_error()
// 2nd arg is invalid
floatx.gammainc(1.0, -1.0)
floatx.incomplete_gamma(1.0, -1.0)
|> should.be_error()
// Valid input returns a result
floatx.gammainc(1.0, 0.0)
floatx.incomplete_gamma(1.0, 0.0)
|> result.unwrap(-999.0)
|> floatx.isclose(0.0, 0.0, 0.01)
|> floatx.is_close(0.0, 0.0, 0.01)
|> should.be_true()
floatx.gammainc(1.0, 2.0)
floatx.incomplete_gamma(1.0, 2.0)
|> result.unwrap(-999.0)
|> floatx.isclose(0.864664716763387308106, 0.0, 0.01)
|> floatx.is_close(0.864664716763387308106, 0.0, 0.01)
|> should.be_true()
floatx.gammainc(2.0, 3.0)
floatx.incomplete_gamma(2.0, 3.0)
|> result.unwrap(-999.0)
|> floatx.isclose(0.8008517265285442280826, 0.0, 0.01)
|> floatx.is_close(0.8008517265285442280826, 0.0, 0.01)
|> should.be_true()
floatx.gammainc(3.0, 4.0)
floatx.incomplete_gamma(3.0, 4.0)
|> result.unwrap(-999.0)
|> floatx.isclose(1.523793388892911312363, 0.0, 0.01)
|> floatx.is_close(1.523793388892911312363, 0.0, 0.01)
|> should.be_true()
}
pub fn float_absdiff_test() {
floatx.absdiff(0.0, 0.0)
pub fn float_absolute_difference_test() {
floatx.absolute_difference(0.0, 0.0)
|> should.equal(0.0)
floatx.absdiff(1.0, 2.0)
floatx.absolute_difference(1.0, 2.0)
|> should.equal(1.0)
floatx.absdiff(2.0, 1.0)
floatx.absolute_difference(2.0, 1.0)
|> should.equal(1.0)
floatx.absdiff(-1.0, 0.0)
floatx.absolute_difference(-1.0, 0.0)
|> should.equal(1.0)
floatx.absdiff(0.0, -1.0)
floatx.absolute_difference(0.0, -1.0)
|> should.equal(1.0)
floatx.absdiff(10.0, 20.0)
floatx.absolute_difference(10.0, 20.0)
|> should.equal(10.0)
floatx.absdiff(-10.0, -20.0)
floatx.absolute_difference(-10.0, -20.0)
|> should.equal(10.0)
floatx.absdiff(-10.5, 10.5)
floatx.absolute_difference(-10.5, 10.5)
|> should.equal(21.0)
}
pub fn float_constants_test() {
floatx.e()
|> io.debug()
|> floatx.is_close(2.71828, 0.0, 0.00001)
|> should.be_true()
floatx.pi()
|> floatx.is_close(3.14159, 0.0, 0.00001)
|> should.be_true()
}