Skip to content

Commit

Permalink
Add an abs function to the Float trait
Browse files Browse the repository at this point in the history
There is no in-crate use for this yet, but we will make use of it in
`libm`.
  • Loading branch information
tgross35 committed Oct 25, 2024
1 parent ff64677 commit 64f131a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 64f131a

Please sign in to comment.