summaryrefslogtreecommitdiff
path: root/lib/math/test/powr-impl.myr
blob: b3fa0b8f0bcfb30c9131d412c43badeb1ac1ea18 (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
use std
use math
use testr

const main = {
	math.fptrap(false)
	testr.run([
		[.name="powr-01", .fn = powr01],
		[.name="powr-02", .fn = powr02],
		[.name="powr-03", .fn = powr03],
	][:])
}

const powr01 = {c
	var inputs : (uint32, uint32, uint32)[:] = [
		(0x08a38749, 0x2ffb67c0, 0x3f7fffff),
		(0x01433ed5, 0x367caeda, 0x3f7feaba),
		(0x7112fd5b, 0x7509b252, 0x7f800000),
		(0x22b5f461, 0xc7335035, 0x7f800000),
		(0x29529847, 0x43c6b361, 0x00000000),
		(0x3fc1cc03, 0x64eb4c95, 0x7f800000),
		(0x653f944a, 0xbf7c2388, 0x1a3c784b),
		(0x545ba67c, 0xc0c7e947, 0x00000000),
		(0x3fca6b0d, 0x44ff18e0, 0x7f800000),
	][:]

	for (x, y, z) : inputs
		var xf : flt32 = std.flt32frombits(x)
		var yf : flt32 = std.flt32frombits(y)
		var zf : flt32 = std.flt32frombits(z)
		var rf = math.powr(xf, yf)
		testr.check(c, rf == zf,
			"powr(0x{b=16,w=8,p=0}, 0x{b=16,w=8,p=0}) should be 0x{b=16,w=8,p=0}, was 0x{b=16,w=8,p=0}",
			x, y, z, std.flt32bits(rf))
	;;
}

const powr02 = {c
	var inputs : (uint64, uint64, uint64)[:] = [
		(0x0000000000000000, 0x0000000000000000, 0x0000000000000000),
		(0x0d30ad40d8223045, 0xffb56d6e33cd6ad2, 0x7ff0000000000000),
		(0x1f192b55704d3500, 0xff8a52f877359f3c, 0x7ff0000000000000),
		(0x7fe6c53d8cef3d27, 0x4bcca2e651c57788, 0x7ff0000000000000),
		(0x7fe78a3740493383, 0xe84e801c38a71fc9, 0x0000000000000000),
		(0x7fea162ffbabd3bc, 0x02414c7fa33dd7db, 0x3ff0000000000000),
		(0x7fe087a9112a21d8, 0x0f2b7a9584736b41, 0x3ff0000000000000),
		(0x7fe5d78f049c0918, 0xd3a145ba5b0fdb9b, 0x0000000000000000),
		(0x7febb342860b3386, 0xe758bd2af063aec2, 0x0000000000000000),

		(0x000342cdeeb18fc9, 0xbe645d513ed4670d, 0x3ff0001c3d5eaa62),
	][:]

	for (x, y, z) : inputs
		var xf : flt64 = std.flt64frombits(x)
		var yf : flt64 = std.flt64frombits(y)
		var zf : flt64 = std.flt64frombits(z)
		var rf = math.powr(xf, yf)
		testr.check(c, rf == zf,
			"powr(0x{b=16,w=16,p=0}, 0x{b=16,w=16,p=0}) should be 0x{b=16,w=16,p=0}, was 0x{b=16,w=16,p=0}",
			x, y, z, std.flt64bits(rf))
	;;
}

const powr03 = {c
	var inputs : (uint32, uint32, uint32, uint32)[:] = [
		(0x1bd2244e, 0x3a647973, 0x3f7535a1, 0x3f7535a0),
		(0x3f264a46, 0x423c927a, 0x30c9b8d3, 0x30c9b8d4),
		(0x61fb73d0, 0xbfd2666c, 0x06c539f6, 0x06c539f5),
		(0x3bbd11f6, 0x3cc159b1, 0x3f62ac1b, 0x3f62ac1a),
		(0x3f7ca5b7, 0xc309857a, 0x40c41bbf, 0x40c41bc0),
		(0x3f6a1a65, 0x43e16065, 0x226731e2, 0x226731e3),
	][:]

	for (x, y, z_perfect, z_accepted) : inputs
		var xf : flt32 = std.flt32frombits(x)
		var yf : flt32 = std.flt32frombits(y)
		var zf_perfect : flt32 = std.flt32frombits(z_perfect)
		var zf_accepted : flt32 = std.flt32frombits(z_accepted)
		var rf = math.powr(xf, yf)
		testr.check(c, rf == zf_perfect || rf == zf_accepted,
			"powr(0x{b=16,w=8,p=0}, 0x{b=16,w=8,p=0}) should be 0x{b=16,w=8,p=0}, will also accept 0x{b=16,w=8,p=0}, was 0x{b=16,w=8,p=0}",
			x, y, z_perfect, z_accepted, std.flt32bits(rf))
	;;
}