remove if_cond_else const hack
This commit is contained in:
parent
5a4d1a6732
commit
7522557e1d
|
@ -877,7 +877,7 @@ assert_eq!(Fix::from_num(5).saturating_neg(), Fix::from_num(0));",
|
||||||
$Signedness,
|
$Signedness,
|
||||||
{
|
{
|
||||||
let (val, overflow) = self.overflowing_neg();
|
let (val, overflow) = self.overflowing_neg();
|
||||||
val.if_cond_else(!overflow, Self::MAX)
|
if !overflow { val } else { Self::MAX }
|
||||||
},
|
},
|
||||||
Self::from_bits(0),
|
Self::from_bits(0),
|
||||||
}
|
}
|
||||||
|
@ -899,14 +899,15 @@ assert_eq!(Fix::MAX.saturating_add(Fix::from_num(1)), Fix::MAX);
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_add(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
|
pub const fn saturating_add(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
|
||||||
let (val, overflow) = self.overflowing_add(rhs);
|
let (val, overflow) = self.overflowing_add(rhs);
|
||||||
val.if_cond_else(
|
if !overflow {
|
||||||
!overflow,
|
val
|
||||||
|
} else {
|
||||||
if_signed_unsigned! {
|
if_signed_unsigned! {
|
||||||
$Signedness,
|
$Signedness,
|
||||||
Self::MIN.if_cond_else(self.to_bits() < 0, Self::MAX),
|
if self.to_bits() < 0 { Self::MIN } else { Self::MAX },
|
||||||
Self::MAX,
|
Self::MAX,
|
||||||
},
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,17 +933,15 @@ assert_eq!(Fix::from_num(0).saturating_sub(Fix::from_num(1)), Fix::from_num(0));
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_sub(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
|
pub const fn saturating_sub(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
|
||||||
let (val, overflow) = self.overflowing_sub(rhs);
|
let (val, overflow) = self.overflowing_sub(rhs);
|
||||||
val.if_cond_else(
|
if !overflow {
|
||||||
!overflow,
|
val
|
||||||
|
} else {
|
||||||
if_signed_unsigned! {
|
if_signed_unsigned! {
|
||||||
$Signedness,
|
$Signedness,
|
||||||
Self::MIN.if_cond_else(
|
if self.to_bits() < rhs.to_bits() { Self::MIN } else { Self::MAX },
|
||||||
self.to_bits() < rhs.to_bits(),
|
|
||||||
Self::MAX,
|
|
||||||
),
|
|
||||||
Self::MIN,
|
Self::MIN,
|
||||||
},
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -961,17 +960,15 @@ assert_eq!(Fix::MAX.saturating_mul_int(2), Fix::MAX);
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_mul_int(self, rhs: $Inner) -> $Fixed<Frac> {
|
pub const fn saturating_mul_int(self, rhs: $Inner) -> $Fixed<Frac> {
|
||||||
let (val, overflow) = self.overflowing_mul_int(rhs);
|
let (val, overflow) = self.overflowing_mul_int(rhs);
|
||||||
val.if_cond_else(
|
if !overflow {
|
||||||
!overflow,
|
val
|
||||||
|
} else {
|
||||||
if_signed_unsigned! {
|
if_signed_unsigned! {
|
||||||
$Signedness,
|
$Signedness,
|
||||||
Self::MIN.if_cond_else(
|
if (self.to_bits() < 0) != (rhs < 0) { Self::MIN } else { Self::MAX },
|
||||||
(self.to_bits() < 0) != (rhs < 0),
|
|
||||||
Self::MAX,
|
|
||||||
),
|
|
||||||
Self::MAX,
|
Self::MAX,
|
||||||
},
|
}
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -994,7 +991,7 @@ assert_eq!(Fix::MIN.saturating_abs(), Fix::MAX);
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_abs(self) -> $Fixed<Frac> {
|
pub const fn saturating_abs(self) -> $Fixed<Frac> {
|
||||||
let (val, overflow) = self.overflowing_abs();
|
let (val, overflow) = self.overflowing_abs();
|
||||||
val.if_cond_else(!overflow, Self::MAX)
|
if !overflow { val } else { Self::MAX }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1485,12 +1482,6 @@ assert_eq!(Fix::MIN.overflowing_abs(), (Fix::MIN, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
const fn if_cond_else(self, cond: bool, otherwise: Self) -> Self {
|
|
||||||
let not_mask = (cond as $Inner).wrapping_sub(1);
|
|
||||||
Self::from_bits((self.to_bits() & !not_mask) | (otherwise.to_bits() & not_mask))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue