pub struct Float { /* private fields */ }Expand description
A floating point number in a given format.
A finite value is significand * 2^(exponent - precision + 1). A normal number has its
leading significand bit set, a subnormal does not and has the format’s minimum exponent.
Implementations§
Source§impl Float
impl Float
Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Whether the number is negative, which a zero can be.
Sourcepub const fn is_infinite(self) -> bool
pub const fn is_infinite(self) -> bool
Whether the number is an infinity.
Sourcepub fn parse(text: &str, format: Format) -> Result<(Float, Status), ParseError>
pub fn parse(text: &str, format: Format) -> Result<(Float, Status), ParseError>
Converts a decimal or hexadecimal spelling into the nearest number in format, rounding
to nearest with ties to even.
The spelling is the number alone: no suffix, because the suffix is what chose the format, and no infinity or nan, because C has no spelling for those. A sign is accepted even though a C constant never has one, since the value the constant evaluator folds does. C23 digit separators are stripped here.
§Errors
ParseError, for a spelling that is not a number at all.
Sourcepub fn to_bits(self) -> u128
pub fn to_bits(self) -> u128
The bits of the encoding, in the low Format::width bits.
The x87 format keeps its leading significand bit, so its eightieth bit is the sign and its sixty fourth is the one every other format leaves implied.
Sourcepub fn from_bits(format: Format, bits: u128) -> Float
pub fn from_bits(format: Format, bits: u128) -> Float
Reads a number back out of its encoding, which is what makes Float::to_bits testable
and what a constant folded in the IR is stored as.
A signalling or quiet nan comes back as an infinity, because nothing here makes one and nothing here has anywhere to put the payload yet.