Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 0ce5308

Browse files
committed
Shift then mask, rather than mask then shift
This may allow for small optimizations with larger float types since `u32` math can be used after shifting. LLVM may be already getting this anyway.
1 parent 54b6e57 commit 0ce5308

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/math/support/float_traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::{fmt, mem, ops};
22

3-
use super::int_traits::{CastFrom, CastInto, Int, MinInt};
3+
use super::int_traits::{CastFrom, Int, MinInt};
44

55
/// Trait for some basic operations on floats
66
#[allow(dead_code)]
@@ -108,7 +108,7 @@ pub trait Float:
108108

109109
/// Returns the exponent, not adjusting for bias, not accounting for subnormals or zero.
110110
fn exp(self) -> i32 {
111-
((self.to_bits() & Self::EXP_MASK) >> Self::SIG_BITS).cast()
111+
(u32::cast_from(self.to_bits() >> Self::SIG_BITS) & Self::EXP_MAX).signed()
112112
}
113113

114114
/// Extract the exponent and adjust it for bias, not accounting for subnormals or zero.

0 commit comments

Comments
 (0)