Skip to content

Commit

Permalink
add math.isNaN
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Nov 29, 2020
1 parent d29eddf commit 580dadd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

- `writeStackTrace` is available in JS backend now.

- Added `math.isNaN`.

## Language changes

- `nimscript` now handles `except Exception as e`.
Expand Down
8 changes: 8 additions & 0 deletions lib/pure/math.nim
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ proc classify*(x: float): FloatClass =
return fcSubnormal
return fcNormal

proc isNaN*(x: float): bool =
## Returns whether `x` is a `NaN`, more efficiently than via `classify(x) == fcNan`.
## Does not work with: `--passc:-ffast-math`.
runnableExamples:
doAssert NaN.isNaN
doAssert not Inf.isNaN
result = x != x

proc almostEqual*[T: SomeFloat](x, y: T; unitsInLastPlace: Natural = 4): bool {.
since: (1, 5), inline, noSideEffect.} =
## Checks if two float values are almost equal, using
Expand Down

0 comments on commit 580dadd

Please sign in to comment.