authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2017-06-21 18:21:11+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2017-06-21 18:21:11+12:00
log14a324a0fa8d60dbf7d6948a992a09d8a65cbdc4
tree2ddb5dd971975ed0726e7946f92426f6d5d7b171
parentdfa2d11167db31e3b490c7d37633871fef4f2d52

Fixes for release mode tests


7 files changed, 27 insertions(+), 16 deletions(-)

std/math/exp.zig+8-1
......@@ -31,6 +31,10 @@ fn exp32(x_: f32) -> f32 {
3131 const sign = i32(hx >> 31);
3232 hx &= 0x7FFFFFFF;
3333
34 if (math.isNan(x)) {
35 return x;
36 }
37
3438 // |x| >= -87.33655 or nan
3539 if (hx >= 0x42AEAC50) {
3640 // nan
......@@ -108,6 +112,10 @@ fn exp64(x_: f64) -> f64 {
108112 const sign = i32(hx >> 31);
109113 hx &= 0x7FFFFFFF;
110114
115 if (math.isNan(x)) {
116 return x;
117 }
118
111119 // |x| >= 708.39 or nan
112120 if (hx >= 0x4086232B) {
113121 // nan
......@@ -204,7 +212,6 @@ test "math.exp32.special" {
204212}
205213
206214test "math.exp64.special" {
207 // TODO: Error on release (like pow)
208215 assert(math.isPositiveInf(exp64(math.inf(f64))));
209216 assert(math.isNan(exp64(math.nan(f64))));
210217}
std/math/expm1.zig+1-1
......@@ -258,7 +258,7 @@ fn expm1_64(x_: f64) -> f64 {
258258 if (k < 0 or k > 56) {
259259 var y = x - e + 1.0;
260260 if (k == 1024) {
261 y = y * 2.0; // TODO: * 0x1.0p1023;
261 y = y * 2.0 * 0x1.0p1022 * 10;
262262 } else {
263263 y = y * twopk;
264264 }
std/math/frexp.zig+1-2
......@@ -77,8 +77,8 @@ fn frexp64(x: f64) -> frexp64_result {
7777 }
7878 return result;
7979 } else if (e == 0x7FF) {
80 // frexp(nan) = (nan, 0)
8180 result.significand = x;
81 result.exponent = 0;
8282 return result;
8383 }
8484
......@@ -141,7 +141,6 @@ test "math.frexp32.special" {
141141}
142142
143143test "math.frexp64.special" {
144 // TODO: Error on release mode (like pow)
145144 var r: frexp64_result = undefined;
146145
147146 r = frexp64(0.0);
std/math/pow.zig-1
......@@ -179,7 +179,6 @@ fn isOddInteger(x: f64) -> bool {
179179test "math.pow" {
180180 const epsilon = 0.000001;
181181
182 // TODO: Error on release
183182 assert(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon));
184183 assert(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon));
185184 assert(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon));
std/math/scalbn.zig+2-3
......@@ -48,11 +48,10 @@ fn scalbn64(x: f64, n_: i32) -> f64 {
4848 var n = n_;
4949
5050 if (n > 1023) {
51 // TODO: Determine how to do the following.
52 // y *= 0x1.0p1023;
51 y *= 0x1.0p1022 * 10.0;
5352 n -= 1023;
5453 if (n > 1023) {
55 // y *= 0x1.0p1023;
54 y *= 0x1.0p1022 * 10.0;
5655 n -= 1023;
5756 if (n > 1023) {
5857 n = 1023;
std/math/sinh.zig+8-1
......@@ -28,6 +28,10 @@ fn sinh32(x: f32) -> f32 {
2828 const ux = u & 0x7FFFFFFF;
2929 const ax = @bitCast(f32, ux);
3030
31 if (x == 0.0 or math.isNan(x)) {
32 return x;
33 }
34
3135 var h: f32 = 0.5;
3236 if (u >> 31 != 0) {
3337 h = -h;
......@@ -57,6 +61,10 @@ fn sinh64(x: f64) -> f64 {
5761 const w = u32(u >> 32);
5862 const ax = @bitCast(f64, u & (@maxValue(u64) >> 1));
5963
64 if (x == 0.0 or math.isNan(x)) {
65 return x;
66 }
67
6068 var h: f32 = 0.5;
6169 if (u >> 63 != 0) {
6270 h = -h;
......@@ -112,7 +120,6 @@ test "math.sinh32.special" {
112120}
113121
114122test "math.sinh64.special" {
115 // TODO: Error on release mode (like pow)
116123 assert(sinh64(0.0) == 0.0);
117124 assert(sinh64(-0.0) == -0.0);
118125 assert(math.isPositiveInf(sinh64(math.inf(f64))));
std/math/tanh.zig+7-7
......@@ -30,11 +30,15 @@ fn tanh32(x: f32) -> f32 {
3030
3131 var t: f32 = undefined;
3232
33 if (x == 0.0 or math.isNan(x)) {
34 return x;
35 }
36
3337 // |x| < log(3) / 2 ~= 0.5493 or nan
3438 if (ux > 0x3F0C9F54) {
3539 // |x| > 10
3640 if (ux > 0x41200000) {
37 t = 1.0 + 0 / x;
41 t = 1.0;
3842 } else {
3943 t = math.expm1(2 * x);
4044 t = 1 - 2 / (t + 2);
......@@ -71,10 +75,7 @@ fn tanh64(x: f64) -> f64 {
7175 var t: f64 = undefined;
7276
7377 // TODO: Shouldn't need these checks.
74 if (x == 0.0) {
75 return x;
76 }
77 if (math.isNan(x)) {
78 if (x == 0.0 or math.isNan(x)) {
7879 return x;
7980 }
8081
......@@ -82,7 +83,7 @@ fn tanh64(x: f64) -> f64 {
8283 if (w > 0x3FE193EA) {
8384 // |x| > 20 or nan
8485 if (w > 0x40340000) {
85 t = 1.0; // TODO + 0 / x;
86 t = 1.0;
8687 } else {
8788 t = math.expm1(2 * x);
8889 t = 1 - 2 / (t + 2);
......@@ -137,7 +138,6 @@ test "math.tanh64" {
137138}
138139
139140test "math.tanh32.special" {
140 // TODO: Error on release (like pow)
141141 assert(tanh32(0.0) == 0.0);
142142 assert(tanh32(-0.0) == -0.0);
143143 assert(tanh32(math.inf(f32)) == 1.0);