mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
16b3d1004e
Follow up to #19079, which made test names fully qualified. This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit: "priority_queue.test.std.PriorityQueue: shrinkAndFree" and the same test's name after the changes in this commit: "priority_queue.test.shrinkAndFree"
41 lines
1.4 KiB
Zig
41 lines
1.4 KiB
Zig
const std = @import("../std.zig");
|
|
const builtin = @import("builtin");
|
|
const math = std.math;
|
|
const meta = std.meta;
|
|
const expect = std.testing.expect;
|
|
|
|
pub fn isNan(x: anytype) bool {
|
|
return x != x;
|
|
}
|
|
|
|
/// TODO: LLVM is known to miscompile on some architectures to quiet NaN -
|
|
/// this is tracked by https://github.com/ziglang/zig/issues/14366
|
|
pub fn isSignalNan(x: anytype) bool {
|
|
const T = @TypeOf(x);
|
|
const U = meta.Int(.unsigned, @bitSizeOf(T));
|
|
const quiet_signal_bit_mask = 1 << (math.floatFractionalBits(T) - 1);
|
|
return isNan(x) and (@as(U, @bitCast(x)) & quiet_signal_bit_mask == 0);
|
|
}
|
|
|
|
test isNan {
|
|
inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| {
|
|
try expect(isNan(math.nan(T)));
|
|
try expect(isNan(-math.nan(T)));
|
|
try expect(isNan(math.snan(T)));
|
|
try expect(!isNan(@as(T, 1.0)));
|
|
try expect(!isNan(@as(T, math.inf(T))));
|
|
}
|
|
}
|
|
|
|
test isSignalNan {
|
|
inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| {
|
|
// TODO: Signalling NaN values get converted to quiet NaN values in
|
|
// some cases where they shouldn't such that this can fail.
|
|
// See https://github.com/ziglang/zig/issues/14366
|
|
// try expect(isSignalNan(math.snan(T)));
|
|
try expect(!isSignalNan(math.nan(T)));
|
|
try expect(!isSignalNan(@as(T, 1.0)));
|
|
try expect(!isSignalNan(math.inf(T)));
|
|
}
|
|
}
|