inline very simple "where"s
This commit is contained in:
parent
d0faad2c0a
commit
3d8eaaac64
|
@ -95,15 +95,12 @@ macro_rules! fmt_radix2_helper {
|
||||||
|
|
||||||
fmt_radix2_helper! { u8 u16 u32 u64 u128 }
|
fmt_radix2_helper! { u8 u16 u32 u64 u128 }
|
||||||
|
|
||||||
fn fmt_radix2_helper<F>(
|
fn fmt_radix2_helper<F: FmtRadix2Helper>(
|
||||||
frac_bits: u32,
|
frac_bits: u32,
|
||||||
(is_neg, mut int, mut frac): (bool, F, F),
|
(is_neg, mut int, mut frac): (bool, F, F),
|
||||||
radix: &dyn Radix2,
|
radix: &dyn Radix2,
|
||||||
fmt: &mut Formatter,
|
fmt: &mut Formatter,
|
||||||
) -> FmtResult
|
) -> FmtResult {
|
||||||
where
|
|
||||||
F: FmtRadix2Helper,
|
|
||||||
{
|
|
||||||
let int_bits = F::NBITS - frac_bits;
|
let int_bits = F::NBITS - frac_bits;
|
||||||
let digit_bits: u32 = radix.digit_bits();
|
let digit_bits: u32 = radix.digit_bits();
|
||||||
// 128 binary digits, one radix point, one leading zero
|
// 128 binary digits, one radix point, one leading zero
|
||||||
|
@ -275,14 +272,11 @@ macro_rules! fmt_dec_helper {
|
||||||
|
|
||||||
fmt_dec_helper! { u8 u16 u32 u64 u128 }
|
fmt_dec_helper! { u8 u16 u32 u64 u128 }
|
||||||
|
|
||||||
fn fmt_dec_helper<F>(
|
fn fmt_dec_helper<F: FmtDecHelper>(
|
||||||
frac_bits: u32,
|
frac_bits: u32,
|
||||||
(is_neg, mut int, mut frac): (bool, F, F),
|
(is_neg, mut int, mut frac): (bool, F, F),
|
||||||
fmt: &mut Formatter,
|
fmt: &mut Formatter,
|
||||||
) -> FmtResult
|
) -> FmtResult {
|
||||||
where
|
|
||||||
F: FmtDecHelper,
|
|
||||||
{
|
|
||||||
let int_bits = F::NBITS - frac_bits;
|
let int_bits = F::NBITS - frac_bits;
|
||||||
// 40 int digits
|
// 40 int digits
|
||||||
// + 128 frac digits
|
// + 128 frac digits
|
||||||
|
|
|
@ -339,10 +339,7 @@ assert_eq!(two_point_75.to_string(), \"2.8\");
|
||||||
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
|
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash<H>(&self, state: &mut H)
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
where
|
|
||||||
H: Hasher,
|
|
||||||
{
|
|
||||||
self.to_bits().hash(state);
|
self.to_bits().hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,10 +89,7 @@ assert_eq!(Dst::from_fixed(src >> 4), Dst::from_bits(1));
|
||||||
[`wrapping_from_fixed`]: #method.wrapping_from_fixed
|
[`wrapping_from_fixed`]: #method.wrapping_from_fixed
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_fixed<F>(val: F) -> $Fixed<Frac>
|
pub fn from_fixed<F: Fixed>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::from_fixed(val)
|
SealedFixed::from_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -127,10 +124,7 @@ assert_eq!((src >> 4u32).to_fixed::<Dst>(), Dst::from_bits(1));
|
||||||
[`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
[`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_fixed<F>(self) -> F
|
pub fn to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::from_fixed(self)
|
SealedFixed::from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -180,10 +174,7 @@ assert_eq!(Fix::from_int(",
|
||||||
[`wrapping_from_int`]: #method.wrapping_from_int
|
[`wrapping_from_int`]: #method.wrapping_from_int
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_int<I>(val: I) -> $Fixed<Frac>
|
pub fn from_int<I: Int>(val: I) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::to_fixed(val)
|
SealedInt::to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -236,10 +227,7 @@ assert_eq!(",
|
||||||
[`wrapping_to_int`]: #method.wrapping_to_int
|
[`wrapping_to_int`]: #method.wrapping_to_int
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_int<I>(self) -> I
|
pub fn to_int<I: Int>(self) -> I {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::from_fixed(self)
|
SealedInt::from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -288,10 +276,7 @@ assert_eq!(Fix::from_float(",
|
||||||
[finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
[finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_float<F>(val: F) -> $Fixed<Frac>
|
pub fn from_float<F: Float>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFloat::to_fixed(val)
|
SealedFloat::to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -328,10 +313,7 @@ assert_eq!(max_fixed.to_float::<f32>(), std::f32::INFINITY);
|
||||||
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
|
[`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html
|
||||||
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
|
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
|
||||||
";
|
";
|
||||||
pub fn to_float<F>(self) -> F
|
pub fn to_float<F: Float>(self) -> F {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFixed::to_float(self)
|
SealedFixed::to_float(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -361,10 +343,7 @@ assert!(Dst::checked_from_fixed(too_large).is_none());
|
||||||
[`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
[`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn checked_from_fixed<F>(val: F) -> Option<$Fixed<Frac>>
|
pub fn checked_from_fixed<F: Fixed>(val: F) -> Option<$Fixed<Frac>> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::checked_from_fixed(val)
|
SealedFixed::checked_from_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -395,10 +374,7 @@ assert!(Src::max_value().checked_to_fixed::<TooFewIntBits>().is_none());
|
||||||
[`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
[`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn checked_to_fixed<F>(self) -> Option<F>
|
pub fn checked_to_fixed<F: Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::checked_from_fixed(self)
|
SealedFixed::checked_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -447,10 +423,7 @@ assert!(Fix::checked_from_int(too_small).is_none());
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn checked_from_int<I>(val: I) -> Option<$Fixed<Frac>>
|
pub fn checked_from_int<I: Int>(val: I) -> Option<$Fixed<Frac>> {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::checked_to_fixed(val)
|
SealedInt::checked_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -508,10 +481,7 @@ assert!(AllInt::",
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn checked_to_int<I>(self) -> Option<I>
|
pub fn checked_to_int<I: Int>(self) -> Option<I> {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::checked_from_fixed(self)
|
SealedInt::checked_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -552,10 +522,7 @@ assert!(Fix::checked_from_float(std::f64::NAN).is_none());
|
||||||
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
|
[`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn checked_from_float<F>(val: F) -> Option<$Fixed<Frac>>
|
pub fn checked_from_float<F: Float>(val: F) -> Option<$Fixed<Frac>> {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFloat::checked_to_fixed(val)
|
SealedFloat::checked_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -591,10 +558,7 @@ assert_eq!(Dst::saturating_from_fixed(too_small), Dst::min_value());
|
||||||
```
|
```
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_from_fixed<F>(val: F) -> $Fixed<Frac>
|
pub fn saturating_from_fixed<F: Fixed>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_fixed(val)
|
SealedFixed::saturating_from_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -623,10 +587,7 @@ assert_eq!(saturated, TooFewIntBits::max_value());
|
||||||
```
|
```
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_to_fixed<F>(self) -> F
|
pub fn saturating_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_fixed(self)
|
SealedFixed::saturating_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -674,10 +635,7 @@ assert_eq!(Fix::saturating_from_int(too_small), Fix::min_value());
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_from_int<I>(val: I) -> $Fixed<Frac>
|
pub fn saturating_from_int<I: Int>(val: I) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::saturating_to_fixed(val)
|
SealedInt::saturating_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -743,10 +701,7 @@ assert_eq!(",
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_to_int<I>(self) -> I
|
pub fn saturating_to_int<I: Int>(self) -> I {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::saturating_from_fixed(self)
|
SealedInt::saturating_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -785,10 +740,7 @@ assert_eq!(Fix::saturating_from_float(f64::NEG_INFINITY), Fix::min_value());
|
||||||
[NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan
|
[NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn saturating_from_float<F>(val: F) -> $Fixed<Frac>
|
pub fn saturating_from_float<F: Float>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFloat::saturating_to_fixed(val)
|
SealedFloat::saturating_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -825,10 +777,7 @@ assert_eq!(Dst::wrapping_from_fixed(too_large), wrapped);
|
||||||
```
|
```
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrapping_from_fixed<F>(val: F) -> $Fixed<Frac>
|
pub fn wrapping_from_fixed<F: Fixed>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::wrapping_from_fixed(val)
|
SealedFixed::wrapping_from_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -858,10 +807,7 @@ assert_eq!(Src::max_value().wrapping_to_fixed::<TooFewIntBits>(), wrapped);
|
||||||
```
|
```
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrapping_to_fixed<F>(self) -> F
|
pub fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::wrapping_from_fixed(self)
|
SealedFixed::wrapping_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -909,10 +855,7 @@ assert_eq!(Fix::wrapping_from_int(large), wrapped);
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrapping_from_int<I>(val: I) -> $Fixed<Frac>
|
pub fn wrapping_from_int<I: Int>(val: I) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::wrapping_to_fixed(val)
|
SealedInt::wrapping_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -978,10 +921,7 @@ assert_eq!(",
|
||||||
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
[`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrapping_to_int<I>(self) -> I
|
pub fn wrapping_to_int<I: Int>(self) -> I {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::wrapping_from_fixed(self)
|
SealedInt::wrapping_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1030,10 +970,7 @@ assert_eq!(Fix::wrapping_from_float(large), wrapped);
|
||||||
[finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
[finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn wrapping_from_float<F>(val: F) -> $Fixed<Frac>
|
pub fn wrapping_from_float<F: Float>(val: F) -> $Fixed<Frac> {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFloat::wrapping_to_fixed(val)
|
SealedFloat::wrapping_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1077,10 +1014,7 @@ assert_eq!(Dst::overflowing_from_fixed(too_large), (wrapped, true));
|
||||||
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overflowing_from_fixed<F>(val: F) -> ($Fixed<Frac>, bool)
|
pub fn overflowing_from_fixed<F: Fixed>(val: F) -> ($Fixed<Frac>, bool) {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_fixed(val)
|
SealedFixed::overflowing_from_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1114,10 +1048,7 @@ assert_eq!(Src::max_value().overflowing_to_fixed::<TooFewIntBits>(), (wrapped, t
|
||||||
```
|
```
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overflowing_to_fixed<F>(self) -> (F, bool)
|
pub fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_fixed(self)
|
SealedFixed::overflowing_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1170,10 +1101,7 @@ assert_eq!(Fix::overflowing_from_int(large), (wrapped, true));
|
||||||
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overflowing_from_int<I>(val: I) -> ($Fixed<Frac>, bool)
|
pub fn overflowing_from_int<I: Int>(val: I) -> ($Fixed<Frac>, bool) {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::overflowing_to_fixed(val)
|
SealedInt::overflowing_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1239,10 +1167,7 @@ assert_eq!(does_not_fit.overflowing_to_int::<",
|
||||||
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overflowing_to_int<I>(self) -> (I, bool)
|
pub fn overflowing_to_int<I: Int>(self) -> (I, bool) {
|
||||||
where
|
|
||||||
I: Int,
|
|
||||||
{
|
|
||||||
SealedInt::overflowing_from_fixed(self)
|
SealedInt::overflowing_from_fixed(self)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1296,10 +1221,7 @@ assert_eq!(Fix::overflowing_from_float(large), (wrapped, true));
|
||||||
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
[tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
";
|
";
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn overflowing_from_float<F>(val: F) -> ($Fixed<Frac>, bool)
|
pub fn overflowing_from_float<F: Float>(val: F) -> ($Fixed<Frac>, bool) {
|
||||||
where
|
|
||||||
F: Float,
|
|
||||||
{
|
|
||||||
SealedFloat::overflowing_to_fixed(val)
|
SealedFloat::overflowing_to_fixed(val)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -48,49 +48,30 @@ pub trait SealedFixed: Copy + Debug + Default + Display + Eq + Hash + Ord {
|
||||||
const INT_LSB: u128 = Self::INT_MASK ^ (Self::INT_MASK << 1);
|
const INT_LSB: u128 = Self::INT_MASK ^ (Self::INT_MASK << 1);
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, overflow) = SealedFixed::overflowing_from_fixed(val);
|
let (wrapped, overflow) = SealedFixed::overflowing_from_fixed(val);
|
||||||
debug_assert!(!overflow, "{} overflows", val);
|
debug_assert!(!overflow, "{} overflows", val);
|
||||||
let _ = overflow;
|
let _ = overflow;
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: Fixed>(val: F) -> Option<Self> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
match SealedFixed::overflowing_from_fixed(val) {
|
match SealedFixed::overflowing_from_fixed(val) {
|
||||||
(_, true) => None,
|
(_, true) => None,
|
||||||
(wrapped, false) => Some(wrapped),
|
(wrapped, false) => Some(wrapped),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn saturating_from_fixed<F>(fixed: F) -> Self
|
fn saturating_from_fixed<F: Fixed>(fixed: F) -> Self;
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, _) = SealedFixed::overflowing_from_fixed(val);
|
let (wrapped, _) = SealedFixed::overflowing_from_fixed(val);
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
fn overflowing_from_fixed<F>(fixed: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: Fixed>(fixed: F) -> (Self, bool);
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
|
|
||||||
fn saturating_from_float<F>(float: F) -> Self
|
fn saturating_from_float<F: SealedFloat>(float: F) -> Self;
|
||||||
where
|
fn overflowing_from_float<F: SealedFloat>(float: F) -> (Self, bool);
|
||||||
F: SealedFloat;
|
fn to_float<F: SealedFloat>(self) -> F;
|
||||||
fn overflowing_from_float<F>(float: F) -> (Self, bool)
|
|
||||||
where
|
|
||||||
F: SealedFloat;
|
|
||||||
fn to_float<F>(self) -> F
|
|
||||||
where
|
|
||||||
F: SealedFloat;
|
|
||||||
|
|
||||||
fn from_sbits(bits: Self::SBits) -> Self;
|
fn from_sbits(bits: Self::SBits) -> Self;
|
||||||
fn to_sbits(self) -> Self::SBits;
|
fn to_sbits(self) -> Self::SBits;
|
||||||
|
@ -119,10 +100,7 @@ macro_rules! sealed_fixed {
|
||||||
type SBits = $Bits;
|
type SBits = $Bits;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (value, _, overflow) = val.to_sbits().to_fixed_dir_overflow(
|
let (value, _, overflow) = val.to_sbits().to_fixed_dir_overflow(
|
||||||
F::FRAC_NBITS as i32,
|
F::FRAC_NBITS as i32,
|
||||||
Self::FRAC_NBITS,
|
Self::FRAC_NBITS,
|
||||||
|
@ -157,10 +135,7 @@ macro_rules! sealed_fixed {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: Fixed>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (value, _, mut overflow) = val.to_sbits().to_fixed_dir_overflow(
|
let (value, _, mut overflow) = val.to_sbits().to_fixed_dir_overflow(
|
||||||
F::FRAC_NBITS as i32,
|
F::FRAC_NBITS as i32,
|
||||||
Self::FRAC_NBITS,
|
Self::FRAC_NBITS,
|
||||||
|
@ -189,10 +164,7 @@ macro_rules! sealed_fixed {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_float<F>(val: F) -> Self
|
fn saturating_from_float<F: SealedFloat>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: SealedFloat,
|
|
||||||
{
|
|
||||||
if val.is_nan() {
|
if val.is_nan() {
|
||||||
panic!("NaN");
|
panic!("NaN");
|
||||||
}
|
}
|
||||||
|
@ -228,10 +200,7 @@ macro_rules! sealed_fixed {
|
||||||
$Fixed::from_bits(bits)
|
$Fixed::from_bits(bits)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_float<F>(val: F) -> (Self, bool)
|
fn overflowing_from_float<F: SealedFloat>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: SealedFloat,
|
|
||||||
{
|
|
||||||
if !val.is_finite() {
|
if !val.is_finite() {
|
||||||
panic!("{} is not finite", val);
|
panic!("{} is not finite", val);
|
||||||
}
|
}
|
||||||
|
@ -260,10 +229,7 @@ macro_rules! sealed_fixed {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_float<F>(self) -> F
|
fn to_float<F: SealedFloat>(self) -> F {
|
||||||
where
|
|
||||||
F: SealedFloat,
|
|
||||||
{
|
|
||||||
let (neg, abs) = self.to_bits().neg_abs();
|
let (neg, abs) = self.to_bits().neg_abs();
|
||||||
SealedFloat::from_neg_abs(neg, u128::from(abs), Self::FRAC_NBITS, Self::INT_NBITS)
|
SealedFloat::from_neg_abs(neg, u128::from(abs), Self::FRAC_NBITS, Self::INT_NBITS)
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,20 +44,14 @@ pub trait SealedFloat: Copy + Debug + Display {
|
||||||
fn from_parts(sign: bool, exp: i32, mant: Self::Bits) -> Self;
|
fn from_parts(sign: bool, exp: i32, mant: Self::Bits) -> Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, overflow) = Self::overflowing_to_fixed(self);
|
let (wrapped, overflow) = Self::overflowing_to_fixed(self);
|
||||||
debug_assert!(!overflow, "{} overflows", self);
|
debug_assert!(!overflow, "{} overflows", self);
|
||||||
let _ = overflow;
|
let _ = overflow;
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
if !self.is_finite() {
|
if !self.is_finite() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -67,25 +61,16 @@ pub trait SealedFloat: Copy + Debug + Display {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_float(self)
|
SealedFixed::saturating_from_float(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, _) = Self::overflowing_to_fixed(self);
|
let (wrapped, _) = Self::overflowing_to_fixed(self);
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_float(self)
|
SealedFixed::overflowing_from_float(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,74 +35,48 @@ pub trait SealedInt: Copy + Ord + Debug + Display {
|
||||||
const MSB: Self;
|
const MSB: Self;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, overflow) = Self::overflowing_from_fixed(val);
|
let (wrapped, overflow) = Self::overflowing_from_fixed(val);
|
||||||
debug_assert!(!overflow, "{} overflows", val);
|
debug_assert!(!overflow, "{} overflows", val);
|
||||||
let _ = overflow;
|
let _ = overflow;
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: Fixed>(val: F) -> Option<Self> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
match Self::overflowing_from_fixed(val) {
|
match Self::overflowing_from_fixed(val) {
|
||||||
(_, true) => None,
|
(_, true) => None,
|
||||||
(wrapped, false) => Some(wrapped),
|
(wrapped, false) => Some(wrapped),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: Fixed>(val: F) -> Self;
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, _) = Self::overflowing_from_fixed(val);
|
let (wrapped, _) = Self::overflowing_from_fixed(val);
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: Fixed>(val: F) -> (Self, bool);
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, overflow) = Self::overflowing_to_fixed(self);
|
let (wrapped, overflow) = Self::overflowing_to_fixed(self);
|
||||||
debug_assert!(!overflow, "{} overflows", self);
|
debug_assert!(!overflow, "{} overflows", self);
|
||||||
let _ = overflow;
|
let _ = overflow;
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
match Self::overflowing_to_fixed(self) {
|
match Self::overflowing_to_fixed(self) {
|
||||||
(_, true) => None,
|
(_, true) => None,
|
||||||
(wrapped, false) => Some(wrapped),
|
(wrapped, false) => Some(wrapped),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: Fixed>(self) -> F;
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, _) = Self::overflowing_to_fixed(self);
|
let (wrapped, _) = Self::overflowing_to_fixed(self);
|
||||||
wrapped
|
wrapped
|
||||||
}
|
}
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool);
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
|
|
||||||
fn min_value() -> Self;
|
fn min_value() -> Self;
|
||||||
fn max_value() -> Self;
|
fn max_value() -> Self;
|
||||||
|
@ -146,34 +120,22 @@ macro_rules! sealed_int {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let saturated = Self::ReprFixed::saturating_from_fixed(val);
|
let saturated = Self::ReprFixed::saturating_from_fixed(val);
|
||||||
IntRepr::from_int_repr(saturated.to_bits())
|
IntRepr::from_int_repr(saturated.to_bits())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: Fixed>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
let (wrapped, overflow) = Self::ReprFixed::overflowing_from_fixed(val);
|
let (wrapped, overflow) = Self::ReprFixed::overflowing_from_fixed(val);
|
||||||
(IntRepr::from_int_repr(wrapped.to_bits()), overflow)
|
(IntRepr::from_int_repr(wrapped.to_bits()), overflow)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_fixed(self.to_repr_fixed())
|
SealedFixed::saturating_from_fixed(self.to_repr_fixed())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: Fixed
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_fixed(self.to_repr_fixed())
|
SealedFixed::overflowing_from_fixed(self.to_repr_fixed())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,7 @@ macro_rules! serde_fixed {
|
||||||
where
|
where
|
||||||
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
||||||
{
|
{
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let bits = self.to_bits();
|
let bits = self.to_bits();
|
||||||
let mut state = serializer.serialize_struct($Name, 1)?;
|
let mut state = serializer.serialize_struct($Name, 1)?;
|
||||||
state.serialize_field("bits", &bits)?;
|
state.serialize_field("bits", &bits)?;
|
||||||
|
@ -45,10 +42,7 @@ macro_rules! serde_fixed {
|
||||||
where
|
where
|
||||||
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
||||||
{
|
{
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct FixedVisitor;
|
struct FixedVisitor;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for FixedVisitor {
|
impl<'de> Visitor<'de> for FixedVisitor {
|
||||||
|
@ -59,20 +53,14 @@ macro_rules! serde_fixed {
|
||||||
formatter.write_str($Name)
|
formatter.write_str($Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq<V>(self, mut seq: V) -> Result<$TBits, V::Error>
|
fn visit_seq<V: SeqAccess<'de>>(self, mut seq: V) -> Result<$TBits, V::Error> {
|
||||||
where
|
|
||||||
V: SeqAccess<'de>,
|
|
||||||
{
|
|
||||||
let bits = seq
|
let bits = seq
|
||||||
.next_element()?
|
.next_element()?
|
||||||
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
|
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
|
||||||
Ok(bits)
|
Ok(bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map<V>(self, mut map: V) -> Result<$TBits, V::Error>
|
fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<$TBits, V::Error> {
|
||||||
where
|
|
||||||
V: MapAccess<'de>,
|
|
||||||
{
|
|
||||||
let mut bits = None;
|
let mut bits = None;
|
||||||
while let Some(key) = map.next_key()? {
|
while let Some(key) = map.next_key()? {
|
||||||
match key {
|
match key {
|
||||||
|
@ -114,10 +102,7 @@ enum Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Field {
|
impl<'de> Deserialize<'de> for Field {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Field, D::Error>
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Field, D::Error> {
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
struct FieldVisitor;
|
struct FieldVisitor;
|
||||||
|
|
||||||
impl<'de> Visitor<'de> for FieldVisitor {
|
impl<'de> Visitor<'de> for FieldVisitor {
|
||||||
|
@ -127,10 +112,7 @@ impl<'de> Deserialize<'de> for Field {
|
||||||
formatter.write_str("`bits`")
|
formatter.write_str("`bits`")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<E>(self, value: &str) -> Result<Field, E>
|
fn visit_str<E: de::Error>(self, value: &str) -> Result<Field, E> {
|
||||||
where
|
|
||||||
E: de::Error,
|
|
||||||
{
|
|
||||||
match value {
|
match value {
|
||||||
"bits" => Ok(Field::Bits),
|
"bits" => Ok(Field::Bits),
|
||||||
_ => Err(de::Error::unknown_field(value, FIELDS)),
|
_ => Err(de::Error::unknown_field(value, FIELDS)),
|
||||||
|
|
213
src/traits.rs
213
src/traits.rs
|
@ -655,33 +655,26 @@ pub trait FromFixed {
|
||||||
/// [`wrapping_from_fixed`] instead.
|
/// [`wrapping_from_fixed`] instead.
|
||||||
///
|
///
|
||||||
/// [`wrapping_from_fixed`]: #method.wrapping_from_fixed
|
/// [`wrapping_from_fixed`]: #method.wrapping_from_fixed
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: sealed::Fixed>(val: F) -> Self;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts from a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts from a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
///
|
///
|
||||||
/// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
/// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: sealed::Fixed>(val: F) -> Option<Self>
|
||||||
where
|
where
|
||||||
F: sealed::Fixed,
|
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
||||||
/// Converts from a fixed-point number, saturating if it does not fit.
|
/// Converts from a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: sealed::Fixed>(val: F) -> Self;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts from a fixed-point number, wrapping if it does not fit.
|
/// Converts from a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: sealed::Fixed>(val: F) -> Self;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts from a fixed-point number.
|
/// Converts from a fixed-point number.
|
||||||
///
|
///
|
||||||
|
@ -693,9 +686,8 @@ pub trait FromFixed {
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: sealed::Fixed>(val: F) -> (Self, bool)
|
||||||
where
|
where
|
||||||
F: sealed::Fixed,
|
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,32 +728,24 @@ pub trait ToFixed {
|
||||||
/// [`wrapping_to_fixed`] instead.
|
/// [`wrapping_to_fixed`] instead.
|
||||||
///
|
///
|
||||||
/// [`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
/// [`wrapping_to_fixed`]: #method.wrapping_to_fixed
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: sealed::Fixed>(self) -> F;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts to a fixed-point number if it fits, otherwise returns [`None`].
|
/// Converts to a fixed-point number if it fits, otherwise returns [`None`].
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
///
|
///
|
||||||
/// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
/// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: sealed::Fixed>(self) -> Option<F>;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts to a fixed-point number, saturating if it does not fit.
|
/// Converts to a fixed-point number, saturating if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: sealed::Fixed>(self) -> F;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts to a fixed-point number, wrapping if it does not fit.
|
/// Converts to a fixed-point number, wrapping if it does not fit.
|
||||||
///
|
///
|
||||||
/// Any extra fractional bits are truncated.
|
/// Any extra fractional bits are truncated.
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: sealed::Fixed>(self) -> F;
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
|
|
||||||
/// Converts from a fixed-point number.
|
/// Converts from a fixed-point number.
|
||||||
///
|
///
|
||||||
|
@ -773,45 +757,28 @@ pub trait ToFixed {
|
||||||
///
|
///
|
||||||
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
/// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html
|
||||||
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
/// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: sealed::Fixed>(self) -> (F, bool);
|
||||||
where
|
|
||||||
F: sealed::Fixed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToFixed for bool {
|
impl ToFixed for bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
ToFixed::to_fixed(u8::from(self))
|
ToFixed::to_fixed(u8::from(self))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: sealed::Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
ToFixed::checked_to_fixed(u8::from(self))
|
ToFixed::checked_to_fixed(u8::from(self))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
ToFixed::saturating_to_fixed(u8::from(self))
|
ToFixed::saturating_to_fixed(u8::from(self))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
ToFixed::wrapping_to_fixed(u8::from(self))
|
ToFixed::wrapping_to_fixed(u8::from(self))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: sealed::Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
ToFixed::overflowing_to_fixed(u8::from(self))
|
ToFixed::overflowing_to_fixed(u8::from(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -820,76 +787,46 @@ macro_rules! impl_int {
|
||||||
($Int:ident) => {
|
($Int:ident) => {
|
||||||
impl FromFixed for $Int {
|
impl FromFixed for $Int {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::from_fixed(val)
|
SealedInt::from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: sealed::Fixed>(val: F) -> Option<Self> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::checked_from_fixed(val)
|
SealedInt::checked_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::saturating_from_fixed(val)
|
SealedInt::saturating_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::wrapping_from_fixed(val)
|
SealedInt::wrapping_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: sealed::Fixed>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::overflowing_from_fixed(val)
|
SealedInt::overflowing_from_fixed(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToFixed for $Int {
|
impl ToFixed for $Int {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::to_fixed(self)
|
SealedInt::to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: sealed::Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::checked_to_fixed(self)
|
SealedInt::checked_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::saturating_to_fixed(self)
|
SealedInt::saturating_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::wrapping_to_fixed(self)
|
SealedInt::wrapping_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: sealed::Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedInt::overflowing_to_fixed(self)
|
SealedInt::overflowing_to_fixed(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -913,76 +850,46 @@ macro_rules! impl_float {
|
||||||
($Float:ty) => {
|
($Float:ty) => {
|
||||||
impl FromFixed for $Float {
|
impl FromFixed for $Float {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
val.to_float()
|
val.to_float()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: sealed::Fixed>(val: F) -> Option<Self> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
Some(val.to_float())
|
Some(val.to_float())
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
val.to_float()
|
val.to_float()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
val.to_float()
|
val.to_float()
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: sealed::Fixed>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
(val.to_float(), false)
|
(val.to_float(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToFixed for $Float {
|
impl ToFixed for $Float {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFloat::to_fixed(self)
|
SealedFloat::to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: sealed::Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFloat::checked_to_fixed(self)
|
SealedFloat::checked_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFloat::saturating_to_fixed(self)
|
SealedFloat::saturating_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFloat::wrapping_to_fixed(self)
|
SealedFloat::wrapping_to_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: sealed::Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFloat::overflowing_to_fixed(self)
|
SealedFloat::overflowing_to_fixed(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1110,38 +1017,23 @@ macro_rules! impl_fixed {
|
||||||
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed<F>(val: F) -> Self
|
fn from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::from_fixed(val)
|
SealedFixed::from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_from_fixed<F>(val: F) -> Option<Self>
|
fn checked_from_fixed<F: sealed::Fixed>(val: F) -> Option<Self> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::checked_from_fixed(val)
|
SealedFixed::checked_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_from_fixed<F>(val: F) -> Self
|
fn saturating_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_fixed(val)
|
SealedFixed::saturating_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_from_fixed<F>(val: F) -> Self
|
fn wrapping_from_fixed<F: sealed::Fixed>(val: F) -> Self {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::wrapping_from_fixed(val)
|
SealedFixed::wrapping_from_fixed(val)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_from_fixed<F>(val: F) -> (Self, bool)
|
fn overflowing_from_fixed<F: sealed::Fixed>(val: F) -> (Self, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_fixed(val)
|
SealedFixed::overflowing_from_fixed(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1151,38 +1043,23 @@ macro_rules! impl_fixed {
|
||||||
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_fixed<F>(self) -> F
|
fn to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::from_fixed(self)
|
SealedFixed::from_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn checked_to_fixed<F>(self) -> Option<F>
|
fn checked_to_fixed<F: sealed::Fixed>(self) -> Option<F> {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::checked_from_fixed(self)
|
SealedFixed::checked_from_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn saturating_to_fixed<F>(self) -> F
|
fn saturating_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::saturating_from_fixed(self)
|
SealedFixed::saturating_from_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn wrapping_to_fixed<F>(self) -> F
|
fn wrapping_to_fixed<F: sealed::Fixed>(self) -> F {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::wrapping_from_fixed(self)
|
SealedFixed::wrapping_from_fixed(self)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn overflowing_to_fixed<F>(self) -> (F, bool)
|
fn overflowing_to_fixed<F: sealed::Fixed>(self) -> (F, bool) {
|
||||||
where
|
|
||||||
F: sealed::Fixed,
|
|
||||||
{
|
|
||||||
SealedFixed::overflowing_from_fixed(self)
|
SealedFixed::overflowing_from_fixed(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,9 @@ use core::{
|
||||||
/// assert_eq!(Fix::min_value(), (max + delta).0);
|
/// assert_eq!(Fix::min_value(), (max + delta).0);
|
||||||
/// ```
|
/// ```
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Wrapping<F>(pub F)
|
pub struct Wrapping<F: Fixed>(pub F);
|
||||||
where
|
|
||||||
F: Fixed;
|
|
||||||
|
|
||||||
impl<F> Wrapping<F>
|
impl<F: Fixed> Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
/// Wrapping ceil. Rounds to the next integer towards +∞, wrapping
|
/// Wrapping ceil. Rounds to the next integer towards +∞, wrapping
|
||||||
/// on overflow.
|
/// on overflow.
|
||||||
///
|
///
|
||||||
|
@ -128,94 +123,64 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Clone for Wrapping<F>
|
impl<F: Fixed> Clone for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> Wrapping<F> {
|
fn clone(&self) -> Wrapping<F> {
|
||||||
Wrapping(self.0)
|
Wrapping(self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Copy for Wrapping<F> where F: Fixed {}
|
impl<F: Fixed> Copy for Wrapping<F> {}
|
||||||
|
|
||||||
impl<F> Default for Wrapping<F>
|
impl<F: Fixed> Default for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Wrapping<F> {
|
fn default() -> Wrapping<F> {
|
||||||
Wrapping(F::default())
|
Wrapping(F::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Hash for Wrapping<F>
|
impl<F: Fixed> Hash for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash<H>(&self, state: &mut H)
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
where
|
|
||||||
H: Hasher,
|
|
||||||
{
|
|
||||||
(self.0).hash(state);
|
(self.0).hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Debug for Wrapping<F>
|
impl<F: Fixed> Debug for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||||
<F as Debug>::fmt(&self.0, f)
|
<F as Debug>::fmt(&self.0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Display for Wrapping<F>
|
impl<F: Fixed> Display for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||||
<F as Display>::fmt(&self.0, f)
|
<F as Display>::fmt(&self.0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> From<F> for Wrapping<F>
|
impl<F: Fixed> From<F> for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(src: F) -> Wrapping<F> {
|
fn from(src: F) -> Wrapping<F> {
|
||||||
Wrapping(src)
|
Wrapping(src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Eq for Wrapping<F> where F: Fixed {}
|
impl<F: Fixed> Eq for Wrapping<F> {}
|
||||||
impl<F> PartialEq<Wrapping<F>> for Wrapping<F>
|
impl<F: Fixed> PartialEq<Wrapping<F>> for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Wrapping<F>) -> bool {
|
fn eq(&self, other: &Wrapping<F>) -> bool {
|
||||||
(self.0).eq(&other.0)
|
(self.0).eq(&other.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<F> Ord for Wrapping<F>
|
impl<F: Fixed> Ord for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self, other: &Wrapping<F>) -> Ordering {
|
fn cmp(&self, other: &Wrapping<F>) -> Ordering {
|
||||||
(self.0).cmp(&other.0)
|
(self.0).cmp(&other.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<F> PartialOrd<Wrapping<F>> for Wrapping<F>
|
impl<F: Fixed> PartialOrd<Wrapping<F>> for Wrapping<F> {
|
||||||
where
|
|
||||||
F: Fixed,
|
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &Wrapping<F>) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Wrapping<F>) -> Option<Ordering> {
|
||||||
(self.0).partial_cmp(&other.0)
|
(self.0).partial_cmp(&other.0)
|
||||||
|
|
Loading…
Reference in New Issue