authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-26 14:57:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-26 14:57:53-04:00
log7fa97b752e167de6df9a8a76999456d2c199b345
treed05c10a10132d99d402d3912d626f84cedb27ceb
parent8efb3f5e197edf2debebf0557c74fef2541cc117

add strict float mode to some math functions

fixes a test failure for acosh32

4 files changed, 13 insertions(+), 2 deletions(-)

std/math/acosh.zig+4
......@@ -19,6 +19,8 @@ pub fn acosh(x: var) @typeOf(x) {
1919
2020// acosh(x) = log(x + sqrt(x * x - 1))
2121fn acosh32(x: f32) f32 {
22 @setFloatMode(this, builtin.FloatMode.Strict);
23
2224 const u = @bitCast(u32, x);
2325 const i = u & 0x7FFFFFFF;
2426
......@@ -37,6 +39,8 @@ fn acosh32(x: f32) f32 {
3739}
3840
3941fn acosh64(x: f64) f64 {
42 @setFloatMode(this, builtin.FloatMode.Strict);
43
4044 const u = @bitCast(u64, x);
4145 const e = (u >> 52) & 0x7FF;
4246
std/math/isnan.zig+2-2
......@@ -19,8 +19,8 @@ pub fn isNan(x: var) bool {
1919 }
2020}
2121
22// Note: A signalling nan is identical to a standard right now by may have a different bit
23// representation in the future when required.
22/// Note: A signalling nan is identical to a standard nan right now but may have a different bit
23/// representation in the future when required.
2424pub fn isSignalNan(x: var) bool {
2525 return isNan(x);
2626}
std/math/log1p.zig+5
......@@ -6,6 +6,7 @@
66// - log1p(x) = nan if x < -1
77// - log1p(nan) = nan
88
9const builtin = @import("builtin");
910const std = @import("../index.zig");
1011const math = std.math;
1112const assert = std.debug.assert;
......@@ -20,6 +21,8 @@ pub fn log1p(x: var) @typeOf(x) {
2021}
2122
2223fn log1p_32(x: f32) f32 {
24 @setFloatMode(this, builtin.FloatMode.Strict);
25
2326 const ln2_hi = 6.9313812256e-01;
2427 const ln2_lo = 9.0580006145e-06;
2528 const Lg1: f32 = 0xaaaaaa.0p-24;
......@@ -96,6 +99,8 @@ fn log1p_32(x: f32) f32 {
9699}
97100
98101fn log1p_64(x: f64) f64 {
102 @setFloatMode(this, builtin.FloatMode.Strict);
103
99104 const ln2_hi: f64 = 6.93147180369123816490e-01;
100105 const ln2_lo: f64 = 1.90821492927058770002e-10;
101106 const Lg1: f64 = 6.666666666666735130e-01;
std/special/builtin.zig+2
......@@ -201,6 +201,8 @@ fn isNan(comptime T: type, bits: T) bool {
201201// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are
202202// potentially some edge cases remaining that are not handled in the same way.
203203export fn sqrt(x: f64) f64 {
204 @setFloatMode(this, builtin.FloatMode.Strict);
205
204206 const tiny: f64 = 1.0e-300;
205207 const sign: u32 = 0x80000000;
206208 const u = @bitCast(u64, x);