Skip to content

Commit

Permalink
Update bounds and docs for the Float trait
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross35 committed Aug 19, 2024
1 parent d6ec620 commit 81148a5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ pub(crate) trait Float:
+ ops::Rem<Output = Self>
{
/// A uint of the same width as the float
type Int: Int;
type Int: Int<OtherSign = Self::SignedInt, UnsignedInt = Self::Int>;

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

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

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

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

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

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

0 comments on commit 81148a5

Please sign in to comment.