aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsharno <sharnoby3@gmail.com>2020-10-10 16:01:50 -0400
committerLouis Pilfold <louis@lpil.uk>2020-10-13 12:50:34 +0100
commit42c75c7c9594a068d72b75390b2a47e17544d087 (patch)
tree9d2bf0998b4551a32d8a67656a2b6c868bb31336 /src
parent2d7e7143d6b6445bd6973ff88e6594dfd1da4966 (diff)
downloadgleam_stdlib-42c75c7c9594a068d72b75390b2a47e17544d087.tar.gz
gleam_stdlib-42c75c7c9594a068d72b75390b2a47e17544d087.zip
add negate functions to int and float modules
Diffstat (limited to 'src')
-rw-r--r--src/gleam/float.gleam11
-rw-r--r--src/gleam/int.gleam11
2 files changed, 22 insertions, 0 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam
index ecb203c..24f0330 100644
--- a/src/gleam/float.gleam
+++ b/src/gleam/float.gleam
@@ -160,3 +160,14 @@ pub fn square_root(number: Float) -> Result(Float, Nil) {
False -> Ok(power(number, 0.5))
}
}
+
+/// Returns the negative of the value provided
+///
+/// ## Examples
+///
+/// > negate(1.)
+/// -1.
+///
+pub fn negate(x: Float) -> Float {
+ -1. *. x
+}
diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam
index 151bfa3..2dc4f46 100644
--- a/src/gleam/int.gleam
+++ b/src/gleam/int.gleam
@@ -121,3 +121,14 @@ pub fn is_even(x: Int) -> Bool {
pub fn is_odd(x: Int) -> Bool {
x % 2 != 0
}
+
+/// Returns the negative of the value provided
+///
+/// ## Examples
+///
+/// > negate(1)
+/// -1
+///
+pub fn negate(x: Int) -> Int {
+ -1 * x
+}