From e33d96ad4ee5d496452a867826ac095cb0ebead4 Mon Sep 17 00:00:00 2001 From: Angel Ezquerra Date: Thu, 18 Jan 2024 21:59:16 +0100 Subject: [PATCH] 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 38f9ee0e5850ac9987fe612edcf48cddd1835091) --- lib/pure/math.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 4bc720a465..dc2d1100a2 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -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