diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/float.gleam | 18 | ||||
-rw-r--r-- | src/gleam/int.gleam | 12 |
2 files changed, 9 insertions, 21 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index 42a7b7b..4ff48b2 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -228,17 +228,17 @@ pub fn absolute_value(float: Float) -> Float { } } -/// Returns the absolute distance of the inputs as a positive Float +/// Returns the absolute difference of the inputs as a positive Float /// /// ## Examples /// -/// > distance(-10.0, 10.0) +/// > absolute_difference(-10.0, 10.0) /// 20.0 /// -/// > distance(0.0, -2.0) +/// > absolute_difference(0.0, -2.0) /// 2.0 /// -pub fn distance(a: Float, b: Float) -> Float { +pub fn absolute_difference(a: Float, b: Float) -> Float { a -. b |> absolute_value() } @@ -371,14 +371,6 @@ pub fn random_between(boundary_a: Float, boundary_b: Float) -> Float { } case min, max { min, _max if min == max -> min - min, max -> random_uniform() *. distance(min, max) +. min + min, max -> random_uniform() *. absolute_difference(min, max) +. min } } - -/// If boundary is `0.0` this will yield `0.0`. -/// If negative, this will yield `-x < 0 ` -/// If positive, this will yield `0 < x ` -/// -pub fn random_to(boundary: Float) -> Float { - random_uniform() *. boundary -} diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index f23f0f9..1f7957a 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -18,17 +18,17 @@ pub fn absolute_value(num: Int) -> Int { } } -/// Returns the absolute distance of the inputs as a positive Int +/// Returns the absolute difference of the inputs as a positive Int /// /// ## Examples /// -/// > distance(-10, 10) +/// > absolute_difference(-10, 10) /// 20 /// -/// > distance(0.0, -2) +/// > absolute_difference(0.0, -2) /// 2 /// -pub fn distance(a: Int, b: Int) -> Int { +pub fn absolute_difference(a: Int, b: Int) -> Int { a - b |> absolute_value() } @@ -415,7 +415,3 @@ pub fn random_between(min: Int, max: Int) -> Int { |> float.floor() |> float.round() } - -pub fn random_to(max: Int) -> Int { - random_between(0, max) -} |