Function nan [src]

Alias for std.math.float.nan

Returns the canonical quiet NaN representation for a floating point Type.

Prototype

pub inline fn nan(comptime Type: type) Type

Parameters

Type: 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 Type: type) Type { const RuntimeType = switch (Type) { else => Type, comptime_float => f128, // any float type will do }; return reconstructFloat( RuntimeType, floatExponentMax(RuntimeType) + 1, mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 1), ); }