summary refs log tree commit diff stats
path: root/compiler/vmops.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/vmops.nim')
-rw-r--r--compiler/vmops.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/vmops.nim b/compiler/vmops.nim
index 504a352b5..ec44a7c08 100644
--- a/compiler/vmops.nim
+++ b/compiler/vmops.nim
@@ -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.} =