ref: 5e1154d69efc86f5fe3831b047e3531d9cfd3478
dir: /lib/math/test/fpmath-sum-impl.myr/
use std
use math
use testr
const main = {
testr.run([
[.name = "trunc-01", .fn = trunc01],
[.name = "trunc-02", .fn = trunc02],
[.name = "floor-01", .fn = floor01],
[.name = "floor-02", .fn = floor02],
[.name = "ceil-01", .fn = ceil01],
[.name = "ceil-02", .fn = ceil02],
[.name = "fast2sum-01", .fn = fast2sum01],
][:])
}
const trunc01 = {c
var flt32s : (flt32, flt32)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(1.0, 1.0),
(1.1, 1.0),
(0.9, 0.0),
(10664524000000000000.0, 10664524000000000000.0),
(-3.5, -3.0),
(101.999, 101.0),
(std.flt32nan(), std.flt32nan()),
][:]
for (f, g) : flt32s
testr.eq(c, math.trunc(f), g)
;;
}
const trunc02 = {c
var flt64s : (flt64, flt64)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(1.0, 1.0),
(1.1, 1.0),
(0.9, 0.0),
(13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0, 13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0),
(-3.5, -3.0),
(101.999, 101.0),
(std.flt64nan(), std.flt64nan()),
][:]
for (f, g) : flt64s
testr.eq(c, math.trunc(f), g)
;;
}
const floor01 = {c
var flt32s : (flt32, flt32)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(0.5, 0.0),
(1.1, 1.0),
(10664524000000000000.0, 10664524000000000000.0),
(-3.5, -4.0),
(-101.999, -102.0),
(std.flt32nan(), std.flt32nan()),
][:]
for (f, g) : flt32s
testr.eq(c, math.floor(f), g)
;;
}
const floor02 = {c
var flt64s : (flt64, flt64)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(0.5, 0.0),
(1.1, 1.0),
(13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0, 13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0),
(-3.5, -4.0),
(-101.999, -102.0),
(std.flt64nan(), std.flt64nan()),
][:]
for (f, g) : flt64s
testr.eq(c, math.floor(f), g)
;;
}
const ceil01 = {c
var flt32s : (flt32, flt32)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(0.5, 1.0),
(-0.1, -0.0),
(1.1, 2.0),
(10664524000000000000.0, 10664524000000000000.0),
(-3.5, -3.0),
(-101.999, -101.0),
(std.flt32nan(), std.flt32nan()),
][:]
for (f, g) : flt32s
testr.eq(c, math.ceil(f), g)
;;
}
const ceil02 = {c
var flt64s : (flt64, flt64)[:] = [
(0.0, 0.0),
(-0.0, -0.0),
(0.5, 1.0),
(-0.1, -0.0),
(1.1, 2.0),
(13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0, 13809453812721350000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0),
(-3.5, -3.0),
(-101.999, -101.0),
(std.flt64nan(), std.flt64nan()),
][:]
for (f, g) : flt64s
testr.eq(c, math.ceil(f), g)
;;
}
const fast2sum01 = {c
var flt32s : (flt32, flt32, flt32, flt32)[:] = [
(1.0, 1.0, 2.0, 0.0),
(10664524000000000000.0, 1.11842, 10664524000000000000.0, 1.11842),
(1.11843, 10664524000000000000.0, 10664524000000000000.0, 1.11843),
(-21897.1324, 17323.22, -4573.912, 0.0),
][:]
for (a, b, s1, t1) : flt32s
var s2, t2
(s2, t2) = math.fast2sum(a, b)
testr.eq(c, s1, s2)
testr.eq(c, t1, t2)
;;
var flt64s : (flt64, flt64, flt64, flt64)[:] = [
(1.0, 1.0, 2.0, 0.0),
(-21897.1324, 17323.22, -4573.912399999997, 0.0),
(std.flt64frombits(0x78591b0672a81284), std.flt64frombits(0x6a8c3190e27a1884),
std.flt64frombits(0x78591b0672a81284), std.flt64frombits(0x6a8c3190e27a1884)),
(std.flt64frombits(0x6a8c3190e27a1884), std.flt64frombits(0x78591b0672a81284),
std.flt64frombits(0x78591b0672a81284), std.flt64frombits(0x6a8c3190e27a1884)),
(std.flt64frombits(0x78591b0672a81284), std.flt64frombits(0x7858273672ca19a0),
std.flt64frombits(0x7868a11e72b91612), 0.0),
][:]
for (a, b, s1, t1) : flt64s
var s2, t2
(s2, t2) = math.fast2sum(a, b)
testr.eq(c, s1, s2)
testr.eq(c, std.flt64bits(t1), std.flt64bits(t2))
;;
}