| 1 | const builtin = @import("builtin"); |
| 2 | const std = @import("std"); |
| 3 | const math = std.math; |
| 4 | const mem = std.mem; |
| 5 | const testing = std.testing; |
| 6 | |
| 7 | const qnan_u16: u16 = 0x7E00; |
| 8 | const snan_u16: u16 = 0x7D00; |
| 9 | const qnan_u32: u32 = 0x7FC00000; |
| 10 | const snan_u32: u32 = 0x7FA00000; |
| 11 | const qnan_u64: u64 = 0x7FF8000000000000; |
| 12 | const snan_u64: u64 = 0x7FF4000000000000; |
| 13 | const qnan_u128: u128 = 0x7FFF8000000000000000000000000000; |
| 14 | const snan_u128: u128 = 0x7FFF4000000000000000000000000000; |
| 15 | const qnan_f16: f16 = math.nan(f16); |
| 16 | const snan_f16: f16 = math.snan(f16); |
| 17 | const qnan_f32: f32 = math.nan(f32); |
| 18 | const snan_f32: f32 = math.snan(f32); |
| 19 | const qnan_f64: f64 = math.nan(f64); |
| 20 | const snan_f64: f64 = math.snan(f64); |
| 21 | const qnan_f128: f128 = math.nan(f128); |
| 22 | const snan_f128: f128 = math.snan(f128); |
| 23 | |
| 24 | test "nan memory equality" { |
| 25 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 26 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 27 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 28 | |
| 29 | // signaled |
| 30 | try testing.expect(mem.eql(u8, mem.asBytes(&snan_u16), mem.asBytes(&snan_f16))); |
| 31 | try testing.expect(mem.eql(u8, mem.asBytes(&snan_u32), mem.asBytes(&snan_f32))); |
| 32 | try testing.expect(mem.eql(u8, mem.asBytes(&snan_u64), mem.asBytes(&snan_f64))); |
| 33 | try testing.expect(mem.eql(u8, mem.asBytes(&snan_u128), mem.asBytes(&snan_f128))); |
| 34 | |
| 35 | // quiet |
| 36 | try testing.expect(mem.eql(u8, mem.asBytes(&qnan_u16), mem.asBytes(&qnan_f16))); |
| 37 | try testing.expect(mem.eql(u8, mem.asBytes(&qnan_u32), mem.asBytes(&qnan_f32))); |
| 38 | try testing.expect(mem.eql(u8, mem.asBytes(&qnan_u64), mem.asBytes(&qnan_f64))); |
| 39 | try testing.expect(mem.eql(u8, mem.asBytes(&qnan_u128), mem.asBytes(&qnan_f128))); |
| 40 | } |