| author | |
| committer | |
| log | 27b02413dc3dacc7d784fe84ff8ba6cb0361842d |
| tree | a48f969278184b262aaae0005583bc182bea45b6 |
| parent | 61df5bc142253b0d33b77bceecfaef4c767e7feb |
refs #11225 files changed, 15 insertions(+), 1 deletions(-)
std/math/index.zig+3| ... | ... | @@ -25,6 +25,9 @@ pub const f16_max = 65504; |
| 25 | 25 | pub const f16_epsilon = 0.0009765625; // 2**-10 |
| 26 | 26 | pub const f16_toint = 1.0 / f16_epsilon; |
| 27 | 27 | |
| 28 | pub const nan_u16 = u16(0x7C01); | |
| 29 | pub const nan_f16 = @bitCast(f16, nan_u16); | |
| 30 | ||
| 28 | 31 | pub const nan_u32 = u32(0x7F800001); |
| 29 | 32 | pub const nan_f32 = @bitCast(f32, nan_u32); |
| 30 | 33 |
std/math/isnan.zig+6| ... | ... | @@ -5,6 +5,10 @@ const assert = std.debug.assert; |
| 5 | 5 | pub fn isNan(x: var) bool { |
| 6 | 6 | const T = @typeOf(x); |
| 7 | 7 | switch (T) { |
| 8 | f16 => { | |
| 9 | const bits = @bitCast(u16, x); | |
| 10 | return (bits & 0x7fff) > 0x7c00; | |
| 11 | }, | |
| 8 | 12 | f32 => { |
| 9 | 13 | const bits = @bitCast(u32, x); |
| 10 | 14 | return bits & 0x7FFFFFFF > 0x7F800000; |
| ... | ... | @@ -26,8 +30,10 @@ pub fn isSignalNan(x: var) bool { |
| 26 | 30 | } |
| 27 | 31 | |
| 28 | 32 | test "math.isNan" { |
| 33 | assert(isNan(math.nan(f16))); | |
| 29 | 34 | assert(isNan(math.nan(f32))); |
| 30 | 35 | assert(isNan(math.nan(f64))); |
| 36 | assert(!isNan(f16(1.0))); | |
| 31 | 37 | assert(!isNan(f32(1.0))); |
| 32 | 38 | assert(!isNan(f64(1.0))); |
| 33 | 39 | } |
std/math/nan.zig+2| ... | ... | @@ -2,6 +2,7 @@ const math = @import("index.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn nan(comptime T: type) T { |
| 4 | 4 | return switch (T) { |
| 5 | f16 => @bitCast(f16, math.nan_u16), | |
| 5 | 6 | f32 => @bitCast(f32, math.nan_u32), |
| 6 | 7 | f64 => @bitCast(f64, math.nan_u64), |
| 7 | 8 | else => @compileError("nan not implemented for " ++ @typeName(T)), |
| ... | ... | @@ -12,6 +13,7 @@ pub fn nan(comptime T: type) T { |
| 12 | 13 | // representation in the future when required. |
| 13 | 14 | pub fn snan(comptime T: type) T { |
| 14 | 15 | return switch (T) { |
| 16 | f16 => @bitCast(f16, math.nan_u16), | |
| 15 | 17 | f32 => @bitCast(f32, math.nan_u32), |
| 16 | 18 | f64 => @bitCast(f64, math.nan_u64), |
| 17 | 19 | else => @compileError("snan not implemented for " ++ @typeName(T)), |
std/special/builtin.zig+3-1| ... | ... | @@ -210,7 +210,9 @@ fn generic_fmod(comptime T: type, x: T, y: T) T { |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | fn isNan(comptime T: type, bits: T) bool { |
| 213 | if (T == u32) { | |
| 213 | if (T == u16) { | |
| 214 | return (bits & 0x7fff) > 0x7c00; | |
| 215 | } else if (T == u32) { | |
| 214 | 216 | return (bits & 0x7fffffff) > 0x7f800000; |
| 215 | 217 | } else if (T == u64) { |
| 216 | 218 | return (bits & (@maxValue(u64) >> 1)) > (u64(0x7ff) << 52); |
std/special/compiler_rt/extendXfYf2_test.zig+1| ... | ... | @@ -88,6 +88,7 @@ test "extenddftf2" { |
| 88 | 88 | test "extendhfsf2" { |
| 89 | 89 | test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN |
| 90 | 90 | test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN |
| 91 | test__extendhfsf2(0x7c01, 0x7f802000); // sNaN | |
| 91 | 92 | |
| 92 | 93 | test__extendhfsf2(0, 0); // 0 |
| 93 | 94 | test__extendhfsf2(0x8000, 0x80000000); // -0 |