Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
fccdbb3238
2 changed files with 34 additions and 32 deletions
|
|
@ -1984,7 +1984,7 @@ proc formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
||||||
# but nothing else is possible:
|
# but nothing else is possible:
|
||||||
if buf[i] in {'.', ','}: result[i] = decimalsep
|
if buf[i] in {'.', ','}: result[i] = decimalsep
|
||||||
else: result[i] = buf[i]
|
else: result[i] = buf[i]
|
||||||
when defined(vcc):
|
when defined(windows):
|
||||||
# VS pre 2015 violates the C standard: "The exponent always contains at
|
# VS pre 2015 violates the C standard: "The exponent always contains at
|
||||||
# least two digits, and only as many more digits as necessary to
|
# least two digits, and only as many more digits as necessary to
|
||||||
# represent the exponent." [C11 §7.21.6.1]
|
# represent the exponent." [C11 §7.21.6.1]
|
||||||
|
|
@ -2478,8 +2478,7 @@ when isMainModule:
|
||||||
doAssert formatBiggestFloat(0.00000000001, ffScientific, 1, ',') in
|
doAssert formatBiggestFloat(0.00000000001, ffScientific, 1, ',') in
|
||||||
["1,0e-11", "1,0e-011"]
|
["1,0e-11", "1,0e-011"]
|
||||||
# bug #6589
|
# bug #6589
|
||||||
doAssert formatFloat(123.456, ffScientific, precision = -1) in
|
doAssert formatFloat(123.456, ffScientific, precision = -1) == "1.234560e+02"
|
||||||
["1.234560e+02", "1.234560e+002"]
|
|
||||||
|
|
||||||
doAssert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"
|
doAssert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"
|
||||||
doAssert "${1}12 ${-1}$2" % ["a", "b"] == "a12 bb"
|
doAssert "${1}12 ${-1}$2" % ["a", "b"] == "a12 bb"
|
||||||
|
|
|
||||||
|
|
@ -322,37 +322,40 @@ proc nimIntToStr(x: int): string {.compilerRtl.} =
|
||||||
result.add x
|
result.add x
|
||||||
|
|
||||||
proc add*(result: var string; x: float) =
|
proc add*(result: var string; x: float) =
|
||||||
var buf: array[0..64, char]
|
when nimvm:
|
||||||
when defined(nimNoArrayToCstringConversion):
|
result.add $x
|
||||||
var n: int = c_sprintf(addr buf, "%.16g", x)
|
|
||||||
else:
|
else:
|
||||||
var n: int = c_sprintf(buf, "%.16g", x)
|
var buf: array[0..64, char]
|
||||||
var hasDot = false
|
when defined(nimNoArrayToCstringConversion):
|
||||||
for i in 0..n-1:
|
var n: int = c_sprintf(addr buf, "%.16g", x)
|
||||||
if buf[i] == ',':
|
|
||||||
buf[i] = '.'
|
|
||||||
hasDot = true
|
|
||||||
elif buf[i] in {'a'..'z', 'A'..'Z', '.'}:
|
|
||||||
hasDot = true
|
|
||||||
if not hasDot:
|
|
||||||
buf[n] = '.'
|
|
||||||
buf[n+1] = '0'
|
|
||||||
buf[n+2] = '\0'
|
|
||||||
# On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN'
|
|
||||||
# of '-1.#IND' are produced.
|
|
||||||
# We want to get rid of these here:
|
|
||||||
if buf[n-1] in {'n', 'N', 'D', 'd'}:
|
|
||||||
result.add "nan"
|
|
||||||
elif buf[n-1] == 'F':
|
|
||||||
if buf[0] == '-':
|
|
||||||
result.add "-inf"
|
|
||||||
else:
|
else:
|
||||||
result.add "inf"
|
var n: int = c_sprintf(buf, "%.16g", x)
|
||||||
else:
|
var hasDot = false
|
||||||
var i = 0
|
for i in 0..n-1:
|
||||||
while buf[i] != '\0':
|
if buf[i] == ',':
|
||||||
result.add buf[i]
|
buf[i] = '.'
|
||||||
inc i
|
hasDot = true
|
||||||
|
elif buf[i] in {'a'..'z', 'A'..'Z', '.'}:
|
||||||
|
hasDot = true
|
||||||
|
if not hasDot:
|
||||||
|
buf[n] = '.'
|
||||||
|
buf[n+1] = '0'
|
||||||
|
buf[n+2] = '\0'
|
||||||
|
# On Windows nice numbers like '1.#INF', '-1.#INF' or '1.#NAN'
|
||||||
|
# of '-1.#IND' are produced.
|
||||||
|
# We want to get rid of these here:
|
||||||
|
if buf[n-1] in {'n', 'N', 'D', 'd'}:
|
||||||
|
result.add "nan"
|
||||||
|
elif buf[n-1] == 'F':
|
||||||
|
if buf[0] == '-':
|
||||||
|
result.add "-inf"
|
||||||
|
else:
|
||||||
|
result.add "inf"
|
||||||
|
else:
|
||||||
|
var i = 0
|
||||||
|
while buf[i] != '\0':
|
||||||
|
result.add buf[i]
|
||||||
|
inc i
|
||||||
|
|
||||||
proc nimFloatToStr(f: float): string {.compilerproc.} =
|
proc nimFloatToStr(f: float): string {.compilerproc.} =
|
||||||
result = newStringOfCap(8)
|
result = newStringOfCap(8)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue