Skip to content

Commit 64f131a

Browse files
committed
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`.
1 parent ff64677 commit 64f131a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/float/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ pub(crate) trait Float:
9898
/// Constructs a `Self` from its parts. Inputs are treated as bits and shifted into position.
9999
fn from_parts(negative: bool, exponent: Self::Int, significand: Self::Int) -> Self;
100100

101+
fn abs(self) -> Self {
102+
let abs_mask = !Self::SIGN_MASK ;
103+
Self::from_bits(self.to_bits() & abs_mask)
104+
}
105+
101106
/// Returns (normalized exponent, normalized significand)
102107
fn normalize(significand: Self::Int) -> (i32, Self::Int);
103108

0 commit comments

Comments
 (0)