fixes #18134; registers formatBiggestFloat in vmops strformat supports float format in VM
This commit is contained in:
parent
23bd812b0c
commit
fc068ee06d
3 changed files with 73 additions and 61 deletions
|
|
@ -38,6 +38,8 @@ when defined(nimPreviewSlimSystem):
|
||||||
else:
|
else:
|
||||||
from std/formatfloat import addFloatRoundtrip, addFloatSprintf
|
from std/formatfloat import addFloatRoundtrip, addFloatSprintf
|
||||||
|
|
||||||
|
from std/strutils import formatBiggestFloat, FloatFormatMode
|
||||||
|
|
||||||
# There are some useful procs in vmconv.
|
# There are some useful procs in vmconv.
|
||||||
import vmconv, vmmarshal
|
import vmconv, vmmarshal
|
||||||
|
|
||||||
|
|
@ -374,6 +376,10 @@ proc registerAdditionalOps*(c: PCtx) =
|
||||||
let x = a.getFloat(1)
|
let x = a.getFloat(1)
|
||||||
addFloatSprintf(p.strVal, x)
|
addFloatSprintf(p.strVal, x)
|
||||||
|
|
||||||
|
registerCallback c, "stdlib.strutils.formatBiggestFloat", proc(a: VmArgs) =
|
||||||
|
setResult(a, formatBiggestFloat(a.getFloat(0), FloatFormatMode(a.getInt(1)),
|
||||||
|
a.getInt(2), chr(a.getInt(3))))
|
||||||
|
|
||||||
wrapIterator("stdlib.envvars.envPairsImplSeq"): envPairs()
|
wrapIterator("stdlib.envvars.envPairsImplSeq"): envPairs()
|
||||||
|
|
||||||
registerCallback c, "stdlib.marshal.toVM", proc(a: VmArgs) =
|
registerCallback c, "stdlib.marshal.toVM", proc(a: VmArgs) =
|
||||||
|
|
|
||||||
|
|
@ -2413,6 +2413,9 @@ func formatBiggestFloat*(f: BiggestFloat, format: FloatFormatMode = ffDefault,
|
||||||
doAssert x.formatBiggestFloat() == "123.4560000000000"
|
doAssert x.formatBiggestFloat() == "123.4560000000000"
|
||||||
doAssert x.formatBiggestFloat(ffDecimal, 4) == "123.4560"
|
doAssert x.formatBiggestFloat(ffDecimal, 4) == "123.4560"
|
||||||
doAssert x.formatBiggestFloat(ffScientific, 2) == "1.23e+02"
|
doAssert x.formatBiggestFloat(ffScientific, 2) == "1.23e+02"
|
||||||
|
when nimvm:
|
||||||
|
discard "implemented in the vmops"
|
||||||
|
else:
|
||||||
when defined(js):
|
when defined(js):
|
||||||
var precision = precision
|
var precision = precision
|
||||||
if precision == -1:
|
if precision == -1:
|
||||||
|
|
|
||||||
|
|
@ -475,8 +475,10 @@ proc main() =
|
||||||
|
|
||||||
# Note: times.format adheres to the format protocol. Test that this
|
# Note: times.format adheres to the format protocol. Test that this
|
||||||
# works:
|
# works:
|
||||||
|
when nimvm:
|
||||||
var dt = initDateTime(01, mJan, 2000, 00, 00, 00)
|
discard
|
||||||
|
else:
|
||||||
|
var dt = dateTime(2000, mJan, 01, 00, 00, 00)
|
||||||
check &"{dt:yyyy-MM-dd}", "2000-01-01"
|
check &"{dt:yyyy-MM-dd}", "2000-01-01"
|
||||||
|
|
||||||
var tm = fromUnix(0)
|
var tm = fromUnix(0)
|
||||||
|
|
@ -558,5 +560,6 @@ proc main() =
|
||||||
doAssert &"""{(if true: "'" & "'" & ')' else: "")}""" == "'')"
|
doAssert &"""{(if true: "'" & "'" & ')' else: "")}""" == "'')"
|
||||||
doAssert &"{(if true: \"\'\" & \"'\" & ')' else: \"\")}" == "'')"
|
doAssert &"{(if true: \"\'\" & \"'\" & ')' else: \"\")}" == "'')"
|
||||||
doAssert fmt"""{(if true: "'" & ')' else: "")}""" == "')"
|
doAssert fmt"""{(if true: "'" & ')' else: "")}""" == "')"
|
||||||
# xxx static: main()
|
|
||||||
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue