make Sum and Product supertraits of Fixed

This commit is contained in:
Trevor Spiteri 2021-03-04 13:59:01 +01:00
parent f6918a36be
commit 4707482970
3 changed files with 22 additions and 6 deletions

View File

@ -99,6 +99,8 @@ The conversions supported cover the following cases.
[`from_ne_bytes`][f-fnb-1-7]
* [`to_be_bytes`][f-tbb-1-7], [`to_le_bytes`][f-tlb-1-7],
[`to_ne_bytes`][f-tnb-1-7]
* [`Sum`] and [`Product`] are now supertraits of the
[`Fixed`][tf-1-7] trait.
* The [`F128Bits`][f128-1-7] type was added to support conversions
and comparisons between fixed-point numbers and *binary128*
floating-point numbers.
@ -111,6 +113,8 @@ The conversions supported cover the following cases.
* [`OverflowingAdd`][nt-0-2-oa], [`OverflowingSub`][nt-0-2-os],
[`OverflowingMul`][nt-0-2-om]
[`Product`]: https://doc.rust-lang.org/nightly/core/iter/trait.Product.html
[`Sum`]: https://doc.rust-lang.org/nightly/core/iter/trait.Sum.html
[f-cnpot-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedU32.html#method.checked_next_power_of_two
[f-fb-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be
[f-fbb-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be_bytes

View File

@ -26,6 +26,8 @@ Version 1.7.0 (unreleased)
[`from_ne_bytes`][f-fnb-1-7]
* [`to_be_bytes`][f-tbb-1-7], [`to_le_bytes`][f-tlb-1-7],
[`to_ne_bytes`][f-tnb-1-7]
* [`Sum`] and [`Product`] are now supertraits of the
[`Fixed`][tf-1-7] trait.
* The [`F128Bits`][f128-1-7] type was added to support conversions
and comparisons between fixed-point numbers and *binary128*
floating-point numbers.
@ -577,3 +579,5 @@ Version 0.1.0 (2018-08-10)
[*az* crate]: https://crates.io/crates/az
[`MulAssign`]: https://doc.rust-lang.org/nightly/core/ops/trait.MulAssign.html
[`Product`]: https://doc.rust-lang.org/nightly/core/iter/trait.Product.html
[`Sum`]: https://doc.rust-lang.org/nightly/core/iter/trait.Sum.html

View File

@ -26,6 +26,7 @@ use crate::{
use core::{
fmt::{Binary, Debug, Display, LowerHex, Octal, UpperHex},
hash::Hash,
iter::{Product, Sum},
mem,
ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div,
@ -310,21 +311,28 @@ where
Self: Debug + Display + Binary + Octal + LowerHex + UpperHex,
Self: FromStr<Err = ParseFixedError>,
Self: FromFixed + ToFixed,
Self: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign,
Self: Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign,
Self: Add<Output = Self> + AddAssign,
Self: Sub<Output = Self> + SubAssign,
Self: Mul<Output = Self> + MulAssign,
Self: Div<Output = Self> + DivAssign,
Self: Rem<Output = Self> + RemAssign,
Self: Mul<<Self as Fixed>::Bits, Output = Self> + MulAssign<<Self as Fixed>::Bits>,
Self: Div<<Self as Fixed>::Bits, Output = Self> + DivAssign<<Self as Fixed>::Bits>,
Self: Rem<<Self as Fixed>::Bits, Output = Self> + RemAssign<<Self as Fixed>::Bits>,
Self: Not<Output = Self> + BitAnd<Output = Self> + BitAndAssign,
Self: BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign,
Self: Shl<u32, Output = Self> + ShlAssign<u32> + Shr<u32, Output = Self> + ShrAssign<u32>,
Self: Not<Output = Self>,
Self: BitAnd<Output = Self> + BitAndAssign,
Self: BitOr<Output = Self> + BitOrAssign,
Self: BitXor<Output = Self> + BitXorAssign,
Self: Shl<u32, Output = Self> + ShlAssign<u32>,
Self: Shr<u32, Output = Self> + ShrAssign<u32>,
Self: Sum + Product,
Self: PartialOrd<i8> + PartialOrd<i16> + PartialOrd<i32>,
Self: PartialOrd<i64> + PartialOrd<i128> + PartialOrd<isize>,
Self: PartialOrd<u8> + PartialOrd<u16> + PartialOrd<u32>,
Self: PartialOrd<u64> + PartialOrd<u128> + PartialOrd<usize>,
Self: PartialOrd<f16> + PartialOrd<bf16>,
Self: PartialOrd<f32> + PartialOrd<f64> + PartialOrd<F128Bits>,
Self: PartialOrd<f32> + PartialOrd<f64>,
Self: PartialOrd<F128Bits>,
Self: FixedOptionalFeatures,
Self: Sealed,
{