Trait fixnum::ops::CheckedAdd [−][src]
pub trait CheckedAdd<Rhs = Self> { type Output; type Error; fn cadd(self, rhs: Rhs) -> Result<Self::Output, Self::Error>; fn saturating_add(self, rhs: Rhs) -> Self::Output
where
Self: Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded, { ... } }
Associated Types
Required methods
fn cadd(self, rhs: Rhs) -> Result<Self::Output, Self::Error>
[src]
fn cadd(self, rhs: Rhs) -> Result<Self::Output, Self::Error>
[src]Checked addition. Returns Err
on overflow.
use fixnum::{FixedPoint, typenum::U9, ops::CheckedAdd}; type Amount = FixedPoint<i64, U9>; let a: Amount = "0.1".parse()?; let b: Amount = "0.2".parse()?; let c: Amount = "0.3".parse()?; assert_eq!(a.cadd(b)?, c);
Provided methods
fn saturating_add(self, rhs: Rhs) -> Self::Output where
Self: Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded,
[src]
fn saturating_add(self, rhs: Rhs) -> Self::Output where
Self: Sized,
Rhs: PartialOrd + Zero,
Self::Output: Bounded,
[src]Saturating addition. Computes self + rhs
, saturating at the numeric bounds
(MIN
, MAX
) instead of overflowing.
use fixnum::{FixedPoint, typenum::U9, ops::{Bounded, RoundMode::*, CheckedAdd}}; type Amount = FixedPoint<i64, U9>; let a: Amount = "1000.00002".parse()?; let b: Amount = "9222000000".parse()?; let c: Amount = "9222001000.00002".parse()?; // 1000.00002 + 9222000000 = 9222001000.00002 assert_eq!(a.saturating_add(b), c); // 9222000000 + 9222000000 = MAX assert_eq!(c.saturating_add(c), Amount::MAX); let d: Amount = "-9222000000".parse()?; // -9222000000 + (-9222000000) = MIN assert_eq!(d.saturating_add(d), Amount::MIN);
Implementations on Foreign Types
impl CheckedAdd<i8> for i8
[src]
impl CheckedAdd<i8> for i8
[src]impl CheckedAdd<i16> for i16
[src]
impl CheckedAdd<i16> for i16
[src]impl CheckedAdd<i32> for i32
[src]
impl CheckedAdd<i32> for i32
[src]impl CheckedAdd<i64> for i64
[src]
impl CheckedAdd<i64> for i64
[src]impl CheckedAdd<i128> for i128
[src]
impl CheckedAdd<i128> for i128
[src]Implementors
impl<P: Precision> CheckedAdd<FixedPoint<i16, P>> for FixedPoint<i16, P>
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i16, P>> for FixedPoint<i16, P>
[src]type Output = FixedPoint<i16, P>
type Error = ArithmeticError
fn cadd(
self,
rhs: FixedPoint<i16, P>
) -> Result<FixedPoint<i16, P>, ArithmeticError>
[src]
self,
rhs: FixedPoint<i16, P>
) -> Result<FixedPoint<i16, P>, ArithmeticError>
fn saturating_add(self, rhs: Self) -> Self::Output
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i32, P>> for FixedPoint<i32, P>
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i32, P>> for FixedPoint<i32, P>
[src]type Output = FixedPoint<i32, P>
type Error = ArithmeticError
fn cadd(
self,
rhs: FixedPoint<i32, P>
) -> Result<FixedPoint<i32, P>, ArithmeticError>
[src]
self,
rhs: FixedPoint<i32, P>
) -> Result<FixedPoint<i32, P>, ArithmeticError>
fn saturating_add(self, rhs: Self) -> Self::Output
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i64, P>> for FixedPoint<i64, P>
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i64, P>> for FixedPoint<i64, P>
[src]type Output = FixedPoint<i64, P>
type Error = ArithmeticError
fn cadd(
self,
rhs: FixedPoint<i64, P>
) -> Result<FixedPoint<i64, P>, ArithmeticError>
[src]
self,
rhs: FixedPoint<i64, P>
) -> Result<FixedPoint<i64, P>, ArithmeticError>
fn saturating_add(self, rhs: Self) -> Self::Output
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i128, P>> for FixedPoint<i128, P>
[src]
impl<P: Precision> CheckedAdd<FixedPoint<i128, P>> for FixedPoint<i128, P>
[src]This is supported on crate feature
i128
only.type Output = FixedPoint<i128, P>
type Error = ArithmeticError
fn cadd(
self,
rhs: FixedPoint<i128, P>
) -> Result<FixedPoint<i128, P>, ArithmeticError>
[src]
self,
rhs: FixedPoint<i128, P>
) -> Result<FixedPoint<i128, P>, ArithmeticError>