* 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

@ -10,6 +10,10 @@ import std/[math, random, os]
import std/[unittest]
import std/[sets, tables]
# Function for approximate comparison of floats
proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
block: # random int
block: # there might be some randomness
var set = initHashSet[int](128)
@ -158,10 +162,6 @@ block:
doAssert(erf(6.0) > erf(5.0))
doAssert(erfc(6.0) < erfc(5.0))
proc `==~`(x, y: float): bool = (abs(x-y) < 1e-9)
# Function for approximate comparison of floats
# xxx use `almostEqual`
block: # prod
doAssert prod([1, 2, 3, 4]) == 24
doAssert prod([1.5, 3.4]).almostEqual 5.1
@ -349,6 +349,28 @@ template main =
doAssert copySign(-NaN, 0.0).isNaN
doAssert copySign(-NaN, -0.0).isNaN
block: # round() tests
# Round to 0 decimal places
doAssert round(54.652) == 55.0
doAssert round(54.352) == 54.0
doAssert round(-54.652) == -55.0
doAssert round(-54.352) == -54.0
doAssert round(0.0) == 0.0
doAssert 1 / round(0.0) == Inf
doAssert 1 / round(-0.0) == -Inf
doAssert round(Inf) == Inf
doAssert round(-Inf) == -Inf
doAssert round(NaN).isNaN
doAssert round(-NaN).isNaN
doAssert round(-0.5) == -1.0
doAssert round(0.5) == 1.0
doAssert round(-1.5) == -2.0
doAssert round(1.5) == 2.0
doAssert round(-2.5) == -3.0
doAssert round(2.5) == 3.0
doAssert round(2.5'f32) == 3.0'f32
doAssert round(2.5'f64) == 3.0'f64
when nimvm:
discard
else: