1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Named constants for common decimal values.
//!
//! Core constants (`ZERO`, `ONE`, `MAX`, `MIN`) are generated for each
//! backing type. Financial constants (CENT, BASIS_POINT, etc.) are
//! in `financial.rs`.
use crate::Decimal;
macro_rules! impl_decimal_constants {
($backing:ty) => {
impl<const D: u8> Decimal<$backing, D> {
/// Zero (`0`).
pub const ZERO: Self = Self { value: 0 };
/// One (`1.0`).
pub const ONE: Self = Self { value: Self::SCALE };
/// Negative one (`-1.0`).
pub const NEG_ONE: Self = Self {
value: -Self::SCALE,
};
/// Maximum representable value.
pub const MAX: Self = Self {
value: <$backing>::MAX,
};
/// Minimum representable value.
pub const MIN: Self = Self {
value: <$backing>::MIN,
};
}
};
}
impl_decimal_constants!(i32);
impl_decimal_constants!(i64);
impl_decimal_constants!(i128);