| ... | ... | @@ -4,28 +4,7 @@ const expect = std.testing.expect; |
| 4 | 4 | const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | pub fn isNan(x: var) bool { |
| 7 | | const T = @typeOf(x); |
| 8 | | switch (T) { |
| 9 | | f16 => { |
| 10 | | const bits = @bitCast(u16, x); |
| 11 | | return (bits & 0x7fff) > 0x7c00; |
| 12 | | }, |
| 13 | | f32 => { |
| 14 | | const bits = @bitCast(u32, x); |
| 15 | | return bits & 0x7FFFFFFF > 0x7F800000; |
| 16 | | }, |
| 17 | | f64 => { |
| 18 | | const bits = @bitCast(u64, x); |
| 19 | | return (bits & (maxInt(u64) >> 1)) > (u64(0x7FF) << 52); |
| 20 | | }, |
| 21 | | f128 => { |
| 22 | | const bits = @bitCast(u128, x); |
| 23 | | return (bits & (maxInt(u128) >> 1)) > (u128(0x7FFF) << 112); |
| 24 | | }, |
| 25 | | else => { |
| 26 | | @compileError("isNan not implemented for " ++ @typeName(T)); |
| 27 | | }, |
| 28 | | } |
| 7 | return x != x; |
| 29 | 8 | } |
| 30 | 9 | |
| 31 | 10 | /// Note: A signalling nan is identical to a standard nan right now but may have a different bit |