use crate::rounding::RoundingMode;
pub trait Decimal:
Copy
+ PartialEq
+ Eq
+ PartialOrd
+ Ord
+ Default
+ core::fmt::Debug
+ core::fmt::Display
+ core::hash::Hash
+ core::ops::Add<Output = Self>
+ core::ops::Sub<Output = Self>
+ core::ops::Mul<Output = Self>
+ core::ops::Div<Output = Self>
+ core::ops::Rem<Output = Self>
+ core::ops::Neg<Output = Self>
+ core::ops::AddAssign
+ core::ops::SubAssign
+ core::ops::MulAssign
+ core::ops::DivAssign
+ core::ops::RemAssign
+ core::ops::BitAnd<Output = Self>
+ core::ops::BitOr<Output = Self>
+ core::ops::BitXor<Output = Self>
+ core::ops::Not<Output = Self>
+ core::ops::Shl<u32, Output = Self>
+ core::ops::Shr<u32, Output = Self>
{
type Storage: Copy + PartialEq + Eq;
const SCALE: u32;
const MAX_SCALE: u32;
const ZERO: Self;
const ONE: Self;
const MAX: Self;
const MIN: Self;
fn multiplier() -> Self::Storage;
fn from_bits(raw: Self::Storage) -> Self;
fn to_bits(self) -> Self::Storage;
fn scale(self) -> u32;
fn abs(self) -> Self;
fn signum(self) -> Self;
fn is_positive(self) -> bool;
fn is_negative(self) -> bool;
fn is_nan(self) -> bool;
fn is_infinite(self) -> bool;
fn is_finite(self) -> bool;
fn div_euclid(self, rhs: Self) -> Self;
fn rem_euclid(self, rhs: Self) -> Self;
fn div_floor(self, rhs: Self) -> Self;
fn div_ceil(self, rhs: Self) -> Self;
fn abs_diff(self, rhs: Self) -> Self;
fn midpoint(self, rhs: Self) -> Self;
fn mul_add(self, a: Self, b: Self) -> Self;
fn pow(self, exp: u32) -> Self;
fn powi(self, exp: i32) -> Self;
fn checked_pow(self, exp: u32) -> Option<Self>;
fn wrapping_pow(self, exp: u32) -> Self;
fn saturating_pow(self, exp: u32) -> Self;
fn overflowing_pow(self, exp: u32) -> (Self, bool);
fn checked_add(self, rhs: Self) -> Option<Self>;
fn checked_sub(self, rhs: Self) -> Option<Self>;
fn checked_mul(self, rhs: Self) -> Option<Self>;
fn checked_div(self, rhs: Self) -> Option<Self>;
fn checked_neg(self) -> Option<Self>;
fn checked_rem(self, rhs: Self) -> Option<Self>;
fn wrapping_add(self, rhs: Self) -> Self;
fn wrapping_sub(self, rhs: Self) -> Self;
fn wrapping_mul(self, rhs: Self) -> Self;
fn wrapping_div(self, rhs: Self) -> Self;
fn wrapping_neg(self) -> Self;
fn wrapping_rem(self, rhs: Self) -> Self;
fn saturating_add(self, rhs: Self) -> Self;
fn saturating_sub(self, rhs: Self) -> Self;
fn saturating_mul(self, rhs: Self) -> Self;
fn saturating_div(self, rhs: Self) -> Self;
fn saturating_neg(self) -> Self;
fn overflowing_add(self, rhs: Self) -> (Self, bool);
fn overflowing_sub(self, rhs: Self) -> (Self, bool);
fn overflowing_mul(self, rhs: Self) -> (Self, bool);
fn overflowing_div(self, rhs: Self) -> (Self, bool);
fn overflowing_neg(self) -> (Self, bool);
fn overflowing_rem(self, rhs: Self) -> (Self, bool);
fn from_i32(value: i32) -> Self;
fn to_int(self) -> i64;
fn to_int_with(self, mode: RoundingMode) -> i64;
#[cfg(feature = "std")]
fn from_f64(value: f64) -> Self;
#[cfg(feature = "std")]
fn from_f64_with(value: f64, mode: RoundingMode) -> Self;
#[cfg(feature = "std")]
fn to_f64(self) -> f64;
#[cfg(feature = "std")]
fn to_f32(self) -> f32;
#[inline]
fn is_zero(self) -> bool {
self == Self::ZERO
}
#[inline]
fn is_one(self) -> bool {
self == Self::ONE
}
#[inline]
fn is_normal(self) -> bool {
!self.is_zero()
}
#[inline]
fn sum<I>(iter: I) -> Self
where
I: IntoIterator<Item = Self>,
{
iter.into_iter().fold(Self::ZERO, |acc, x| acc + x)
}
#[inline]
fn product<I>(iter: I) -> Self
where
I: IntoIterator<Item = Self>,
{
iter.into_iter().fold(Self::ONE, |acc, x| acc * x)
}
}