Function nan [src]
Alias for std.math.float.nan
Returns the canonical quiet NaN representation for floating point type T.
Prototype
pub inline fn nan(comptime T: type) T
Parameters
T: type
Example
test nan {
const qnan_u16: u16 = 0x7E00;
const qnan_u32: u32 = 0x7FC00000;
const qnan_u64: u64 = 0x7FF8000000000000;
const qnan_u80: u80 = 0x7FFFC000000000000000;
const qnan_u128: u128 = 0x7FFF8000000000000000000000000000;
try expectEqual(qnan_u16, @as(u16, @bitCast(nan(f16))));
try expectEqual(qnan_u32, @as(u32, @bitCast(nan(f32))));
try expectEqual(qnan_u64, @as(u64, @bitCast(nan(f64))));
try expectEqual(qnan_u80, @as(u80, @bitCast(nan(f80))));
try expectEqual(qnan_u128, @as(u128, @bitCast(nan(f128))));
}
Source
pub inline fn nan(comptime T: type) T {
return reconstructFloat(
T,
floatExponentMax(T) + 1,
mantissaOne(T) | 1 << (floatFractionalBits(T) - 1),
);
}