fix #16815 round(x,places) works again in vm (#16825)

* fix #16815 round+places works again in vm

* improve tests; fix for linux 32bit

* fix test for windows
This commit is contained in:
Timothee Cour 2021-01-28 01:40:18 -08:00 • committed by GitHub
commit b0f38a63c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 29 deletions

View file

@ -52,6 +52,7 @@ template md5op(op) {.dirty.} =
template wrap1f_math(op) {.dirty.} =
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
doAssert a.numArgs == 1
setResult(a, op(getFloat(a, 0)))
mathop op
@ -157,7 +158,6 @@ proc registerAdditionalOps*(c: PCtx) =
wrap1f_math(log10)
wrap1f_math(log2)
wrap1f_math(exp)
wrap1f_math(round)
wrap1f_math(arccos)
wrap1f_math(arcsin)
wrap1f_math(arctan)
@ -180,6 +180,13 @@ proc registerAdditionalOps*(c: PCtx) =
when declared(signbit):
wrap1f_math(signbit)
registerCallback c, "stdlib.math.round", proc (a: VmArgs) {.nimcall.} =
let n = a.numArgs
case n
of 1: setResult(a, round(getFloat(a, 0)))
of 2: setResult(a, round(getFloat(a, 0), getInt(a, 1).int))
else: doAssert false, $n
wrap1s(getMD5, md5op)
proc `mod Wrapper`(a: VmArgs) {.nimcall.} =