Add an abs function to the Float trait

There is no in-crate use for this yet, but we will make use of it in
`libm`.
This commit is contained in:
Trevor Gross 2024-10-25 14:30:03 -05:00
parent 2f7fafd182
commit 394fb9f2bc

View file

@ -98,6 +98,11 @@ pub(crate) trait Float:
/// Constructs a `Self` from its parts. Inputs are treated as bits and shifted into position.
fn from_parts(negative: bool, exponent: Self::Int, significand: Self::Int) -> Self;
fn abs(self) -> Self {
let abs_mask = !Self::SIGN_MASK ;
Self::from_bits(self.to_bits() & abs_mask)
}
/// Returns (normalized exponent, normalized significand)
fn normalize(significand: Self::Int) -> (i32, Self::Int);