Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
5262b86001
3 changed files with 19 additions and 4 deletions
|
|
@ -78,8 +78,10 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
[p.module.tmpBase, rope(id)])
|
[p.module.tmpBase, rope(id)])
|
||||||
else:
|
else:
|
||||||
result = makeCString(n.strVal)
|
result = makeCString(n.strVal)
|
||||||
of nkFloatLit..nkFloat64Lit:
|
of nkFloatLit, nkFloat64Lit:
|
||||||
result = rope(n.floatVal.toStrMaxPrecision)
|
result = rope(n.floatVal.toStrMaxPrecision)
|
||||||
|
of nkFloat32Lit:
|
||||||
|
result = rope(n.floatVal.toStrMaxPrecision("f"))
|
||||||
else:
|
else:
|
||||||
internalError(n.info, "genLiteral(" & $n.kind & ')')
|
internalError(n.info, "genLiteral(" & $n.kind & ')')
|
||||||
result = nil
|
result = nil
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,17 @@ import strutils
|
||||||
|
|
||||||
proc c_sprintf(buf, frmt: cstring) {.importc: "sprintf", header: "<stdio.h>", nodecl, varargs.}
|
proc c_sprintf(buf, frmt: cstring) {.importc: "sprintf", header: "<stdio.h>", nodecl, varargs.}
|
||||||
|
|
||||||
proc toStrMaxPrecision*(f: BiggestFloat): string =
|
proc toStrMaxPrecision*(f: BiggestFloat, literalPostfix = ""): string =
|
||||||
if f != f:
|
if f != f:
|
||||||
result = "NAN"
|
result = "NAN"
|
||||||
elif f == 0.0:
|
elif f == 0.0:
|
||||||
result = "0.0"
|
result = "0.0" & literalPostfix
|
||||||
elif f == 0.5 * f:
|
elif f == 0.5 * f:
|
||||||
if f > 0.0: result = "INF"
|
if f > 0.0: result = "INF"
|
||||||
else: result = "-INF"
|
else: result = "-INF"
|
||||||
else:
|
else:
|
||||||
var buf: array[0..80, char]
|
var buf: array[0..80, char]
|
||||||
c_sprintf(buf, "%#.16e", f)
|
c_sprintf(buf, "%#.16e" & literalPostfix, f)
|
||||||
result = $buf
|
result = $buf
|
||||||
|
|
||||||
proc encodeStr*(s: string, result: var string) =
|
proc encodeStr*(s: string, result: var string) =
|
||||||
|
|
|
||||||
13
tests/float/tissue5821.nim
Normal file
13
tests/float/tissue5821.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
file: "tissue5821.nim"
|
||||||
|
output: ''''''
|
||||||
|
"""
|
||||||
|
proc main(): void =
|
||||||
|
let a: float32 = 47.11'f32
|
||||||
|
doAssert a == 47.11'f32
|
||||||
|
|
||||||
|
let b: float64 = 10.234402823e+38'f64
|
||||||
|
doAssert b != 10.123402823e+38'f64
|
||||||
|
doAssert b == 10.234402823e+38'f64
|
||||||
|
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue