Fixes codegen bug with literal negative zero, fixes #7079 (#7158)

* Fixes #7079

* Fix handling of neg zero during constant folding
This commit is contained in:
GULPF 2018-01-31 16:29:42 +01:00 • committed by Andreas Rumpf
commit 94038545be
4 changed files with 31 additions and 11 deletions

View file

@ -2284,11 +2284,17 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
r.kind = resExpr
of nkFloatLit..nkFloat64Lit:
let f = n.floatVal
if f != f: r.res = rope"NaN"
elif f == 0.0: r.res = rope"0.0"
elif f == 0.5 * f:
if f > 0.0: r.res = rope"Infinity"
else: r.res = rope"-Infinity"
case classify(f)
of fcNaN:
r.res = rope"NaN"
of fcNegZero:
r.res = rope"-0.0"
of fcZero:
r.res = rope"0.0"
of fcInf:
r.res = rope"Infinity"
of fcNegInf:
r.res = rope"-Infinity"
else: r.res = rope(f.toStrMaxPrecision)
r.kind = resExpr
of nkCallKinds: