diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2021-01-05 10:47:10 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 17:47:10 +0100 |
commit | df9e74b510a84b0050ffe022e77d42c6f949c2bc (patch) | |
tree | 19dc525cc74f6a63bb26f838a3050e36b7fc5cc7 /lib/pure | |
parent | b24d6d4b6a57a14aba0b22a9ea888a4adb19928c (diff) | |
download | Nim-df9e74b510a84b0050ffe022e77d42c6f949c2bc.tar.gz |
fix #9125 (#16582)
* fix #9125 * Update tests/stdlib/tmath.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * back Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/math.nim | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/pure/math.nim b/lib/pure/math.nim index 76052ec3b..a6a3676b9 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -847,7 +847,17 @@ else: # JS func floor*(x: float64): float64 {.importc: "Math.floor", nodecl.} func ceil*(x: float32): float32 {.importc: "Math.ceil", nodecl.} func ceil*(x: float64): float64 {.importc: "Math.ceil", nodecl.} - func round*(x: float): float {.importc: "Math.round", nodecl.} + + when (NimMajor, NimMinor) < (1, 5) or defined(nimLegacyJsRound): + func round*(x: float): float {.importc: "Math.round", nodecl.} + else: + func jsRound(x: float): float {.importc: "Math.round", nodecl.} + func round*[T: float64 | float32](x: T): T = + if x >= 0: result = jsRound(x) + else: + result = ceil(x) + if result - x >= T(0.5): + result -= T(1.0) func trunc*(x: float32): float32 {.importc: "Math.trunc", nodecl.} func trunc*(x: float64): float64 {.importc: "Math.trunc", nodecl.} |