mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 15:04:59 +00:00
saves/loads float Inf, NaN and NegInf literals
This commit is contained in:
@@ -293,9 +293,23 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode =
|
||||
inc n
|
||||
of nkFloatLit .. nkFloat128Lit:
|
||||
c.withNode n, result, kind:
|
||||
expect n, FloatLit
|
||||
result.floatVal = pool.floats[n.floatId]
|
||||
inc n
|
||||
if n.kind == FloatLit:
|
||||
result.floatVal = pool.floats[n.floatId]
|
||||
inc n
|
||||
elif n.kind == ParLe:
|
||||
case pool.tags[n.tagId]
|
||||
of "inf":
|
||||
result.floatVal = Inf
|
||||
of "nan":
|
||||
result.floatVal = NaN
|
||||
of "neginf":
|
||||
result.floatVal = NegInf
|
||||
else:
|
||||
assert false, "expected float literal but got " & pool.tags[n.tagId]
|
||||
inc n
|
||||
skipParRi n
|
||||
else:
|
||||
assert false, "expected float literal but got " & $n.kind
|
||||
of nkStrLit .. nkTripleStrLit:
|
||||
c.withNode n, result, kind:
|
||||
expect n, StringLit
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import std/assertions
|
||||
import std/[assertions, math]
|
||||
import "../../compiler/icnif" / [nifencoder, nifdecoder]
|
||||
import "../../compiler" / [idents, ast, astalgo, options, pathutils, modulegraphs, modules, msgs, pipelines, syntaxes, sem, llstream, lineinfos]
|
||||
|
||||
@@ -294,8 +294,25 @@ proc eql(x, y: PNode; c: var EqlContext): bool =
|
||||
debug(y.sym)
|
||||
debug(x.sym.typ)
|
||||
debug(y.sym.typ)
|
||||
of nkCharLit .. nkTripleStrLit:
|
||||
of nkCharLit .. nkUInt64Lit, nkStrLit .. nkTripleStrLit:
|
||||
result = sameValue(x, y)
|
||||
of nkFloatLit .. nkFloat128Lit:
|
||||
# want to know if x and y are identical float value.
|
||||
# so x == y doesn't work if both x and y are NaN or x == 0 and y == -0.
|
||||
let xc = classify(x.floatVal)
|
||||
let yc = classify(y.floatVal)
|
||||
if xc == yc:
|
||||
if xc in {fcNormal, fcSubnormal}:
|
||||
if x.floatVal != y.floatVal:
|
||||
echo "float literal mismatch: ", x.floatVal, "/", y.floatVal
|
||||
result = false
|
||||
else:
|
||||
result = true
|
||||
else:
|
||||
result = true
|
||||
else:
|
||||
echo "float literal mismatch: ", xc, "/", yc
|
||||
result = false
|
||||
else:
|
||||
result = true
|
||||
for i in 0 ..< x.safeLen:
|
||||
|
||||
@@ -23,7 +23,14 @@ var uint32litH = 4294967295'u32
|
||||
var uint64litH = 18446744073709551615'u64
|
||||
|
||||
var floatlit = 1.25
|
||||
var floatlit2 = -1.25
|
||||
var float32lit = 1.25'f32
|
||||
var float64lit = 1.25'f64
|
||||
var floatZero = 0.0
|
||||
# Needs newer Nimony to save `-0.0` to NIF correclty
|
||||
#var floatNegZero = -0.0
|
||||
var floatInf = Inf
|
||||
var floatNaN = NaN
|
||||
var floatNegInf = NegInf
|
||||
|
||||
var nillit: ptr int = nil
|
||||
|
||||
Reference in New Issue
Block a user