diff options
author | Louis Pilfold <louis@lpil.uk> | 2023-11-11 13:37:48 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-11-11 13:39:52 +0000 |
commit | 5f0a4a01f9650f00398b5b4fdf10447ad667afda (patch) | |
tree | 11dfec5616899db821afff08812c9c93a026c3c6 | |
parent | 920b2694dcb4bd345489ff04e0b6dff2c4ebb397 (diff) | |
download | gleam_stdlib-5f0a4a01f9650f00398b5b4fdf10447ad667afda.tar.gz gleam_stdlib-5f0a4a01f9650f00398b5b4fdf10447ad667afda.zip |
Document division by zero
-rw-r--r-- | src/gleam/float.gleam | 14 | ||||
-rw-r--r-- | src/gleam/int.gleam | 12 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index 59789fc..5d62419 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -1,3 +1,17 @@ +//// Functions for working with floats. +//// +//// ## Division by zero +//// +//// Gleam runs on the Erlang virtual machine, which does not follow the IEEE +//// 754 standard for floating point arithmetic and does not have an `Infinity` +//// value. In Erlang division by zero results in a crash, however Gleam does +//// not have partial functions and operators in core so instead division by zero +//// returns zero, a behaviour taken from Pony, Coq, and Lean. +//// +//// This may seem unexpected at first, but it is no less mathematically valid +//// than crashing or returning a special value. Division by zero is undefined +//// in mathematics. + import gleam/order.{type Order} /// Attempts to parse a string as a `Float`, returning `Error(Nil)` if it was diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index 8b3b89e..d93c16a 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -1,3 +1,15 @@ +//// Functions for working with integers. +//// +//// ## Division by zero +//// +//// In Erlang division by zero results in a crash, however Gleam does not have +//// partial functions and operators in core so instead division by zero returns +//// zero, a behaviour taken from Pony, Coq, and Lean. +//// +//// This may seem unexpected at first, but it is no less mathematically valid +//// than crashing or returning a special value. Division by zero is undefined +//// in mathematics. + import gleam/float import gleam/order.{type Order} |