fix negative nan (#16628)
This commit is contained in:
parent
5897ed9d3d
commit
be6e8916fa
3 changed files with 29 additions and 5 deletions
|
|
@ -8,7 +8,7 @@
|
|||
#
|
||||
|
||||
## Serialization utilities for the compiler.
|
||||
import strutils, math
|
||||
import std/[strutils, math]
|
||||
|
||||
# bcc on windows doesn't have C99 functions
|
||||
when defined(windows) and defined(bcc):
|
||||
|
|
@ -33,10 +33,19 @@ when defined(windows) and defined(bcc):
|
|||
|
||||
proc c_snprintf(s: cstring; n:uint; frmt: cstring): cint {.importc: "snprintf", header: "<stdio.h>", nodecl, varargs.}
|
||||
|
||||
|
||||
when not declared(signbit):
|
||||
proc c_signbit(x: SomeFloat): cint {.importc: "signbit", header: "<math.h>".}
|
||||
proc signbit*(x: SomeFloat): bool {.inline.} =
|
||||
result = c_signbit(x) != 0
|
||||
|
||||
proc toStrMaxPrecision*(f: BiggestFloat, literalPostfix = ""): string =
|
||||
case classify(f)
|
||||
of fcNan:
|
||||
result = "NAN"
|
||||
if signbit(f):
|
||||
result = "-NAN"
|
||||
else:
|
||||
result = "NAN"
|
||||
of fcNegZero:
|
||||
result = "-0.0" & literalPostfix
|
||||
of fcZero:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue