Skip to content

Commit accd88f

Browse files
committed
Update bounds and docs for the Float trait
Add some bounds to integer types that allow our function trait bounds to be slightly less verbose. Also clarify documentation and remove a redundant operation.
1 parent 02d5e44 commit accd88f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/float/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ pub(crate) trait Float:
3131
+ ops::Rem<Output = Self>
3232
{
3333
/// A uint of the same width as the float
34-
type Int: Int;
34+
type Int: Int<OtherSign = Self::SignedInt, UnsignedInt = Self::Int>;
3535

3636
/// A int of the same width as the float
37-
type SignedInt: Int;
37+
type SignedInt: Int + MinInt<OtherSign = Self::Int, UnsignedInt = Self::Int>;
3838

3939
/// An int capable of containing the exponent bits plus a sign bit. This is signed.
4040
type ExpInt: Int;
@@ -51,7 +51,7 @@ pub(crate) trait Float:
5151
/// The bitwidth of the exponent
5252
const EXPONENT_BITS: u32 = Self::BITS - Self::SIGNIFICAND_BITS - 1;
5353

54-
/// The maximum value of the exponent
54+
/// The saturated value of the exponent (infinite representation), in the rightmost postiion.
5555
const EXPONENT_MAX: u32 = (1 << Self::EXPONENT_BITS) - 1;
5656

5757
/// The exponent bias value
@@ -83,7 +83,7 @@ pub(crate) trait Float:
8383
/// Returns true if the sign is negative
8484
fn is_sign_negative(self) -> bool;
8585

86-
/// Returns the exponent with bias
86+
/// Returns the exponent, not adjusting for bias.
8787
fn exp(self) -> Self::ExpInt;
8888

8989
/// Returns the significand with no implicit bit (or the "fractional" part)
@@ -175,7 +175,7 @@ macro_rules! float_impl {
175175
fn normalize(significand: Self::Int) -> (i32, Self::Int) {
176176
let shift = significand
177177
.leading_zeros()
178-
.wrapping_sub((Self::Int::ONE << Self::SIGNIFICAND_BITS).leading_zeros());
178+
.wrapping_sub(Self::EXPONENT_BITS);
179179
(
180180
1i32.wrapping_sub(shift as i32),
181181
significand << shift as Self::Int,

0 commit comments

Comments
 (0)