add constraints on Frac to ensure correct range

This commit is contained in:
Trevor Spiteri 2018-08-15 20:03:19 +02:00
parent d6d65f8af4
commit e3acd60315
7 changed files with 381 additions and 175 deletions

View File

@ -20,15 +20,18 @@ use core::ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, SubAssign,
};
use frac::Unsigned;
use frac::{IsLessOrEqual, True, U128, U16, U32, U64, U8, Unsigned};
use {
FixedHelper, FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32,
FixedU64, FixedU8,
};
macro_rules! refs {
(impl $Imp:ident for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<'a, Frac: Unsigned> $Imp<$Fixed<Frac>> for &'a $Fixed<Frac> {
(impl $Imp:ident for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<'a, Frac> $Imp<$Fixed<Frac>> for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -36,7 +39,10 @@ macro_rules! refs {
}
}
impl<'a, Frac: Unsigned> $Imp<&'a $Fixed<Frac>> for $Fixed<Frac> {
impl<'a, Frac> $Imp<&'a $Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: &$Fixed<Frac>) -> $Fixed<Frac> {
@ -44,7 +50,10 @@ macro_rules! refs {
}
}
impl<'a, 'b, Frac: Unsigned> $Imp<&'a $Fixed<Frac>> for &'b $Fixed<Frac> {
impl<'a, 'b, Frac> $Imp<&'a $Fixed<Frac>> for &'b $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: &$Fixed<Frac>) -> $Fixed<Frac> {
@ -55,8 +64,11 @@ macro_rules! refs {
}
macro_rules! refs_assign {
(impl $Imp:ident for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<'a, Frac: Unsigned> $Imp<&'a $Fixed<Frac>> for $Fixed<Frac> {
(impl $Imp:ident for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<'a, Frac> $Imp<&'a $Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn $method(&mut self, rhs: &$Fixed<Frac>) {
<$Fixed<Frac> as $Imp<$Fixed<Frac>>>::$method(self, *rhs);
@ -66,8 +78,11 @@ macro_rules! refs_assign {
}
macro_rules! pass {
(impl $Imp:ident for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<Frac: Unsigned> $Imp<$Fixed<Frac>> for $Fixed<Frac> {
(impl $Imp:ident for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<Frac> $Imp<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -78,26 +93,32 @@ macro_rules! pass {
}
}
refs! { impl $Imp for $Fixed($Inner) { $method } }
refs! { impl $Imp for $Fixed($Inner, $Len) { $method } }
};
}
macro_rules! pass_assign {
(impl $Imp:ident for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<Frac: Unsigned> $Imp<$Fixed<Frac>> for $Fixed<Frac> {
(impl $Imp:ident for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<Frac> $Imp<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn $method(&mut self, rhs: $Fixed<Frac>) {
<$Inner as $Imp<$Inner>>::$method(&mut (self.0).0, rhs.to_bits());
}
}
refs_assign! { impl $Imp for $Fixed($Inner) { $method } }
refs_assign! { impl $Imp for $Fixed($Inner, $Len) { $method } }
};
}
macro_rules! pass_one {
(impl $Imp:ident for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<Frac: Unsigned> $Imp for $Fixed<Frac> {
(impl $Imp:ident for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<Frac> $Imp for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self) -> $Fixed<Frac> {
@ -105,7 +126,10 @@ macro_rules! pass_one {
}
}
impl<'a, Frac: Unsigned> $Imp for &'a $Fixed<Frac> {
impl<'a, Frac> $Imp for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self) -> $Fixed<Frac> {
@ -116,8 +140,11 @@ macro_rules! pass_one {
}
macro_rules! shift {
(impl $Imp:ident < $Rhs:ty > for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<Frac: Unsigned> $Imp<$Rhs> for $Fixed<Frac> {
(impl $Imp:ident < $Rhs:ty > for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<Frac> $Imp<$Rhs> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: $Rhs) -> $Fixed<Frac> {
@ -125,7 +152,10 @@ macro_rules! shift {
}
}
impl<'a, Frac: Unsigned> $Imp<$Rhs> for &'a $Fixed<Frac> {
impl<'a, Frac> $Imp<$Rhs> for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: $Rhs) -> $Fixed<Frac> {
@ -133,7 +163,10 @@ macro_rules! shift {
}
}
impl<'a, Frac: Unsigned> $Imp<&'a $Rhs> for $Fixed<Frac> {
impl<'a, Frac> $Imp<&'a $Rhs> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: &$Rhs) -> $Fixed<Frac> {
@ -141,7 +174,10 @@ macro_rules! shift {
}
}
impl<'a, 'b, Frac: Unsigned> $Imp<&'a $Rhs> for &'b $Fixed<Frac> {
impl<'a, 'b, Frac> $Imp<&'a $Rhs> for &'b $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn $method(self, rhs: &$Rhs) -> $Fixed<Frac> {
@ -152,15 +188,21 @@ macro_rules! shift {
}
macro_rules! shift_assign {
(impl $Imp:ident < $Rhs:ty > for $Fixed:ident($Inner:ty) { $method:ident }) => {
impl<Frac: Unsigned> $Imp<$Rhs> for $Fixed<Frac> {
(impl $Imp:ident < $Rhs:ty > for $Fixed:ident($Inner:ty, $Len:ty) { $method:ident }) => {
impl<Frac> $Imp<$Rhs> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn $method(&mut self, rhs: $Rhs) {
<$Inner as $Imp<$Rhs>>::$method(&mut (self.0).0, rhs);
}
}
impl<'a, Frac: Unsigned> $Imp<&'a $Rhs> for $Fixed<Frac> {
impl<'a, Frac> $Imp<&'a $Rhs> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn $method(&mut self, rhs: &$Rhs) {
<$Fixed<Frac> as $Imp<$Rhs>>::$method(self, *rhs);
@ -172,26 +214,29 @@ macro_rules! shift_assign {
macro_rules! shift_all {
(
impl {$Imp:ident, $ImpAssign:ident}<{$($Rhs:ty),*}>
for $Fixed:ident($Inner:ty)
for $Fixed:ident($Inner:ty, $Len:ty)
{ $method:ident, $method_assign:ident }
) => { $(
shift! { impl $Imp<$Rhs> for $Fixed($Inner) { $method } }
shift_assign! { impl $ImpAssign<$Rhs> for $Fixed($Inner) { $method_assign } }
shift! { impl $Imp<$Rhs> for $Fixed($Inner, $Len) { $method } }
shift_assign! { impl $ImpAssign<$Rhs> for $Fixed($Inner, $Len) { $method_assign } }
)* };
}
macro_rules! fixed_arith {
($Fixed:ident($Inner:ty, $bits_count:expr), $Signedness:tt) => {
($Fixed:ident($Inner:ty, $Len:ty, $bits_count:expr), $Signedness:tt) => {
if_signed! {
$Signedness => pass_one! { impl Neg for $Fixed($Inner) { neg } }
$Signedness => pass_one! { impl Neg for $Fixed($Inner, $Len) { neg } }
}
pass! { impl Add for $Fixed($Inner) { add } }
pass_assign! { impl AddAssign for $Fixed($Inner) { add_assign } }
pass! { impl Sub for $Fixed($Inner) { sub } }
pass_assign! { impl SubAssign for $Fixed($Inner) { sub_assign } }
pass! { impl Add for $Fixed($Inner, $Len) { add } }
pass_assign! { impl AddAssign for $Fixed($Inner, $Len) { add_assign } }
pass! { impl Sub for $Fixed($Inner, $Len) { sub } }
pass_assign! { impl SubAssign for $Fixed($Inner, $Len) { sub_assign } }
impl<Frac: Unsigned> Mul<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> Mul<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -201,18 +246,24 @@ macro_rules! fixed_arith {
}
}
refs! { impl Mul for $Fixed($Inner) { mul } }
refs! { impl Mul for $Fixed($Inner, $Len) { mul } }
impl<Frac: Unsigned> MulAssign<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> MulAssign<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn mul_assign(&mut self, rhs: $Fixed<Frac>) {
*self = <$Fixed<Frac> as Mul<$Fixed<Frac>>>::mul(*self, rhs)
}
}
refs_assign! { impl MulAssign for $Fixed($Inner) { mul_assign } }
refs_assign! { impl MulAssign for $Fixed($Inner, $Len) { mul_assign } }
impl<Frac: Unsigned> Div<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> Div<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn div(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -222,26 +273,32 @@ macro_rules! fixed_arith {
}
}
refs! { impl Div for $Fixed($Inner) { div } }
refs! { impl Div for $Fixed($Inner, $Len) { div } }
impl<Frac: Unsigned> DivAssign<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> DivAssign<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn div_assign(&mut self, rhs: $Fixed<Frac>) {
*self = <$Fixed<Frac> as Div<$Fixed<Frac>>>::div(*self, rhs)
}
}
refs_assign! { impl DivAssign for $Fixed($Inner) { div_assign } }
refs_assign! { impl DivAssign for $Fixed($Inner, $Len) { div_assign } }
pass_one! { impl Not for $Fixed($Inner) { not } }
pass! { impl BitAnd for $Fixed($Inner) { bitand } }
pass_assign! { impl BitAndAssign for $Fixed($Inner) { bitand_assign } }
pass! { impl BitOr for $Fixed($Inner) { bitor } }
pass_assign! { impl BitOrAssign for $Fixed($Inner) { bitor_assign } }
pass! { impl BitXor for $Fixed($Inner) { bitxor } }
pass_assign! { impl BitXorAssign for $Fixed($Inner) { bitxor_assign } }
pass_one! { impl Not for $Fixed($Inner, $Len) { not } }
pass! { impl BitAnd for $Fixed($Inner, $Len) { bitand } }
pass_assign! { impl BitAndAssign for $Fixed($Inner, $Len) { bitand_assign } }
pass! { impl BitOr for $Fixed($Inner, $Len) { bitor } }
pass_assign! { impl BitOrAssign for $Fixed($Inner, $Len) { bitor_assign } }
pass! { impl BitXor for $Fixed($Inner, $Len) { bitxor } }
pass_assign! { impl BitXorAssign for $Fixed($Inner, $Len) { bitxor_assign } }
impl<Frac: Unsigned> Mul<$Inner> for $Fixed<Frac> {
impl<Frac> Mul<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: $Inner) -> $Fixed<Frac> {
@ -249,7 +306,10 @@ macro_rules! fixed_arith {
}
}
impl<Frac: Unsigned> Mul<$Fixed<Frac>> for $Inner {
impl<Frac> Mul<$Fixed<Frac>> for $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -257,7 +317,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Mul<$Inner> for &'a $Fixed<Frac> {
impl<'a, Frac> Mul<$Inner> for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: $Inner) -> $Fixed<Frac> {
@ -265,7 +328,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Mul<&'a $Fixed<Frac>> for $Inner {
impl<'a, Frac> Mul<&'a $Fixed<Frac>> for $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: &$Fixed<Frac>) -> $Fixed<Frac> {
@ -273,7 +339,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Mul<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> Mul<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: &$Inner) -> $Fixed<Frac> {
@ -281,7 +350,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Mul<$Fixed<Frac>> for &'a $Inner {
impl<'a, Frac> Mul<$Fixed<Frac>> for &'a $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: $Fixed<Frac>) -> $Fixed<Frac> {
@ -289,7 +361,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, 'b, Frac: Unsigned> Mul<&'a $Inner> for &'b $Fixed<Frac> {
impl<'a, 'b, Frac> Mul<&'a $Inner> for &'b $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: &$Inner) -> $Fixed<Frac> {
@ -297,7 +372,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, 'b, Frac: Unsigned> Mul<&'a $Fixed<Frac>> for &'b $Inner {
impl<'a, 'b, Frac> Mul<&'a $Fixed<Frac>> for &'b $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn mul(self, rhs: &$Fixed<Frac>) -> $Fixed<Frac> {
@ -305,21 +383,30 @@ macro_rules! fixed_arith {
}
}
impl<Frac: Unsigned> MulAssign<$Inner> for $Fixed<Frac> {
impl<Frac> MulAssign<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn mul_assign(&mut self, rhs: $Inner) {
*self = <$Fixed<Frac> as Mul<$Inner>>::mul(*self, rhs)
}
}
impl<'a, Frac: Unsigned> MulAssign<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> MulAssign<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn mul_assign(&mut self, rhs: &$Inner) {
*self = <$Fixed<Frac> as Mul<$Inner>>::mul(*self, *rhs)
}
}
impl<Frac: Unsigned> Div<$Inner> for $Fixed<Frac> {
impl<Frac> Div<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn div(self, rhs: $Inner) -> $Fixed<Frac> {
@ -327,7 +414,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Div<$Inner> for &'a $Fixed<Frac> {
impl<'a, Frac> Div<$Inner> for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn div(self, rhs: $Inner) -> $Fixed<Frac> {
@ -335,14 +425,20 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Div<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> Div<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn div(self, rhs: &$Inner) -> $Fixed<Frac> {
<$Fixed<Frac> as Div<$Inner>>::div(self, *rhs)
}
}
impl<'a, 'b, Frac: Unsigned> Div<&'a $Inner> for &'b $Fixed<Frac> {
impl<'a, 'b, Frac> Div<&'a $Inner> for &'b $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn div(self, rhs: &$Inner) -> $Fixed<Frac> {
@ -350,21 +446,30 @@ macro_rules! fixed_arith {
}
}
impl<Frac: Unsigned> DivAssign<$Inner> for $Fixed<Frac> {
impl<Frac> DivAssign<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn div_assign(&mut self, rhs: $Inner) {
*self = <$Fixed<Frac> as Div<$Inner>>::div(*self, rhs)
}
}
impl<'a, Frac: Unsigned> DivAssign<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> DivAssign<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn div_assign(&mut self, rhs: &$Inner) {
*self = <$Fixed<Frac> as Div<$Inner>>::div(*self, *rhs)
}
}
impl<Frac: Unsigned> Rem<$Inner> for $Fixed<Frac> {
impl<Frac> Rem<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn rem(self, rhs: $Inner) -> $Fixed<Frac> {
@ -372,7 +477,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Rem<$Inner> for &'a $Fixed<Frac> {
impl<'a, Frac> Rem<$Inner> for &'a $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn rem(self, rhs: $Inner) -> $Fixed<Frac> {
@ -380,14 +488,21 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned> Rem<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> Rem<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn rem(self, rhs: &$Inner) -> $Fixed<Frac> {
<$Fixed<Frac> as Rem<$Inner>>::rem(self, *rhs)
}
}
impl<'a, 'b, Frac: Unsigned> Rem<&'a $Inner> for &'b $Fixed<Frac> {
impl<'a, 'b, Frac> Rem<&'a $Inner> for &'b $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type Output = $Fixed<Frac>;
#[inline]
fn rem(self, rhs: &$Inner) -> $Fixed<Frac> {
@ -395,14 +510,20 @@ macro_rules! fixed_arith {
}
}
impl<Frac: Unsigned> RemAssign<$Inner> for $Fixed<Frac> {
impl<Frac> RemAssign<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn rem_assign(&mut self, rhs: $Inner) {
*self = <$Fixed<Frac> as Rem<$Inner>>::rem(*self, rhs)
}
}
impl<'a, Frac: Unsigned> RemAssign<&'a $Inner> for $Fixed<Frac> {
impl<'a, Frac> RemAssign<&'a $Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn rem_assign(&mut self, rhs: &$Inner) {
*self = <$Fixed<Frac> as Rem<$Inner>>::rem(*self, *rhs)
@ -412,31 +533,40 @@ macro_rules! fixed_arith {
shift_all! {
impl {Shl, ShlAssign}<{
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize
}> for $Fixed($Inner) {
}> for $Fixed($Inner, $Len) {
shl, shl_assign
}
}
shift_all! {
impl {Shr, ShrAssign}<{
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize
}> for $Fixed($Inner) {
}> for $Fixed($Inner, $Len) {
shr, shr_assign
}
}
impl<Frac: Unsigned> Sum<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> Sum<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn sum<I: Iterator<Item = $Fixed<Frac>>>(iter: I) -> $Fixed<Frac> {
iter.fold($Fixed::from_bits(0), Add::add)
}
}
impl<'a, Frac: Unsigned + 'a> Sum<&'a $Fixed<Frac>> for $Fixed<Frac> {
impl<'a, Frac> Sum<&'a $Fixed<Frac>> for $Fixed<Frac>
where
Frac: 'a + Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn sum<I: Iterator<Item = &'a $Fixed<Frac>>>(iter: I) -> $Fixed<Frac> {
iter.fold($Fixed::from_bits(0), Add::add)
}
}
impl<Frac: Unsigned> Product<$Fixed<Frac>> for $Fixed<Frac> {
impl<Frac> Product<$Fixed<Frac>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn product<I: Iterator<Item = $Fixed<Frac>>>(mut iter: I) -> $Fixed<Frac> {
match iter.next() {
None => <$Fixed<Frac> as FixedHelper<Frac>>::one().expect("overflow"),
@ -445,7 +575,10 @@ macro_rules! fixed_arith {
}
}
impl<'a, Frac: Unsigned + 'a> Product<&'a $Fixed<Frac>> for $Fixed<Frac> {
impl<'a, Frac> Product<&'a $Fixed<Frac>> for $Fixed<Frac>
where
Frac: 'a + Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn product<I: Iterator<Item = &'a $Fixed<Frac>>>(mut iter: I) -> $Fixed<Frac> {
match iter.next() {
None => <$Fixed<Frac> as FixedHelper<Frac>>::one().expect("overflow"),
@ -456,16 +589,16 @@ macro_rules! fixed_arith {
};
}
fixed_arith! { FixedU8(u8, 8), Unsigned }
fixed_arith! { FixedU16(u16, 16), Unsigned }
fixed_arith! { FixedU32(u32, 32), Unsigned }
fixed_arith! { FixedU64(u64, 64), Unsigned }
fixed_arith! { FixedU128(u128, 128), Unsigned }
fixed_arith! { FixedI8(i8, 8), Signed }
fixed_arith! { FixedI16(i16, 16), Signed }
fixed_arith! { FixedI32(i32, 32), Signed }
fixed_arith! { FixedI64(i64, 64), Signed }
fixed_arith! { FixedI128(i128, 128), Signed }
fixed_arith! { FixedU8(u8, U8, 8), Unsigned }
fixed_arith! { FixedU16(u16, U16, 16), Unsigned }
fixed_arith! { FixedU32(u32, U32, 32), Unsigned }
fixed_arith! { FixedU64(u64, U64, 64), Unsigned }
fixed_arith! { FixedU128(u128, U128, 128), Unsigned }
fixed_arith! { FixedI8(i8, U8, 8), Signed }
fixed_arith! { FixedI16(i16, U16, 16), Signed }
fixed_arith! { FixedI32(i32, U32, 32), Signed }
fixed_arith! { FixedI64(i64, U64, 64), Signed }
fixed_arith! { FixedI128(i128, U128, 128), Signed }
pub(crate) trait MulDivDir: Sized {
fn mul_dir(self, rhs: Self, frac_bits: u32) -> (Self, Ordering);

View File

@ -14,17 +14,21 @@
// <https://opensource.org/licenses/MIT>.
use core::cmp::Ordering;
use frac::{self, Unsigned};
use frac::{self, IsLessOrEqual, True, U128, U16, U32, U64, U8, Unsigned};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
};
macro_rules! fixed_cmp {
($Fixed:ident($Inner:ty, $bits_count:expr)) => {
impl<Frac: Unsigned> Eq for $Fixed<Frac> {}
($Fixed:ident($Inner:ty, $Len:ty, $bits_count:expr)) => {
impl<Frac> Eq for $Fixed<Frac> where Frac: Unsigned + IsLessOrEqual<$Len, Output = True> {}
impl<Frac: Unsigned, FracRhs: Unsigned> PartialEq<$Fixed<FracRhs>> for $Fixed<Frac> {
impl<Frac, FracRhs> PartialEq<$Fixed<FracRhs>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
FracRhs: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn eq(&self, rhs: &$Fixed<FracRhs>) -> bool {
let (fl, fr) = (Frac::to_u32(), FracRhs::to_u32());
@ -46,28 +50,41 @@ macro_rules! fixed_cmp {
}
}
impl<Frac: Unsigned> PartialEq<$Inner> for $Fixed<Frac> {
impl<Frac> PartialEq<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn eq(&self, rhs: &$Inner) -> bool {
<$Fixed<Frac> as PartialEq<$Fixed<frac::U0>>>::eq(self, &$Fixed::from_bits(*rhs))
}
}
impl<Frac: Unsigned> PartialEq<$Fixed<Frac>> for $Inner {
impl<Frac> PartialEq<$Fixed<Frac>> for $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn eq(&self, rhs: &$Fixed<Frac>) -> bool {
<$Fixed<frac::U0> as PartialEq<$Fixed<Frac>>>::eq(&$Fixed::from_bits(*self), rhs)
}
}
impl<Frac: Unsigned> Ord for $Fixed<Frac> {
impl<Frac> Ord for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn cmp(&self, rhs: &$Fixed<Frac>) -> Ordering {
self.to_bits().cmp(&rhs.to_bits())
}
}
impl<Frac: Unsigned, FracRhs: Unsigned> PartialOrd<$Fixed<FracRhs>> for $Fixed<Frac> {
impl<Frac, FracRhs> PartialOrd<$Fixed<FracRhs>> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
FracRhs: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn partial_cmp(&self, rhs: &$Fixed<FracRhs>) -> Option<Ordering> {
let (fl, fr) = (Frac::to_u32(), FracRhs::to_u32());
@ -147,7 +164,10 @@ macro_rules! fixed_cmp {
}
}
impl<Frac: Unsigned> PartialOrd<$Inner> for $Fixed<Frac> {
impl<Frac> PartialOrd<$Inner> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn partial_cmp(&self, rhs: &$Inner) -> Option<Ordering> {
self.partial_cmp(&$Fixed::<frac::U0>::from_bits(*rhs))
@ -174,7 +194,10 @@ macro_rules! fixed_cmp {
}
}
impl<Frac: Unsigned> PartialOrd<$Fixed<Frac>> for $Inner {
impl<Frac> PartialOrd<$Fixed<Frac>> for $Inner
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn partial_cmp(&self, rhs: &$Fixed<Frac>) -> Option<Ordering> {
$Fixed::<frac::U0>::from_bits(*self).partial_cmp(rhs)
@ -203,16 +226,16 @@ macro_rules! fixed_cmp {
};
}
fixed_cmp! { FixedU8(u8, 8) }
fixed_cmp! { FixedU16(u16, 16) }
fixed_cmp! { FixedU32(u32, 32) }
fixed_cmp! { FixedU64(u64, 64) }
fixed_cmp! { FixedU128(u128, 128) }
fixed_cmp! { FixedI8(i8, 8) }
fixed_cmp! { FixedI16(i16, 16) }
fixed_cmp! { FixedI32(i32, 32) }
fixed_cmp! { FixedI64(i64, 64) }
fixed_cmp! { FixedI128(i128, 128) }
fixed_cmp! { FixedU8(u8, U8, 8) }
fixed_cmp! { FixedU16(u16, U16, 16) }
fixed_cmp! { FixedU32(u32, U32, 32) }
fixed_cmp! { FixedU64(u64, U64, 64) }
fixed_cmp! { FixedU128(u128, U128, 128) }
fixed_cmp! { FixedI8(i8, U8, 8) }
fixed_cmp! { FixedI16(i16, U16, 16) }
fixed_cmp! { FixedI32(i32, U32, 32) }
fixed_cmp! { FixedI64(i64, U64, 64) }
fixed_cmp! { FixedI128(i128, U128, 128) }
#[cfg(test)]
mod tests {

View File

@ -19,7 +19,7 @@ use core::fmt::{
};
use core::mem;
use core::str;
use frac::Unsigned;
use frac::{IsLessOrEqual, True, U128, U16, U32, U64, U8, Unsigned};
use FixedHelper;
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
@ -170,33 +170,56 @@ where
}
macro_rules! impl_fmt {
($($Fixed:ident)*) => { $(
impl<Frac: Unsigned> Display for $Fixed<Frac> {
($($Fixed:ident($Len:ty))*) => { $(
impl<Frac> Display for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_dec(*self, f)
}
}
impl<Frac: Unsigned> Debug for $Fixed<Frac> {
impl<Frac> Debug for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_dec(*self, f)
}
}
impl<Frac: Unsigned> Binary for $Fixed<Frac> {
impl<Frac> Binary for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_radix2(*self, &Bin, f)
}
}
impl<Frac: Unsigned> Octal for $Fixed<Frac> {
impl<Frac> Octal for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_radix2(*self, &Oct, f)
}
}
impl<Frac: Unsigned> LowerHex for $Fixed<Frac> {
impl<Frac> LowerHex for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_radix2(*self, &LowHex, f)
}
}
impl<Frac: Unsigned> UpperHex for $Fixed<Frac> {
impl<Frac> UpperHex for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fmt_radix2(*self, &UpHex, f)
}
@ -204,8 +227,8 @@ macro_rules! impl_fmt {
)* };
}
impl_fmt!{ FixedU8 FixedU16 FixedU32 FixedU64 FixedU128 }
impl_fmt!{ FixedI8 FixedI16 FixedI32 FixedI64 FixedI128 }
impl_fmt!{ FixedU8(U8) FixedU16(U16) FixedU32(U32) FixedU64(U64) FixedU128(U128) }
impl_fmt!{ FixedI8(U8) FixedI16(U16) FixedI32(U32) FixedI64(U64) FixedI128(U128) }
fn dec_int_digits(int_bits: u32) -> u32 {
assert!(int_bits < 299);

View File

@ -14,7 +14,7 @@
// <https://opensource.org/licenses/MIT>.
use core::mem;
use frac::Unsigned;
use frac::{IsLessOrEqual, True, U16, U32, U8, Unsigned};
use helper::FloatHelper;
use {FixedI16, FixedI32, FixedI8, FixedU16, FixedU32, FixedU8};
@ -168,8 +168,11 @@ macro_rules! float_conv {
float_conv! { u8 u16 u32 u64 u128 }
macro_rules! lossless_from_fixed {
($Fixed:ident:: $method:ident -> $Float:ident) => {
impl<Frac: Unsigned> From<$Fixed<Frac>> for $Float {
($Fixed:ident($Len:ty):: $method:ident -> $Float:ident) => {
impl<Frac> From<$Fixed<Frac>> for $Float
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn from(src: $Fixed<Frac>) -> $Float {
src.$method()
@ -178,16 +181,16 @@ macro_rules! lossless_from_fixed {
};
}
lossless_from_fixed! { FixedI8::to_f32 -> f32 }
lossless_from_fixed! { FixedI16::to_f32 -> f32 }
lossless_from_fixed! { FixedU8::to_f32 -> f32 }
lossless_from_fixed! { FixedU16::to_f32 -> f32 }
lossless_from_fixed! { FixedI8::to_f64 -> f64 }
lossless_from_fixed! { FixedI16::to_f64 -> f64 }
lossless_from_fixed! { FixedI32::to_f64 -> f64 }
lossless_from_fixed! { FixedU8::to_f64 -> f64 }
lossless_from_fixed! { FixedU16::to_f64 -> f64 }
lossless_from_fixed! { FixedU32::to_f64 -> f64 }
lossless_from_fixed! { FixedI8(U8)::to_f32 -> f32 }
lossless_from_fixed! { FixedI16(U16)::to_f32 -> f32 }
lossless_from_fixed! { FixedU8(U8)::to_f32 -> f32 }
lossless_from_fixed! { FixedU16(U16)::to_f32 -> f32 }
lossless_from_fixed! { FixedI8(U8)::to_f64 -> f64 }
lossless_from_fixed! { FixedI16(U16)::to_f64 -> f64 }
lossless_from_fixed! { FixedI32(U32)::to_f64 -> f64 }
lossless_from_fixed! { FixedU8(U8)::to_f64 -> f64 }
lossless_from_fixed! { FixedU16(U16)::to_f64 -> f64 }
lossless_from_fixed! { FixedU32(U32)::to_f64 -> f64 }
#[cfg(test)]
mod tests {

View File

@ -20,12 +20,12 @@ This module reexports items from the [*typenum* crate].
*/
pub use typenum::{
U0, U1, U10, U100, U101, U102, U103, U104, U105, U106, U107, U108, U109, U11, U110, U111, U112,
U113, U114, U115, U116, U117, U118, U119, U12, U120, U121, U122, U123, U124, U125, U126, U127,
U128, U13, U14, U15, U16, U17, U18, U19, U2, U20, U21, U22, U23, U24, U25, U26, U27, U28, U29,
U3, U30, U31, U32, U33, U34, U35, U36, U37, U38, U39, U4, U40, U41, U42, U43, U44, U45, U46,
U47, U48, U49, U5, U50, U51, U52, U53, U54, U55, U56, U57, U58, U59, U6, U60, U61, U62, U63,
U64, U65, U66, U67, U68, U69, U7, U70, U71, U72, U73, U74, U75, U76, U77, U78, U79, U8, U80,
U81, U82, U83, U84, U85, U86, U87, U88, U89, U9, U90, U91, U92, U93, U94, U95, U96, U97, U98,
U99, Unsigned,
IsLessOrEqual, True, U0, U1, U10, U100, U101, U102, U103, U104, U105, U106, U107, U108, U109,
U11, U110, U111, U112, U113, U114, U115, U116, U117, U118, U119, U12, U120, U121, U122, U123,
U124, U125, U126, U127, U128, U13, U14, U15, U16, U17, U18, U19, U2, U20, U21, U22, U23, U24,
U25, U26, U27, U28, U29, U3, U30, U31, U32, U33, U34, U35, U36, U37, U38, U39, U4, U40, U41,
U42, U43, U44, U45, U46, U47, U48, U49, U5, U50, U51, U52, U53, U54, U55, U56, U57, U58, U59,
U6, U60, U61, U62, U63, U64, U65, U66, U67, U68, U69, U7, U70, U71, U72, U73, U74, U75, U76,
U77, U78, U79, U8, U80, U81, U82, U83, U84, U85, U86, U87, U88, U89, U9, U90, U91, U92, U93,
U94, U95, U96, U97, U98, U99, Unsigned,
};

View File

@ -14,7 +14,7 @@
// <https://opensource.org/licenses/MIT>.
use core::mem;
use frac::Unsigned;
use frac::{IsLessOrEqual, True, U128, U16, U32, U64, U8, Unsigned};
use {
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
FixedU8,
@ -113,7 +113,10 @@ macro_rules! float_helper {
float_helper! { f32(u32, 24) }
float_helper! { f64(u64, 53) }
pub(crate) trait FixedHelper<Frac: Unsigned>: Sized {
pub(crate) trait FixedHelper<Frac>: Sized
where
Frac: Unsigned,
{
type UInner;
#[inline]
@ -129,8 +132,11 @@ pub(crate) trait FixedHelper<Frac: Unsigned>: Sized {
}
macro_rules! fixed_num_unsigned {
($Fixed:ident($UInner:ty)) => {
impl<Frac: Unsigned> FixedHelper<Frac> for $Fixed<Frac> {
($Fixed:ident($UInner:ty, $Len:ty)) => {
impl<Frac> FixedHelper<Frac> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type UInner = $UInner;
#[inline]
@ -191,8 +197,11 @@ macro_rules! fixed_num_unsigned {
}
macro_rules! fixed_num_signed {
($Fixed:ident($UInner:ty)) => {
impl<Frac: Unsigned> FixedHelper<Frac> for $Fixed<Frac> {
($Fixed:ident($UInner:ty, $Len:ty)) => {
impl<Frac> FixedHelper<Frac> for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
type UInner = $UInner;
#[inline]
@ -269,13 +278,13 @@ macro_rules! fixed_num_signed {
};
}
fixed_num_unsigned! { FixedU8(u8) }
fixed_num_unsigned! { FixedU16(u16) }
fixed_num_unsigned! { FixedU32(u32) }
fixed_num_unsigned! { FixedU64(u64) }
fixed_num_unsigned! { FixedU128(u128) }
fixed_num_signed! { FixedI8(u8) }
fixed_num_signed! { FixedI16(u16) }
fixed_num_signed! { FixedI32(u32) }
fixed_num_signed! { FixedI64(u64) }
fixed_num_signed! { FixedI128(u128) }
fixed_num_unsigned! { FixedU8(u8, U8) }
fixed_num_unsigned! { FixedU16(u16, U16) }
fixed_num_unsigned! { FixedU32(u32, U32) }
fixed_num_unsigned! { FixedU64(u64, U64) }
fixed_num_unsigned! { FixedU128(u128, U128) }
fixed_num_signed! { FixedI8(u8, U8) }
fixed_num_signed! { FixedI16(u16, U16) }
fixed_num_signed! { FixedI32(u32, U32) }
fixed_num_signed! { FixedI64(u64, U64) }
fixed_num_signed! { FixedI128(u128, U128) }

View File

@ -149,7 +149,7 @@ use core::f64;
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;
use float::FloatConv;
use frac::Unsigned;
use frac::{IsLessOrEqual, True, U128, U16, U32, U64, U8, Unsigned};
use helper::FixedHelper;
macro_rules! pass_method {
@ -355,7 +355,7 @@ macro_rules! to_float {
}
macro_rules! fixed {
($description:expr, $Fixed:ident($Inner:ty, $bits_count:expr), $Signedness:tt) => {
($description:expr, $Fixed:ident($Inner:ty, $Len:ty, $bits_count:expr), $Signedness:tt) => {
doc_comment! {
concat!(
$description,
@ -382,26 +382,40 @@ macro_rules! fixed {
"[typenum crate]: https://crates.io/crates/typenum\n"
),
#[repr(transparent)]
pub struct $Fixed<Frac: Unsigned>(($Inner, PhantomData<Frac>));
pub struct $Fixed<Frac>(($Inner, PhantomData<Frac>))
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>;
}
impl<Frac: Unsigned> Clone for $Fixed<Frac> {
impl<Frac> Clone for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn clone(&self) -> $Fixed<Frac> {
$Fixed::from_bits(self.to_bits())
}
}
impl<Frac: Unsigned> Copy for $Fixed<Frac> {}
impl<Frac> Copy for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{}
impl<Frac: Unsigned> Default for $Fixed<Frac> {
impl<Frac> Default for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn default() -> $Fixed<Frac> {
$Fixed::from_bits(<$Inner as Default>::default())
}
}
impl<Frac: Unsigned> Hash for $Fixed<Frac> {
impl<Frac> Hash for $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
#[inline]
fn hash<H>(&self, state: &mut H)
where
@ -411,7 +425,10 @@ macro_rules! fixed {
}
}
impl<Frac: Unsigned> $Fixed<Frac> {
impl<Frac> $Fixed<Frac>
where
Frac: Unsigned + IsLessOrEqual<$Len, Output = True>,
{
pass_method_signed_unsigned! {
$Signedness,
concat!(
@ -514,8 +531,6 @@ macro_rules! fixed {
),
#[inline]
pub fn from_bits(v: $Inner) -> $Fixed<Frac> {
let int_frac_bits = <$Fixed<Frac> as FixedHelper<Frac>>::int_frac_bits();
assert!(Frac::to_u32() <= int_frac_bits, "`Frac` too large");
$Fixed((v, PhantomData))
}
}
@ -1448,16 +1463,16 @@ macro_rules! fixed {
};
}
fixed! { "An eight-bit fixed-point unsigned integer", FixedU8(u8, 8), Unsigned }
fixed! { "A 16-bit fixed-point unsigned integer", FixedU16(u16, 16), Unsigned }
fixed! { "A 32-bit fixed-point unsigned integer", FixedU32(u32, 32), Unsigned }
fixed! { "A 64-bit fixed-point unsigned integer", FixedU64(u64, 64), Unsigned }
fixed! { "A 128-bit fixed-point unsigned integer", FixedU128(u128, 128), Unsigned }
fixed! { "An eight-bit fixed-point signed integer", FixedI8(i8, 8), Signed }
fixed! { "A 16-bit fixed-point signed integer", FixedI16(i16, 16), Signed }
fixed! { "A 32-bit fixed-point signed integer", FixedI32(i32, 32), Signed }
fixed! { "A 64-bit fixed-point signed integer", FixedI64(i64, 64), Signed }
fixed! { "A 128-bit fixed-point signed integer", FixedI128(i128, 128), Signed }
fixed! { "An eight-bit fixed-point unsigned integer", FixedU8(u8, U8, 8), Unsigned }
fixed! { "A 16-bit fixed-point unsigned integer", FixedU16(u16, U16, 16), Unsigned }
fixed! { "A 32-bit fixed-point unsigned integer", FixedU32(u32, U32, 32), Unsigned }
fixed! { "A 64-bit fixed-point unsigned integer", FixedU64(u64, U64, 64), Unsigned }
fixed! { "A 128-bit fixed-point unsigned integer", FixedU128(u128, U128, 128), Unsigned }
fixed! { "An eight-bit fixed-point signed integer", FixedI8(i8, U8, 8), Signed }
fixed! { "A 16-bit fixed-point signed integer", FixedI16(i16, U16, 16), Signed }
fixed! { "A 32-bit fixed-point signed integer", FixedI32(i32, U32, 32), Signed }
fixed! { "A 64-bit fixed-point signed integer", FixedI64(i64, U64, 64), Signed }
fixed! { "A 128-bit fixed-point signed integer", FixedI128(i128, U128, 128), Signed }
#[cfg(test)]
mod tests {