diff options
author | Dirk Gadsden <dirk@esherido.com> | 2019-08-15 11:53:05 -0700 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-08-16 17:11:11 +0100 |
commit | 3798acbcdef9cb2312ba21666858a1f1776198d6 (patch) | |
tree | b39635d756ff3d8113e0b0b7e0b2458d1b832a81 /src | |
parent | 261889c5b56b6610c370e2bd6ae78c0f81e22688 (diff) | |
download | gleam_stdlib-3798acbcdef9cb2312ba21666858a1f1776198d6.tar.gz gleam_stdlib-3798acbcdef9cb2312ba21666858a1f1776198d6.zip |
Add `float:compare` function to stdlib
Fixes #209
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/float.gleam | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index b1ae86e..65be088 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -1,4 +1,5 @@ import gleam/iodata +import gleam/order pub enum NotAFloat = | NotAFloat @@ -12,6 +13,17 @@ pub fn to_string(f) { |> iodata:to_string } +pub fn compare(a, b) { + case a == b { + | True -> order:Eq + | False -> + case a <. b { + | True -> order:Lt + | False -> order:Gt + } + } +} + pub external fn ceiling(Float) -> Float = "math" "ceil"; pub external fn floor(Float) -> Float = "math" "floor"; |