added when statement (#6759)
This commit is contained in:
parent
001298eb22
commit
a11be5f21f
1 changed files with 32 additions and 29 deletions
|
|
@ -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