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) {...@@ -19,6 +19,8 @@ pub fn acosh(x: var) @typeOf(x) {
1919
20// acosh(x) = log(x + sqrt(x * x - 1))20// acosh(x) = log(x + sqrt(x * x - 1))
21fn acosh32(x: f32) f32 {21fn acosh32(x: f32) f32 {
22 @setFloatMode(this, builtin.FloatMode.Strict);
23
22 const u = @bitCast(u32, x);24 const u = @bitCast(u32, x);
23 const i = u & 0x7FFFFFFF;25 const i = u & 0x7FFFFFFF;
2426
...@@ -37,6 +39,8 @@ fn acosh32(x: f32) f32 {...@@ -37,6 +39,8 @@ fn acosh32(x: f32) f32 {
37}39}
3840
39fn acosh64(x: f64) f64 {41fn acosh64(x: f64) f64 {
42 @setFloatMode(this, builtin.FloatMode.Strict);
43
40 const u = @bitCast(u64, x);44 const u = @bitCast(u64, x);
41 const e = (u >> 52) & 0x7FF;45 const e = (u >> 52) & 0x7FF;
4246
std/math/isnan.zig+2-2
...@@ -19,8 +19,8 @@ pub fn isNan(x: var) bool {...@@ -19,8 +19,8 @@ pub fn isNan(x: var) bool {
19 }19 }
20}20}
2121
22// Note: A signalling nan is identical to a standard right now by may have a different bit22/// 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.23/// representation in the future when required.
24pub fn isSignalNan(x: var) bool {24pub fn isSignalNan(x: var) bool {
25 return isNan(x);25 return isNan(x);
26}26}
std/math/log1p.zig+5
...@@ -6,6 +6,7 @@...@@ -6,6 +6,7 @@
6// - log1p(x) = nan if x < -16// - log1p(x) = nan if x < -1
7// - log1p(nan) = nan7// - log1p(nan) = nan
88
9const builtin = @import("builtin");
9const std = @import("../index.zig");10const std = @import("../index.zig");
10const math = std.math;11const math = std.math;
11const assert = std.debug.assert;12const assert = std.debug.assert;
...@@ -20,6 +21,8 @@ pub fn log1p(x: var) @typeOf(x) {...@@ -20,6 +21,8 @@ pub fn log1p(x: var) @typeOf(x) {
20}21}
2122
22fn log1p_32(x: f32) f32 {23fn log1p_32(x: f32) f32 {
24 @setFloatMode(this, builtin.FloatMode.Strict);
25
23 const ln2_hi = 6.9313812256e-01;26 const ln2_hi = 6.9313812256e-01;
24 const ln2_lo = 9.0580006145e-06;27 const ln2_lo = 9.0580006145e-06;
25 const Lg1: f32 = 0xaaaaaa.0p-24;28 const Lg1: f32 = 0xaaaaaa.0p-24;
...@@ -96,6 +99,8 @@ fn log1p_32(x: f32) f32 {...@@ -96,6 +99,8 @@ fn log1p_32(x: f32) f32 {
96}99}
97100
98fn log1p_64(x: f64) f64 {101fn log1p_64(x: f64) f64 {
102 @setFloatMode(this, builtin.FloatMode.Strict);
103
99 const ln2_hi: f64 = 6.93147180369123816490e-01;104 const ln2_hi: f64 = 6.93147180369123816490e-01;
100 const ln2_lo: f64 = 1.90821492927058770002e-10;105 const ln2_lo: f64 = 1.90821492927058770002e-10;
101 const Lg1: f64 = 6.666666666666735130e-01;106 const Lg1: f64 = 6.666666666666735130e-01;
std/special/builtin.zig+2
...@@ -201,6 +201,8 @@ fn isNan(comptime T: type, bits: T) bool {...@@ -201,6 +201,8 @@ fn isNan(comptime T: type, bits: T) bool {
201// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are201// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are
202// potentially some edge cases remaining that are not handled in the same way.202// potentially some edge cases remaining that are not handled in the same way.
203export fn sqrt(x: f64) f64 {203export fn sqrt(x: f64) f64 {
204 @setFloatMode(this, builtin.FloatMode.Strict);
205
204 const tiny: f64 = 1.0e-300;206 const tiny: f64 = 1.0e-300;
205 const sign: u32 = 0x80000000;207 const sign: u32 = 0x80000000;
206 const u = @bitCast(u64, x);208 const u = @bitCast(u64, x);