aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorinoas <mail@inoas.com>2022-04-13 02:51:22 +0200
committerLouis Pilfold <louis@lpil.uk>2022-04-16 10:23:34 +0100
commit4e06f94b78b3a47ed5b9745e7f646ed261fbe98c (patch)
treea5dcf833f431eae2e60970d5b4e0d3a291b4b55c /src
parent3402ff3617bcc12365a20e6f24c5e007656836e6 (diff)
downloadgleam_stdlib-4e06f94b78b3a47ed5b9745e7f646ed261fbe98c.tar.gz
gleam_stdlib-4e06f94b78b3a47ed5b9745e7f646ed261fbe98c.zip
rename {float,int}.distance() to {float,int}.absolute_difference(), remove {float,int}.random_to()
Diffstat (limited to 'src')
-rw-r--r--src/gleam/float.gleam18
-rw-r--r--src/gleam/int.gleam12
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)
-}