Skip to content

Commit

Permalink
Minor documentation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-viney committed Sep 8, 2024
1 parent 301ee9a commit 482c3ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This Gleam library provides an `IEEEFloat` type that is compliant with the IEEE

## Background

Erlang's native float data type does not support infinity and NaN values, and
this library fills that gap when these values need to be able to be represented
and worked with.
Erlang's native float data type does not support infinity and NaN values. This
library fills that gap when such values need to be able to be represented and
worked with.

On the JavaScript target, an `IEEEFloat` is simply a `number` because JavaScript
natively implements the IEEE 754 standard.
Expand Down
16 changes: 10 additions & 6 deletions src/ieee_float.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,21 @@ fn rescue_bad_arith(do: fn() -> a) -> Result(a, Nil) {
case erlang.rescue(do) {
Ok(r) -> Ok(r)

Error(erlang.Errored(reason)) ->
case
atom.from_dynamic(reason) |> result.map(atom.to_string)
== Ok("badarith")
{
Error(erlang.Errored(reason)) -> {
// Convert reason to string
let reason =
reason
|> atom.from_dynamic
|> result.map(atom.to_string)

case reason == Ok("badarith") {
True -> Error(Nil)
False ->
panic as {
"Unexpected error in float operation: " <> string.inspect(reason)
}
}
}

Error(e) ->
panic as { "Unexpected error in float operation: " <> string.inspect(e) }
Expand Down Expand Up @@ -357,7 +361,7 @@ pub fn clamp(
|> max(min_bound)
}

/// Compares two `IEEEFloats`, returning an `Order`: `Lt` for lower than, `Eq`
/// Compares two `IEEEFloat`s, returning an `Order`: `Lt` for lower than, `Eq`
/// for equals, or `Gt` for greater than. If either value is NaN then
/// `Error(Nil)` is returned.
///
Expand Down

0 comments on commit 482c3ab

Please sign in to comment.