#[repr(transparent)]pub struct Dec19x19 {
pub repr: i128,
}
Expand description
A high-precision, high-performance fixed-point decimal type.
Internally, values are stored as i128
, which supports 39 digits with the first digit never
exceeding 1
. The last 19 digits are interpreted as the fractional part. This allows all
operations to perform without rounding or approximations within the full range of exactly 19
fractional and 19 integer digits.
Fields§
§repr: i128
Implementations§
Source§impl Dec19x19
impl Dec19x19
Sourcepub const MAX_INT: Self
pub const MAX_INT: Self
The biggest possible integer value that can be stored in a Dec19x19
.
§Tests
assert_eq!(Dec19x19::MAX_INT, Dec19x19::MAX.trunc());
Sourcepub const MIN_INT: Self
pub const MIN_INT: Self
The smallest possible integer value that can be stored in a Dec19x19
.
§Tests
assert_eq!(Dec19x19::MIN_INT, Dec19x19::MIN.trunc());
Sourcepub const LN_2: Self
pub const LN_2: Self
The natural logarithm of 2 (ln(2)
), accurate to all 19 decimal places of the Dec19x19
fixed-point format.
Sourcepub const SMALLEST_STEP: Self
pub const SMALLEST_STEP: Self
The smallest possible value that can be stored in a Dec19x19
.
§Tests
assert_eq!(Dec19x19::SMALLEST_STEP / Dec19x19!(2), Dec19x19!(0));
Source§impl Dec19x19
impl Dec19x19
Sourcepub fn unchecked_mul_no_opt(self, rhs: Self) -> Self
pub fn unchecked_mul_no_opt(self, rhs: Self) -> Self
Multiplication without checking for overflow and no optimization for LHS or RHS being ints
or fracs only. You probably want to use Dec19x19::mul
with mul_opt
flag disabled
instead.
Sourcepub fn unchecked_mul_opt(self, rhs: Self) -> Self
pub fn unchecked_mul_opt(self, rhs: Self) -> Self
Multiplication without checking for overflow and optimization for LHS or RHS being ints or
fracs only. You probably want to use Dec19x19::mul
with mul_opt
flag enabled instead
(default).
Sourcepub fn checked_mul_no_opt(self, rhs: Self) -> Option<Self>
pub fn checked_mul_no_opt(self, rhs: Self) -> Option<Self>
Multiplication with checking for overflow and no optimization for LHS or RHS being ints. You
probably want to use Dec19x19::checked_mul
with mul_opt
flag disabled instead.
Sourcepub fn checked_mul_opt(self, rhs: Self) -> Option<Self>
pub fn checked_mul_opt(self, rhs: Self) -> Option<Self>
Multiplication with checking for overflow and optimization for LHS or RHS being ints. You
probably want to use Dec19x19::checked_mul
with mul_opt
flag enabled instead.
Trait Implementations§
Source§impl Abs for Dec19x19
§Tests
check!( [Dec19x19::abs] {
(Dec19x19::MAX) => Dec19x19::MAX,
(Dec19x19!(3.0)) => Dec19x19!(3.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(3.0),
(Dec19x19::MIN) => Dec19x19::MAX,
});
impl Abs for Dec19x19
§Tests
check!( [Dec19x19::abs] {
(Dec19x19::MAX) => Dec19x19::MAX,
(Dec19x19!(3.0)) => Dec19x19!(3.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(3.0),
(Dec19x19::MIN) => Dec19x19::MAX,
});
Source§impl Add for Dec19x19
§Tests
check!( [Dec19x19::add, Dec19x19::checked_add] {
(Dec19x19::MAX, Dec19x19::MIN) => -Dec19x19::SMALLEST_STEP,
(Dec19x19::MAX - Dec19x19!(1), Dec19x19!(1)) => Dec19x19::MAX,
(Dec19x19::MAX, Dec19x19!(0)) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19!(0)) => Dec19x19::MIN,
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => FAIL,
(Dec19x19::MAX, Dec19x19!(1)) => FAIL,
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => FAIL
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=18, 0..=19), Series::new(0..=18, 0..=19),
|(f1, b1), (f2, b2)| should_eq(f1 + f2, b1 + b2)
);
impl Add for Dec19x19
§Tests
check!( [Dec19x19::add, Dec19x19::checked_add] {
(Dec19x19::MAX, Dec19x19::MIN) => -Dec19x19::SMALLEST_STEP,
(Dec19x19::MAX - Dec19x19!(1), Dec19x19!(1)) => Dec19x19::MAX,
(Dec19x19::MAX, Dec19x19!(0)) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19!(0)) => Dec19x19::MIN,
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => FAIL,
(Dec19x19::MAX, Dec19x19!(1)) => FAIL,
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => FAIL
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=18, 0..=19), Series::new(0..=18, 0..=19),
|(f1, b1), (f2, b2)| should_eq(f1 + f2, b1 + b2)
);
Source§impl AddAssign for Dec19x19
impl AddAssign for Dec19x19
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl CheckedAdd for Dec19x19
impl CheckedAdd for Dec19x19
Source§impl CheckedDiv for Dec19x19
impl CheckedDiv for Dec19x19
Source§impl CheckedLog10Floor for Dec19x19
impl CheckedLog10Floor for Dec19x19
const fn checked_log10_floor(self) -> Option<Self>
Source§impl CheckedMul for Dec19x19
impl CheckedMul for Dec19x19
Source§impl CheckedPow<i32> for Dec19x19
impl CheckedPow<i32> for Dec19x19
Source§impl CheckedSqrt for Dec19x19
impl CheckedSqrt for Dec19x19
fn checked_sqrt(self) -> Option<Self>
Source§impl CheckedSub for Dec19x19
impl CheckedSub for Dec19x19
Source§impl Div for Dec19x19
§Tests
check! ( [Dec19x19::div, Dec19x19::checked_div] {
(Dec19x19!(20), Dec19x19!(0.2)) => Dec19x19!(100.0),
(Dec19x19::MAX, Dec19x19!(-1)) => Dec19x19::MIN + Dec19x19::SMALLEST_STEP,
(Dec19x19::MIN + Dec19x19::SMALLEST_STEP, Dec19x19!(-1)) => Dec19x19::MAX,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(0.1)) => FAIL,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(0)) => FAIL,
(Dec19x19!(10), Dec19x19!(0)) => FAIL,
(Dec19x19::MAX, Dec19x19!(0.1)) => FAIL,
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=9, 0..=9), Series::new(0..=9, 0..=9),
|(f1, b1), (f2, b2)| should_eq(f1 / f2, b1 / b2)
);
impl Div for Dec19x19
§Tests
check! ( [Dec19x19::div, Dec19x19::checked_div] {
(Dec19x19!(20), Dec19x19!(0.2)) => Dec19x19!(100.0),
(Dec19x19::MAX, Dec19x19!(-1)) => Dec19x19::MIN + Dec19x19::SMALLEST_STEP,
(Dec19x19::MIN + Dec19x19::SMALLEST_STEP, Dec19x19!(-1)) => Dec19x19::MAX,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(0.1)) => FAIL,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(0)) => FAIL,
(Dec19x19!(10), Dec19x19!(0)) => FAIL,
(Dec19x19::MAX, Dec19x19!(0.1)) => FAIL,
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=9, 0..=9), Series::new(0..=9, 0..=9),
|(f1, b1), (f2, b2)| should_eq(f1 / f2, b1 / b2)
);
Source§impl DivAssign for Dec19x19
impl DivAssign for Dec19x19
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moreSource§impl FromStr for Dec19x19
§Tests
use std::str::FromStr;
assert_eq!(Dec19x19!(17_014_118_346_046_923_173.168_730_371_588_410_572_7).repr, i128::MAX);
assert_eq!(Dec19x19!(-17_014_118_346_046_923_173.168_730_371_588_410_572_8).repr, i128::MIN);
assert_eq!(Dec19x19!(987e-19), Dec19x19!(0.000_000_000_000_000_098_7));
assert_eq!(Dec19x19!(987e-2), Dec19x19!(9.87));
assert_eq!(Dec19x19!(987e-1), Dec19x19!(98.7));
assert_eq!(Dec19x19!(987e-0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e+0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e+1), Dec19x19!(9_870));
assert_eq!(Dec19x19!(987e+2), Dec19x19!(98_700));
assert_eq!(Dec19x19!(987e16), Dec19x19!(9_870_000_000_000_000_000));
assert_eq!(Dec19x19!(1_000_000_000_000_000e-34), Dec19x19::SMALLEST_STEP);
assert_eq!(Dec19x19!(0.000_000_000_000_000e34), Dec19x19!(0));
assert!(Dec19x19::from_str("17_014_118_346_046_923_173.168_730_371_588_410_572_8").is_err());
assert!(Dec19x19::from_str("-17_014_118_346_046_923_173.168_730_371_588_410_572_9").is_err());
assert!(Dec19x19::from_str("987e+17").is_err());
assert!(Dec19x19::from_str("987e-20").is_err());
impl FromStr for Dec19x19
§Tests
use std::str::FromStr;
assert_eq!(Dec19x19!(17_014_118_346_046_923_173.168_730_371_588_410_572_7).repr, i128::MAX);
assert_eq!(Dec19x19!(-17_014_118_346_046_923_173.168_730_371_588_410_572_8).repr, i128::MIN);
assert_eq!(Dec19x19!(987e-19), Dec19x19!(0.000_000_000_000_000_098_7));
assert_eq!(Dec19x19!(987e-2), Dec19x19!(9.87));
assert_eq!(Dec19x19!(987e-1), Dec19x19!(98.7));
assert_eq!(Dec19x19!(987e-0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e+0), Dec19x19!(987));
assert_eq!(Dec19x19!(987e+1), Dec19x19!(9_870));
assert_eq!(Dec19x19!(987e+2), Dec19x19!(98_700));
assert_eq!(Dec19x19!(987e16), Dec19x19!(9_870_000_000_000_000_000));
assert_eq!(Dec19x19!(1_000_000_000_000_000e-34), Dec19x19::SMALLEST_STEP);
assert_eq!(Dec19x19!(0.000_000_000_000_000e34), Dec19x19!(0));
assert!(Dec19x19::from_str("17_014_118_346_046_923_173.168_730_371_588_410_572_8").is_err());
assert!(Dec19x19::from_str("-17_014_118_346_046_923_173.168_730_371_588_410_572_9").is_err());
assert!(Dec19x19::from_str("987e+17").is_err());
assert!(Dec19x19::from_str("987e-20").is_err());
Source§impl HasMax for Dec19x19
The biggest possible value that can be stored in a Dec19x19
, equal to
impl HasMax for Dec19x19
The biggest possible value that can be stored in a Dec19x19
, equal to
17_014_118_346_046_923_173.168_730_371_588_410_572_7
Source§impl HasMin for Dec19x19
The smallest possible value that can be stored in a Dec19x19
, equal to
impl HasMin for Dec19x19
The smallest possible value that can be stored in a Dec19x19
, equal to
-17_014_118_346_046_923_173.168_730_371_588_410_572_8
Source§impl Mul for Dec19x19
§Tests
check!(
[
Dec19x19::unchecked_mul_no_opt,
Dec19x19::unchecked_mul_opt,
Dec19x19::checked_mul_no_opt,
Dec19x19::checked_mul_opt,
] {
(Dec19x19!(20), Dec19x19!(2.2)) => Dec19x19!(44.0),
(Dec19x19::MAX, Dec19x19!(10)) => FAIL,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(2)) => FAIL,
});
§Fuzzy
let series = [
Series::new(0..=9, 0..=19),
Series::new(9, 19),
Series::new(0, 19),
Series::new(9, 0),
];
for s in series {
fuzzy2::<Dec19x19, BigDecimal>(s.clone(), s,
|(f1, b1), (f2, b2)| {
should_eq(f1.unchecked_mul_opt(f2), b1.clone() * b2.clone());
should_eq(f1.unchecked_mul_no_opt(f2), b1.clone() * b2.clone());
should_eq(f1.checked_mul_opt(f2).unwrap(), b1.clone() * b2.clone());
should_eq(f1.checked_mul_no_opt(f2).unwrap(), b1 * b2);
}
);
}
impl Mul for Dec19x19
§Tests
check!(
[
Dec19x19::unchecked_mul_no_opt,
Dec19x19::unchecked_mul_opt,
Dec19x19::checked_mul_no_opt,
Dec19x19::checked_mul_opt,
] {
(Dec19x19!(20), Dec19x19!(2.2)) => Dec19x19!(44.0),
(Dec19x19::MAX, Dec19x19!(10)) => FAIL,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(2)) => FAIL,
});
§Fuzzy
let series = [
Series::new(0..=9, 0..=19),
Series::new(9, 19),
Series::new(0, 19),
Series::new(9, 0),
];
for s in series {
fuzzy2::<Dec19x19, BigDecimal>(s.clone(), s,
|(f1, b1), (f2, b2)| {
should_eq(f1.unchecked_mul_opt(f2), b1.clone() * b2.clone());
should_eq(f1.unchecked_mul_no_opt(f2), b1.clone() * b2.clone());
should_eq(f1.checked_mul_opt(f2).unwrap(), b1.clone() * b2.clone());
should_eq(f1.checked_mul_no_opt(f2).unwrap(), b1 * b2);
}
);
}
Source§impl MulAssign for Dec19x19
impl MulAssign for Dec19x19
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl Neg for Dec19x19
§Tests
check! ( [Dec19x19::neg] {
(Dec19x19::MAX) => Dec19x19::MIN + Dec19x19::SMALLEST_STEP,
(Dec19x19!(3.0)) => Dec19x19!(-3.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(3.0),
(Dec19x19::MIN) => Dec19x19::MAX,
((Dec19x19::MIN + Dec19x19::SMALLEST_STEP)) => Dec19x19::MAX,
});
impl Neg for Dec19x19
§Tests
check! ( [Dec19x19::neg] {
(Dec19x19::MAX) => Dec19x19::MIN + Dec19x19::SMALLEST_STEP,
(Dec19x19!(3.0)) => Dec19x19!(-3.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(3.0),
(Dec19x19::MIN) => Dec19x19::MAX,
((Dec19x19::MIN + Dec19x19::SMALLEST_STEP)) => Dec19x19::MAX,
});
Source§impl Ord for Dec19x19
impl Ord for Dec19x19
Source§impl PartialOrd for Dec19x19
impl PartialOrd for Dec19x19
Source§impl Rand for Dec19x19
Generates a deterministic random Dec19x19
value using a seed, an integer precision, and a
fractional precision. Never returns zero.
impl Rand for Dec19x19
Generates a deterministic random Dec19x19
value using a seed, an integer precision, and a
fractional precision. Never returns zero.
§Tests
check! ( [Dec19x19::rand] {
(0, 6, 0) => Dec19x19!(-758_415),
(1, 6, 0) => Dec19x19!(-717_558),
(2, 6, 0) => Dec19x19!(-149_577),
(3, 6, 0) => Dec19x19!(-442_649),
(4, 6, 0) => Dec19x19!( 658_419),
(5, 6, 0) => Dec19x19!( 165_296),
(6, 3, 0) => Dec19x19!(-787),
(7, 3, 0) => Dec19x19!(-354),
(8, 3, 0) => Dec19x19!( 745),
(9, 3, 0) => Dec19x19!( 163),
(10, 3, 0) => Dec19x19!(-211),
(11, 3, 0) => Dec19x19!(-719),
(12, 3, 3) => Dec19x19!(-698.488),
(13, 3, 3) => Dec19x19!( 354.710),
(14, 3, 3) => Dec19x19!( 807.648),
(15, 3, 3) => Dec19x19!(-392.145),
(16, 3, 3) => Dec19x19!(-243.552),
(17, 3, 3) => Dec19x19!( 378.313),
(18, 6, 6) => Dec19x19!( 428_879.493_071),
(19, 6, 6) => Dec19x19!( 414_719.622_665),
(20, 6, 6) => Dec19x19!( 154_184.335_022),
(21, 6, 6) => Dec19x19!( 335_592.781_210),
(22, 6, 6) => Dec19x19!(-562_472.732_119),
(23, 6, 6) => Dec19x19!(-990_435.673_210),
(0, 0, 6) => Dec19x19!(-0.758_415),
(1, 0, 6) => Dec19x19!(-0.617_558),
(2, 0, 6) => Dec19x19!(-0.049_577),
(3, 0, 6) => Dec19x19!(-0.342_649),
(4, 0, 6) => Dec19x19!( 0.658_419),
(5, 0, 6) => Dec19x19!( 0.065_296),
(1, 19, 19) => Dec19x19!(-7_175_586_050_193_843_404.647_199_936_274_331_797_4),
(0, 0, 0) => Dec19x19!(-7),
(1, 0, 0) => Dec19x19!(-6),
(2, 0, 0) => Dec19x19!(-1),
(3, 0, 0) => Dec19x19!(-3),
(4, 0, 0) => Dec19x19!(6),
(5, 0, 0) => Dec19x19!(1),
(1, 0..=9, 0..=9) => Dec19x19!(42545517.614973869),
(2, 0..=9, 0..=9) => Dec19x19!(-0.41),
(3, 0..=9, 0..=9) => Dec19x19!(-224053),
(4, 0..=9, 0..=9) => Dec19x19!(662259.83081),
(5, 0..=9, 0..=9) => Dec19x19!(-5.748),
});
fn rand(seed: u64, int: impl IntoRandRange, frac: impl IntoRandRange) -> Self
Source§impl Rem for Dec19x19
§Tests
check!( [Dec19x19::rem] {
(Dec19x19!(14.7), Dec19x19!(5)) => Dec19x19!(4.7),
(Dec19x19!(14.7), Dec19x19!(0)) => Dec19x19!(14.7),
(Dec19x19!(14.7), Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::MAX) => Dec19x19!(0),
(Dec19x19::MIN, Dec19x19::MIN) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19::MAX) => -Dec19x19::SMALLEST_STEP,
});
impl Rem for Dec19x19
§Tests
check!( [Dec19x19::rem] {
(Dec19x19!(14.7), Dec19x19!(5)) => Dec19x19!(4.7),
(Dec19x19!(14.7), Dec19x19!(0)) => Dec19x19!(14.7),
(Dec19x19!(14.7), Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::MAX) => Dec19x19!(0),
(Dec19x19::MIN, Dec19x19::MIN) => Dec19x19!(0),
(Dec19x19::MAX, Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19::MAX) => -Dec19x19::SMALLEST_STEP,
});
Source§impl SaturatingAdd for Dec19x19
§Tests
check! ( [Dec19x19::saturating_add] {
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => Dec19x19::MAX,
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => Dec19x19::MIN,
});
impl SaturatingAdd for Dec19x19
§Tests
check! ( [Dec19x19::saturating_add] {
(Dec19x19::MAX, Dec19x19::SMALLEST_STEP) => Dec19x19::MAX,
(Dec19x19::MIN, -Dec19x19::SMALLEST_STEP) => Dec19x19::MIN,
});
Source§impl SaturatingDiv for Dec19x19
§Tests
assert_eq!((Dec19x19::MAX - Dec19x19!(10)).saturating_div(Dec19x19!(0.1)), Dec19x19::MAX);
assert_eq!((Dec19x19::MAX - Dec19x19!(10)).saturating_div(Dec19x19!(-0.1)), Dec19x19::MIN);
assert_eq!(Dec19x19::MIN.saturating_div(Dec19x19!(-1)), Dec19x19::MAX);
impl SaturatingDiv for Dec19x19
§Tests
assert_eq!((Dec19x19::MAX - Dec19x19!(10)).saturating_div(Dec19x19!(0.1)), Dec19x19::MAX);
assert_eq!((Dec19x19::MAX - Dec19x19!(10)).saturating_div(Dec19x19!(-0.1)), Dec19x19::MIN);
assert_eq!(Dec19x19::MIN.saturating_div(Dec19x19!(-1)), Dec19x19::MAX);
Source§impl SaturatingMul for Dec19x19
§Tests
check! ( [Dec19x19::saturating_mul] {
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(2)) => Dec19x19::MAX,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(-2)) => Dec19x19::MIN,
});
impl SaturatingMul for Dec19x19
§Tests
check! ( [Dec19x19::saturating_mul] {
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(2)) => Dec19x19::MAX,
(Dec19x19::MAX - Dec19x19!(10), Dec19x19!(-2)) => Dec19x19::MIN,
});
Source§impl SaturatingSub for Dec19x19
§Tests
check! ( [Dec19x19::saturating_sub] {
(Dec19x19::MIN, Dec19x19!(1)) => Dec19x19::MIN,
(Dec19x19!(10), Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19!(0), Dec19x19::MIN) => Dec19x19::MAX,
});
impl SaturatingSub for Dec19x19
§Tests
check! ( [Dec19x19::saturating_sub] {
(Dec19x19::MIN, Dec19x19!(1)) => Dec19x19::MIN,
(Dec19x19!(10), Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19!(0), Dec19x19::MIN) => Dec19x19::MAX,
});
Source§impl Signum for Dec19x19
§Tests
check! ( [Dec19x19::signum] {
(Dec19x19::MAX) => Dec19x19!(1.0),
(Dec19x19!(3.0)) => Dec19x19!(1.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(-1.0),
(Dec19x19::MIN) => Dec19x19!(-1.0),
});
impl Signum for Dec19x19
§Tests
check! ( [Dec19x19::signum] {
(Dec19x19::MAX) => Dec19x19!(1.0),
(Dec19x19!(3.0)) => Dec19x19!(1.0),
(Dec19x19!(0.0)) => Dec19x19!(0.0),
(Dec19x19!(-3.0)) => Dec19x19!(-1.0),
(Dec19x19::MIN) => Dec19x19!(-1.0),
});
Source§impl Step for Dec19x19
impl Step for Dec19x19
Source§fn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait
)Source§fn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait
)Source§unsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait
)Source§unsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait
)Source§fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
step_trait
)start
to end
like Iterator::size_hint()
. Read moreSource§fn forward_checked(start: Self, count: usize) -> Option<Self>
fn forward_checked(start: Self, count: usize) -> Option<Self>
step_trait
)Source§impl Sub for Dec19x19
§Tests
check!( [Dec19x19::sub, Dec19x19::checked_sub] {
(Dec19x19::MIN + Dec19x19!(1), Dec19x19!(1)) => Dec19x19::MIN,
(-Dec19x19::SMALLEST_STEP, Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19::SMALLEST_STEP) => FAIL,
(Dec19x19::MIN, Dec19x19!(1)) => FAIL,
(Dec19x19!(0), Dec19x19::MIN) => FAIL,
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=18, 0..=19), Series::new(0..=18, 0..=19),
|(f1, b1), (f2, b2)| should_eq(f1 - f2, b1 - b2)
);
impl Sub for Dec19x19
§Tests
check!( [Dec19x19::sub, Dec19x19::checked_sub] {
(Dec19x19::MIN + Dec19x19!(1), Dec19x19!(1)) => Dec19x19::MIN,
(-Dec19x19::SMALLEST_STEP, Dec19x19::MIN) => Dec19x19::MAX,
(Dec19x19::MIN, Dec19x19::SMALLEST_STEP) => FAIL,
(Dec19x19::MIN, Dec19x19!(1)) => FAIL,
(Dec19x19!(0), Dec19x19::MIN) => FAIL,
});
§Fuzzy
fuzzy2::<Dec19x19, BigDecimal>(Series::new(0..=18, 0..=19), Series::new(0..=18, 0..=19),
|(f1, b1), (f2, b2)| should_eq(f1 - f2, b1 - b2)
);
Source§impl SubAssign for Dec19x19
impl SubAssign for Dec19x19
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moreSource§impl UncheckedAdd for Dec19x19
impl UncheckedAdd for Dec19x19
Source§impl UncheckedDiv for Dec19x19
impl UncheckedDiv for Dec19x19
Source§impl UncheckedLn for Dec19x19
§Tests
let trunc = |t: Dec19x19| t.trunc_to(17);
check!( [|t| trunc(Dec19x19::unchecked_ln(t)), |t| Dec19x19::checked_ln(t).map(trunc)] {
(Dec19x19::MAX) => trunc(Dec19x19!(44.280_575_164_226_186_298_3)),
(Dec19x19!(10)) => trunc(Dec19x19!(2.302_585_092_994_045_684_0)),
(Dec19x19!(100)) => trunc(Dec19x19!(4.605_170_185_988_091_367_8)),
(Dec19x19!(0.1)) => trunc(Dec19x19!(-2.302_585_092_994_045_683_7)),
(Dec19x19!(2.718281828459045239)) => Dec19x19!(1),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
impl UncheckedLn for Dec19x19
§Tests
let trunc = |t: Dec19x19| t.trunc_to(17);
check!( [|t| trunc(Dec19x19::unchecked_ln(t)), |t| Dec19x19::checked_ln(t).map(trunc)] {
(Dec19x19::MAX) => trunc(Dec19x19!(44.280_575_164_226_186_298_3)),
(Dec19x19!(10)) => trunc(Dec19x19!(2.302_585_092_994_045_684_0)),
(Dec19x19!(100)) => trunc(Dec19x19!(4.605_170_185_988_091_367_8)),
(Dec19x19!(0.1)) => trunc(Dec19x19!(-2.302_585_092_994_045_683_7)),
(Dec19x19!(2.718281828459045239)) => Dec19x19!(1),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
fn unchecked_ln(self) -> Self
Source§impl UncheckedLog10Floor for Dec19x19
§Tests
check! ( [Dec19x19::unchecked_log10_floor, Dec19x19::checked_log10_floor] {
(Dec19x19::MAX) => Dec19x19!(19),
(Dec19x19!(10.1)) => Dec19x19!(1),
(Dec19x19!(10.0)) => Dec19x19!(1),
(Dec19x19!(9.99)) => Dec19x19!(0),
(Dec19x19!(1.17)) => Dec19x19!(0),
(Dec19x19!(1.0)) => Dec19x19!(0),
(Dec19x19!(0.9)) => Dec19x19!(-1),
(Dec19x19!(0.11)) => Dec19x19!(-1),
(Dec19x19!(0.1)) => Dec19x19!(-1),
(Dec19x19!(0.09)) => Dec19x19!(-2),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
impl UncheckedLog10Floor for Dec19x19
§Tests
check! ( [Dec19x19::unchecked_log10_floor, Dec19x19::checked_log10_floor] {
(Dec19x19::MAX) => Dec19x19!(19),
(Dec19x19!(10.1)) => Dec19x19!(1),
(Dec19x19!(10.0)) => Dec19x19!(1),
(Dec19x19!(9.99)) => Dec19x19!(0),
(Dec19x19!(1.17)) => Dec19x19!(0),
(Dec19x19!(1.0)) => Dec19x19!(0),
(Dec19x19!(0.9)) => Dec19x19!(-1),
(Dec19x19!(0.11)) => Dec19x19!(-1),
(Dec19x19!(0.1)) => Dec19x19!(-1),
(Dec19x19!(0.09)) => Dec19x19!(-2),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
const fn unchecked_log10_floor(self) -> Self
Source§impl UncheckedMul for Dec19x19
impl UncheckedMul for Dec19x19
Source§impl UncheckedPow<i32> for Dec19x19
check! ( [Dec19x19::unchecked_pow, Dec19x19::checked_pow] {
// Identity and basic powers
(Dec19x19!(2), 0_i32) => Dec19x19!(1),
(Dec19x19!(2), 1_i32) => Dec19x19!(2),
(Dec19x19!(2), 3_i32) => Dec19x19!(8),
(Dec19x19!(2), 4_i32) => Dec19x19!(16),
(Dec19x19!(2), 5_i32) => Dec19x19!(32),
(Dec19x19!(2), 6_i32) => Dec19x19!(64),
(Dec19x19!(2), 7_i32) => Dec19x19!(128),
(Dec19x19!(2), 8_i32) => Dec19x19!(256),
(Dec19x19!(2), 9_i32) => Dec19x19!(512),
(Dec19x19!(2), 10_i32) => Dec19x19!(1024),
(Dec19x19!(2), 11_i32) => Dec19x19!(2048),
(Dec19x19!(2), 12_i32) => Dec19x19!(4096),
(Dec19x19!(2), 13_i32) => Dec19x19!(8192),
(Dec19x19!(2), 14_i32) => Dec19x19!(16384),
(Dec19x19!(2), 15_i32) => Dec19x19!(32768),
(Dec19x19!(2), 16_i32) => Dec19x19!(65536),
// Zero exponent
(Dec19x19!(20), 0) => Dec19x19!(1),
// Negative exponents
(Dec19x19!(2), -1_i32) => Dec19x19!(0.5),
(Dec19x19!(2), -2_i32) => Dec19x19!(0.25),
// Fractional bases
(Dec19x19!(0.5), 2_i32) => Dec19x19!(0.25),
(Dec19x19!(0.5), 3_i32) => Dec19x19!(0.125),
(Dec19x19!(0.5), -1_i32) => Dec19x19!(2.0),
// Fractional result rounding
(Dec19x19!(1.1), 2_i32) => Dec19x19!(1.21),
(Dec19x19!(1.5), 2_i32) => Dec19x19!(2.25),
// Larger integer base
(Dec19x19!(10), 3_i32) => Dec19x19!(1000),
(Dec19x19::MAX, -1_i32) => Dec19x19!(0),
(Dec19x19!(2), 63_i32) => Dec19x19!(9_223_372_036_854_775_808),
(Dec19x19!(2), 64) => FAIL,
(Dec19x19!(0), -1_i32) => FAIL,
(Dec19x19::MAX, 2_i32) => FAIL,
(Dec19x19::MIN, 2_i32) => FAIL,
});
impl UncheckedPow<i32> for Dec19x19
check! ( [Dec19x19::unchecked_pow, Dec19x19::checked_pow] {
// Identity and basic powers
(Dec19x19!(2), 0_i32) => Dec19x19!(1),
(Dec19x19!(2), 1_i32) => Dec19x19!(2),
(Dec19x19!(2), 3_i32) => Dec19x19!(8),
(Dec19x19!(2), 4_i32) => Dec19x19!(16),
(Dec19x19!(2), 5_i32) => Dec19x19!(32),
(Dec19x19!(2), 6_i32) => Dec19x19!(64),
(Dec19x19!(2), 7_i32) => Dec19x19!(128),
(Dec19x19!(2), 8_i32) => Dec19x19!(256),
(Dec19x19!(2), 9_i32) => Dec19x19!(512),
(Dec19x19!(2), 10_i32) => Dec19x19!(1024),
(Dec19x19!(2), 11_i32) => Dec19x19!(2048),
(Dec19x19!(2), 12_i32) => Dec19x19!(4096),
(Dec19x19!(2), 13_i32) => Dec19x19!(8192),
(Dec19x19!(2), 14_i32) => Dec19x19!(16384),
(Dec19x19!(2), 15_i32) => Dec19x19!(32768),
(Dec19x19!(2), 16_i32) => Dec19x19!(65536),
// Zero exponent
(Dec19x19!(20), 0) => Dec19x19!(1),
// Negative exponents
(Dec19x19!(2), -1_i32) => Dec19x19!(0.5),
(Dec19x19!(2), -2_i32) => Dec19x19!(0.25),
// Fractional bases
(Dec19x19!(0.5), 2_i32) => Dec19x19!(0.25),
(Dec19x19!(0.5), 3_i32) => Dec19x19!(0.125),
(Dec19x19!(0.5), -1_i32) => Dec19x19!(2.0),
// Fractional result rounding
(Dec19x19!(1.1), 2_i32) => Dec19x19!(1.21),
(Dec19x19!(1.5), 2_i32) => Dec19x19!(2.25),
// Larger integer base
(Dec19x19!(10), 3_i32) => Dec19x19!(1000),
(Dec19x19::MAX, -1_i32) => Dec19x19!(0),
(Dec19x19!(2), 63_i32) => Dec19x19!(9_223_372_036_854_775_808),
(Dec19x19!(2), 64) => FAIL,
(Dec19x19!(0), -1_i32) => FAIL,
(Dec19x19::MAX, 2_i32) => FAIL,
(Dec19x19::MIN, 2_i32) => FAIL,
});
Source§impl UncheckedSqrt for Dec19x19
§Tests
check! ( [Dec19x19::unchecked_sqrt, Dec19x19::checked_sqrt] {
(Dec19x19!(0)) => Dec19x19!(0),
(Dec19x19::MAX) => Dec19x19!(4_124_817_371.235_594_858_790_322_117_5),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
// Precision test.
assert_eq!(Dec19x19!(1e-18).unchecked_sqrt() * Dec19x19!(1e-18).unchecked_sqrt(), Dec19x19!(1e-18));
§Validation
fuzzy1::<Dec19x19, BigDecimal>(Series::new(0..=19, 0..=19),
|f1, b1| should_eq(f1.abs().unchecked_sqrt(), b1.abs().sqrt().unwrap())
);
impl UncheckedSqrt for Dec19x19
§Tests
check! ( [Dec19x19::unchecked_sqrt, Dec19x19::checked_sqrt] {
(Dec19x19!(0)) => Dec19x19!(0),
(Dec19x19::MAX) => Dec19x19!(4_124_817_371.235_594_858_790_322_117_5),
(-Dec19x19::SMALLEST_STEP) => FAIL,
});
// Precision test.
assert_eq!(Dec19x19!(1e-18).unchecked_sqrt() * Dec19x19!(1e-18).unchecked_sqrt(), Dec19x19!(1e-18));
§Validation
fuzzy1::<Dec19x19, BigDecimal>(Series::new(0..=19, 0..=19),
|f1, b1| should_eq(f1.abs().unchecked_sqrt(), b1.abs().sqrt().unwrap())
);