summaryrefslogtreecommitdiff
path: root/lib/math/test/round-impl.myr
blob: ecfe9c7ddc8569657c528dfe973262f4b861ad7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std
use math
use testr

const main = {
	testr.run([
		[.name = "round-01",    .fn = round01],
		[.name = "round-02",    .fn = round02],
	][:])
}

const round01 = {c
	var inputs : (flt32, int32)[:] = [
		(123.4, 123),
		(0.0, 0),
		(-0.0, 0),
		(1.0, 1),
		(1.1, 1),
		(0.9, 1),
		(15.3, 15),
		(15.5, 16),
		(15.7, 16),
		(16.3, 16),
		(16.5, 16),
		(16.7, 17),
		(-102.1, -102),
		(-102.5, -102),
		(-102.7, -103),
		(-103.1, -103),
		(-103.5, -104),
		(-103.7, -104),
		(2147483641.5, -2147483648),
		(2147483646.5, -2147483648),
		(2147483647.5, -2147483648),
		(2147483649.0, -2147483648),
		(-2147483641.5, -2147483648),
		(-2147483646.5, -2147483648),
		(-2147483647.5, -2147483648),
		(-2147483649.0, -2147483648),
	][:]

	for (f, g) : inputs
		testr.eq(c, math.rn(f), g)
	;;
}

const round02 = {c
	var inputs : (flt64, int64)[:] = [
		(123.4, 123),
		(0.0, 0),
		(-0.0, 0),
		(1.0, 1),
		(1.1, 1),
		(0.9, 1),
		(15.3, 15),
		(15.5, 16),
		(15.7, 16),
		(16.3, 16),
		(16.5, 16),
		(16.7, 17),
		(-102.1, -102),
		(-102.5, -102),
		(-102.7, -103),
		(-103.1, -103),
		(-103.5, -104),
		(-103.7, -104),
		(2147483641.5, 2147483642),
		(2147483646.5, 2147483646),
		(2147483647.5, 2147483648),
		(2147483649.0, 2147483649),
		(-2147483641.5, -2147483642),
		(-2147483646.5, -2147483646),
		(-2147483647.5, -2147483648),
		(-2147483649.0, -2147483649),
		(9223372036854775806.1, -9223372036854775808),
		(-9223372036854775806.1, -9223372036854775808),
	][:]

	for (f, g) : inputs
		testr.eq(c, math.rn(f), g)
	;;
}