Skip to content

Commit

Permalink
Make std/math classify work without --passc:-fast-math. (#23211)
Browse files Browse the repository at this point in the history
By using the existing isNaN function we can make std/math's classify
function work even if `--passc:-fast-math` is used.
  • Loading branch information
AngelEzquerra authored Jan 18, 2024
1 parent b2f79df commit 38f9ee0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/pure/math.nim
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func isNaN*(x: SomeFloat): bool {.inline, since: (1,5,1).} =
template fn: untyped = result = x != x
when nimvm: fn()
else:
when defined(js): fn()
when defined(js) or defined(nimscript): fn()
else: result = c_isnan(x)

when defined(js):
Expand Down Expand Up @@ -270,7 +270,6 @@ func classify*(x: float): FloatClass =
## Classifies a floating point value.
##
## Returns `x`'s class as specified by the `FloatClass enum<#FloatClass>`_.
## Doesn't work with `--passc:-ffast-math`.
runnableExamples:
doAssert classify(0.3) == fcNormal
doAssert classify(0.0) == fcZero
Expand All @@ -279,6 +278,7 @@ func classify*(x: float): FloatClass =
doAssert classify(5.0e-324) == fcSubnormal

# JavaScript and most C compilers have no classify:
if isNan(x): return fcNan
if x == 0.0:
if 1.0 / x == Inf:
return fcZero
Expand All @@ -287,7 +287,6 @@ func classify*(x: float): FloatClass =
if x * 0.5 == x:
if x > 0.0: return fcInf
else: return fcNegInf
if x != x: return fcNan
if abs(x) < MinFloatNormal:
return fcSubnormal
return fcNormal
Expand Down

0 comments on commit 38f9ee0

Please sign in to comment.