diff options
author | Simon Johansson <simon@findsourcing.com> | 2024-01-29 08:26:04 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-01-30 10:43:42 +0000 |
commit | 8544c4099ca8747486410f33cb1cb0c06ba2f684 (patch) | |
tree | ec734cbd44b38e4f696b4d3c95ba2e51f35db5e6 /src | |
parent | c2145387b54904694cadbc3140bd89ce1dc6a185 (diff) | |
download | tour-8544c4099ca8747486410f33cb1cb0c06ba2f684.tar.gz tour-8544c4099ca8747486410f33cb1cb0c06ba2f684.zip |
Explain runtime differences for floats
Diffstat (limited to 'src')
-rw-r--r-- | src/content/chapter0_basics/lesson05_floats/code.gleam | 3 | ||||
-rw-r--r-- | src/content/chapter0_basics/lesson05_floats/text.html | 24 |
2 files changed, 21 insertions, 6 deletions
diff --git a/src/content/chapter0_basics/lesson05_floats/code.gleam b/src/content/chapter0_basics/lesson05_floats/code.gleam index 8c4e89a..4241ab4 100644 --- a/src/content/chapter0_basics/lesson05_floats/code.gleam +++ b/src/content/chapter0_basics/lesson05_floats/code.gleam @@ -18,6 +18,9 @@ pub fn main() { io.debug(1.1 == 1.1) io.debug(2.1 == 1.2) + // Division by zero is not an error + io.debug(3.14 /. 0.0) + // Standard library float functions io.debug(float.max(2.0, 9.5)) io.debug(float.ceiling(5.4)) diff --git a/src/content/chapter0_basics/lesson05_floats/text.html b/src/content/chapter0_basics/lesson05_floats/text.html index cc993c4..1b56d73 100644 --- a/src/content/chapter0_basics/lesson05_floats/text.html +++ b/src/content/chapter0_basics/lesson05_floats/text.html @@ -1,15 +1,27 @@ <p>Gleam's <code>Float</code> type represents numbers that are not integers.</p> <p> - Unlike many languages Gleam does not have a <code>NaN</code> or - <code>Infinity</code> float value. + Gleam's numerical operators are not overloaded, so there are dedicatated + operators for working with floats. </p> <p> - Gleam's numerical operators are not overloaded, so there are dedictated - operators for working with floats. + Floats are represented as 64 bit floating point numbers on both the Erlang and + JavaScript runtimes. The floating point behaviour is native to their + respective runtimes, so their exact behaviour will be slightly different + on the two runtimes. +</p> +<p> + Under the JavaScript runtime, exceeding the maximum (or minimum) representable + value for a floating point value will result in <code>Infinity</code> (or + <code>-Infinity</code>). Should you try to divide two infinities you will + get <code>NaN</code> as a result. +</p> +<p> + When running on the BEAM any overflow will raise an error. So there is + no <code>NaN</code> or <code>Infinity</code> float value in the Erlang + runtime. </p> <p> - Floats are represented as 64 bit floating point numbers on both Erlang and - JavaScript runtimes. + Division by zero will not overflow, but is instead defined to be zero. </p> <p> The |