summaryrefslogtreecommitdiff
path: root/lib/math/test/trunc-impl.myr
blob: 328b8ddc387e308a5bfcf5ba7f80df2f35ae76b2 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use std
use math
use testr

const main = {
	math.fptrap(false)
	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],
	][:])
}

const trunc01 = {c
	var flt32s : (flt32, flt32)[:] = [
		(123.4, 123.0),
		(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),
		(-126.999, -127.0),
		(-127.999, -128.0),
		(-128.999, -129.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)
	;;
}