aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/int.gleam17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 002a155..a4a956a 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -3,6 +3,23 @@ import gleam/order.{Order}
pub type Int =
Int
+/// Returns the absolute value of the input.
+///
+/// ## Examples
+///
+/// > absolute_value(-12)
+/// 12
+///
+/// > absolute_value(10)
+/// 10
+///
+pub fn absolute_value(num: Int) -> Int {
+ case num >= 0 {
+ True -> num
+ False -> num * -1
+ }
+}
+
/// Parse a given string as an int if possible.
///
/// ## Examples