* 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>
This commit is contained in:
flywind 2021-01-05 10:47:10 -06:00 • committed by GitHub
commit df9e74b510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 7 deletions

View file

@ -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.}