use std::convert::TryFrom;
use crate::error::*;
pub const SCALE: usize = 18;
pub const WAD: u64 = 1_000_000_000_000_000_000;
pub const HALF_WAD: u64 = 500_000_000_000_000_000;
pub const PERCENT_SCALER: u64 = 10_000_000_000_000_000;
pub const BPS_SCALER: u64 = PERCENT_SCALER / 100;
#[allow(clippy::assign_op_pattern)]
#[allow(clippy::ptr_offset_with_cast)]
#[allow(clippy::reversed_empty_ranges)]
#[allow(clippy::manual_range_contains)]
pub mod uint {
use super::*;
use ::uint::construct_uint;
construct_uint! {
pub struct U192(3);
}
construct_uint! {
pub struct U128(2);
}
impl From<U128> for U192 {
fn from(value: U128) -> U192 {
let U128(ref arr) = value;
let mut ret = [0; 3];
ret[0] = arr[0];
ret[1] = arr[1];
U192(ret)
}
}
impl TryFrom<U192> for U128 {
type Error = DecimalError;
fn try_from(value: U192) -> Result<U128, DecimalError> {
let U192(ref arr) = value;
if arr[2] != 0 {
return Err(DecimalError::MathOverflow);
}
let mut ret = [0; 2];
ret[0] = arr[0];
ret[1] = arr[1];
Ok(U128(ret))
}
}
}
pub trait TrySub: Sized {
fn try_sub(self, rhs: Self) -> Result<Self, DecimalError>;
}
pub trait TryAdd: Sized {
fn try_add(self, rhs: Self) -> Result<Self, DecimalError>;
}
pub trait TryDiv<RHS>: Sized {
fn try_div(self, rhs: RHS) -> Result<Self, DecimalError>;
}
pub trait TryMul<RHS>: Sized {
fn try_mul(self, rhs: RHS) -> Result<Self, DecimalError>;
}