* fix #16815 round+places works again in vm * improve tests; fix for linux 32bit * fix test for windows
This commit is contained in:
parent
37a98c6c58
commit
b0f38a63c4
3 changed files with 41 additions and 29 deletions
|
|
@ -168,14 +168,6 @@ block:
|
|||
let x: seq[float] = @[]
|
||||
doAssert prod(x) == 1.0
|
||||
|
||||
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
|
||||
|
||||
block: # splitDecimal() tests
|
||||
doAssert splitDecimal(54.674).intpart == 54.0
|
||||
doAssert splitDecimal(54.674).floatpart ==~ 0.674
|
||||
|
|
@ -372,26 +364,36 @@ template main =
|
|||
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
|
||||
block: # 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
|
||||
block: # func round*[T: float32|float64](x: T, places: int): T
|
||||
doAssert round(54.345, 0) == 54.0
|
||||
template fn(x) =
|
||||
doAssert round(x, 2).almostEqual 54.35
|
||||
doAssert round(x, 2).almostEqual 54.35
|
||||
doAssert round(x, -1).almostEqual 50.0
|
||||
doAssert round(x, -2).almostEqual 100.0
|
||||
doAssert round(x, -3).almostEqual 0.0
|
||||
fn(54.346)
|
||||
fn(54.346'f32)
|
||||
|
||||
when nimvm:
|
||||
discard
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue