diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-10-25 14:30:03 -0500 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-10-25 14:30:03 -0500 |
| commit | 394fb9f2bcf0fa2e6d0ab6d0787e7859cdd9e8ac (patch) | |
| tree | 362fec1ca0822302ef830cac3e2dc62ba7a8464f | |
| parent | 2f7fafd182f53e827f12da5af5ab42b3484e44d6 (diff) | |
| download | rust-394fb9f2bcf0fa2e6d0ab6d0787e7859cdd9e8ac.tar.gz rust-394fb9f2bcf0fa2e6d0ab6d0787e7859cdd9e8ac.zip | |
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`.
| -rw-r--r-- | library/compiler-builtins/src/float/mod.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/library/compiler-builtins/src/float/mod.rs b/library/compiler-builtins/src/float/mod.rs index 5eedf544f12..af83986447e 100644 --- a/library/compiler-builtins/src/float/mod.rs +++ b/library/compiler-builtins/src/float/mod.rs @@ -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); |
