use constants {INT,FRAC}_NBITS instead of methods where possible
This commit is contained in:
parent
3f7d1f42a5
commit
07ea3ff1ae
33
src/cmp.rs
33
src/cmp.rs
|
@ -30,9 +30,9 @@ macro_rules! fixed_cmp_fixed {
|
|||
#[inline]
|
||||
fn eq(&self, rhs: &$Rhs<FracRhs>) -> bool {
|
||||
let conv = rhs.to_bits().to_fixed_helper(
|
||||
<$Rhs<FracRhs>>::frac_nbits() as i32,
|
||||
Self::frac_nbits(),
|
||||
Self::int_nbits(),
|
||||
<$Rhs<FracRhs>>::FRAC_NBITS as i32,
|
||||
Self::FRAC_NBITS,
|
||||
Self::INT_NBITS,
|
||||
);
|
||||
let rhs_bits = match conv.bits {
|
||||
Widest::Unsigned(bits) => bits as <Self as Fixed>::Bits,
|
||||
|
@ -51,9 +51,9 @@ macro_rules! fixed_cmp_fixed {
|
|||
_ => {}
|
||||
}
|
||||
let conv = rhs.to_bits().to_fixed_helper(
|
||||
<$Rhs<FracRhs>>::frac_nbits() as i32,
|
||||
Self::frac_nbits(),
|
||||
Self::int_nbits(),
|
||||
<$Rhs<FracRhs>>::FRAC_NBITS as i32,
|
||||
Self::FRAC_NBITS,
|
||||
Self::INT_NBITS,
|
||||
);
|
||||
if conv.overflow {
|
||||
return if rhs.to_bits().is_negative() {
|
||||
|
@ -77,9 +77,9 @@ macro_rules! fixed_cmp_fixed {
|
|||
_ => {}
|
||||
}
|
||||
let conv = rhs.to_bits().to_fixed_helper(
|
||||
<$Rhs<FracRhs>>::frac_nbits() as i32,
|
||||
Self::frac_nbits(),
|
||||
Self::int_nbits(),
|
||||
<$Rhs<FracRhs>>::FRAC_NBITS as i32,
|
||||
Self::FRAC_NBITS,
|
||||
Self::INT_NBITS,
|
||||
);
|
||||
if conv.overflow {
|
||||
return !rhs.to_bits().is_negative();
|
||||
|
@ -187,7 +187,7 @@ macro_rules! fixed_cmp_float {
|
|||
impl<Frac: $LeEqU> PartialEq<$Float> for $Fix<Frac> {
|
||||
#[inline]
|
||||
fn eq(&self, rhs: &$Float) -> bool {
|
||||
let conv = match rhs.to_float_kind(Self::frac_nbits(), Self::int_nbits()) {
|
||||
let conv = match rhs.to_float_kind(Self::FRAC_NBITS, Self::INT_NBITS) {
|
||||
FloatKind::Finite { conv, .. } => conv,
|
||||
_ => return false,
|
||||
};
|
||||
|
@ -209,8 +209,8 @@ macro_rules! fixed_cmp_float {
|
|||
impl<Frac: $LeEqU> PartialOrd<$Float> for $Fix<Frac> {
|
||||
#[inline]
|
||||
fn partial_cmp(&self, rhs: &$Float) -> Option<Ordering> {
|
||||
let (rhs_is_neg, conv) =
|
||||
match rhs.to_float_kind(Self::frac_nbits(), Self::int_nbits()) {
|
||||
let (rhs_is_neg, conv) = match rhs.to_float_kind(Self::FRAC_NBITS, Self::INT_NBITS)
|
||||
{
|
||||
FloatKind::NaN => return None,
|
||||
FloatKind::Infinite { neg } => {
|
||||
return if neg {
|
||||
|
@ -242,8 +242,8 @@ macro_rules! fixed_cmp_float {
|
|||
|
||||
#[inline]
|
||||
fn lt(&self, rhs: &$Float) -> bool {
|
||||
let (rhs_is_neg, conv) =
|
||||
match rhs.to_float_kind(Self::frac_nbits(), Self::int_nbits()) {
|
||||
let (rhs_is_neg, conv) = match rhs.to_float_kind(Self::FRAC_NBITS, Self::INT_NBITS)
|
||||
{
|
||||
FloatKind::NaN => return false,
|
||||
FloatKind::Infinite { neg } => return !neg,
|
||||
FloatKind::Finite { neg, conv } => (neg, conv),
|
||||
|
@ -289,9 +289,8 @@ macro_rules! fixed_cmp_float {
|
|||
|
||||
#[inline]
|
||||
fn lt(&self, rhs: &$Fix<Frac>) -> bool {
|
||||
let (lhs_is_neg, conv) = match self
|
||||
.to_float_kind(<$Fix<Frac>>::frac_nbits(), <$Fix<Frac>>::int_nbits())
|
||||
{
|
||||
let (lhs_is_neg, conv) =
|
||||
match self.to_float_kind(<$Fix<Frac>>::FRAC_NBITS, <$Fix<Frac>>::INT_NBITS) {
|
||||
FloatKind::NaN => return false,
|
||||
FloatKind::Infinite { neg } => return neg,
|
||||
FloatKind::Finite { neg, conv } => (neg, conv),
|
||||
|
|
|
@ -547,16 +547,14 @@ macro_rules! impl_from_str {
|
|||
type Err = ParseFixedError;
|
||||
#[inline]
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
$method(s.as_bytes(), 10, Self::int_nbits(), Self::frac_nbits())
|
||||
.map(Self::from_bits)
|
||||
$method(s.as_bytes(), 10, Self::INT_NBITS, Self::FRAC_NBITS).map(Self::from_bits)
|
||||
}
|
||||
}
|
||||
impl<Frac: $LeEqU> FromStrRadix for $Fixed<Frac> {
|
||||
type Err = ParseFixedError;
|
||||
#[inline]
|
||||
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::Err> {
|
||||
$method(s.as_bytes(), radix, Self::int_nbits(), Self::frac_nbits())
|
||||
.map(Self::from_bits)
|
||||
$method(s.as_bytes(), radix, Self::INT_NBITS, Self::FRAC_NBITS).map(Self::from_bits)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -64,7 +64,7 @@ macro_rules! impl_sealed {
|
|||
dst_int_nbits: u32,
|
||||
) -> ToFixedHelper {
|
||||
self.to_bits().to_fixed_helper(
|
||||
Self::frac_nbits() as i32,
|
||||
Self::FRAC_NBITS as i32,
|
||||
dst_frac_nbits,
|
||||
dst_int_nbits,
|
||||
)
|
||||
|
|
|
@ -1399,7 +1399,7 @@ macro_rules! impl_fixed {
|
|||
}
|
||||
#[inline]
|
||||
fn saturating_from_fixed<F: Fixed>(src: F) -> Self {
|
||||
let conv = src.private_to_fixed_helper(Self::frac_nbits(), Self::int_nbits());
|
||||
let conv = src.private_to_fixed_helper(Self::FRAC_NBITS, Self::INT_NBITS);
|
||||
if conv.overflow {
|
||||
return if src < 0 {
|
||||
Self::min_value()
|
||||
|
@ -1434,7 +1434,7 @@ macro_rules! impl_fixed {
|
|||
}
|
||||
#[inline]
|
||||
fn overflowing_from_fixed<F: Fixed>(src: F) -> (Self, bool) {
|
||||
let conv = src.private_to_fixed_helper(Self::frac_nbits(), Self::int_nbits());
|
||||
let conv = src.private_to_fixed_helper(Self::FRAC_NBITS, Self::INT_NBITS);
|
||||
let mut new_overflow = false;
|
||||
let bits = if_signed_unsigned!(
|
||||
$Signedness,
|
||||
|
|
Loading…
Reference in New Issue