mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 18:07:59 +00:00
Make std/math classify work without --passc:-fast-math. (#23211)
By using the existing isNaN function we can make std/math's classify
function work even if `--passc:-fast-math` is used.
(cherry picked from commit 38f9ee0e58)
This commit is contained in:
committed by
narimiran
parent
5a2cd98867
commit
e33d96ad4e
@@ -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):
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user