Skip to content

Commit

Permalink
Rename EXP_MAX to EXP_SAT
Browse files Browse the repository at this point in the history
"Maximum" is technically correct here with regards to what the
bitpattern can represent, but it is not the numeric maximum value of the
exponent which has a relationship with the bias. So, replace the maximum
terminology with "saturated" to indicate it only means the full
bitpattern.

This change is more relevant to `libm` than `compiler-builtins`.
  • Loading branch information
tgross35 committed Jan 3, 2025
1 parent 85604d9 commit ef00132
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/float/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where

let bits = F::BITS.cast();
let significand_bits = F::SIG_BITS;
let max_exponent = F::EXP_MAX;
let max_exponent = F::EXP_SAT;

let implicit_bit = F::IMPLICIT_BIT;
let significand_mask = F::SIG_MASK;
Expand Down
2 changes: 1 addition & 1 deletion src/float/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where

let significand_bits = F::SIG_BITS;
// Saturated exponent, representing infinity
let exponent_sat: F::Int = F::EXP_MAX.cast();
let exponent_sat: F::Int = F::EXP_SAT.cast();

let exponent_bias = F::EXP_BIAS;
let implicit_bit = F::IMPLICIT_BIT;
Expand Down
2 changes: 1 addition & 1 deletion src/float/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where

let dst_bits = R::BITS;
let dst_sign_bits = R::SIG_BITS;
let dst_inf_exp = R::EXP_MAX;
let dst_inf_exp = R::EXP_SAT;
let dst_exp_bias = R::EXP_BIAS;
let dst_min_normal = R::IMPLICIT_BIT;

Expand Down
9 changes: 6 additions & 3 deletions src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ pub(crate) trait Float:
/// The bitwidth of the exponent.
const EXP_BITS: u32 = Self::BITS - Self::SIG_BITS - 1;

/// The saturated value of the exponent (infinite representation), in the rightmost postiion.
const EXP_MAX: u32 = (1 << Self::EXP_BITS) - 1;
/// The saturated (maximum bitpattern) value of the exponent, i.e. the infinite
/// representation.
///
/// This is in the rightmost position, use `EXP_MASK` for the shifted value.
const EXP_SAT: u32 = (1 << Self::EXP_BITS) - 1;

/// The exponent bias value.
const EXP_BIAS: u32 = Self::EXP_MAX >> 1;
const EXP_BIAS: u32 = Self::EXP_SAT >> 1;

/// A mask for the sign bit.
const SIGN_MASK: Self::Int;
Expand Down
2 changes: 1 addition & 1 deletion src/float/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where

let bits = F::BITS;
let significand_bits = F::SIG_BITS;
let max_exponent = F::EXP_MAX;
let max_exponent = F::EXP_SAT;

let exponent_bias = F::EXP_BIAS;

Expand Down
2 changes: 1 addition & 1 deletion src/float/trunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
let dst_zero = R::Int::ZERO;
let dst_one = R::Int::ONE;
let dst_bits = R::BITS;
let dst_inf_exp = R::EXP_MAX;
let dst_inf_exp = R::EXP_SAT;
let dst_exp_bias = R::EXP_BIAS;

let underflow_exponent: F::Int = (src_exp_bias + 1 - dst_exp_bias).cast();
Expand Down

0 comments on commit ef00132

Please sign in to comment.