From 5f0a4a01f9650f00398b5b4fdf10447ad667afda Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Sat, 11 Nov 2023 13:37:48 +0000 Subject: Document division by zero --- src/gleam/float.gleam | 14 ++++++++++++++ src/gleam/int.gleam | 12 ++++++++++++ 2 files changed, 26 insertions(+) (limited to 'src') 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} -- cgit v1.2.3