reconstruct
This currently truncates denormal values, which needs to be fixed before this can be used to produce a rounded value.
Function parameters
Parameters
- sign:std.math.Sign
Functions in this namespace
Functions
- floatExponentBits
- Returns the number of bits in the exponent of floating point type T.
- floatMantissaBits
- Returns the number of bits in the mantissa of floating point type T.
- floatFractionalBits
- Returns the number of fractional bits in the mantissa of floating point type T.
- floatExponentMin
- Returns the minimum exponent that can represent
- floatExponentMax
- Returns the maximum exponent that can represent
- floatTrueMin
- Returns the smallest subnormal number representable in floating point type T.
- floatMin
- Returns the smallest normal number representable in floating point type T.
- floatMax
- Returns the largest normal number representable in floating point type T.
- floatEps
- Returns the machine epsilon of floating point type T.
- floatEpsAt
- Returns the local epsilon of floating point type T.
- inf
- Returns the inf value for a floating point `Type`.
- nan
- Returns the canonical quiet NaN representation for a floating point `Type`.
- snan
- Returns a signalling NaN representation for a floating point `Type`.
Source
Implementation
pub fn reconstruct(normalized: Normalized, sign: std.math.Sign) Float {
if (normalized.exponent > BiasedExponent.max_normal.unbias()) return @bitCast(Repr{
.mantissa = 0,
.exponent = .infinite,
.sign = sign,
});
const mantissa = @as(Mantissa, 1 << fractional_bits) | normalized.fraction;
if (normalized.exponent < BiasedExponent.min_normal.unbias()) return @bitCast(Repr{
.mantissa = @truncate(std.math.shr(
Mantissa,
mantissa,
BiasedExponent.min_normal.unbias() - normalized.exponent,
)),
.exponent = .denormal,
.sign = sign,
});
return @bitCast(Repr{
.mantissa = @truncate(mantissa),
.exponent = .bias(@intCast(normalized.exponent)),
.sign = sign,
});
}