rust_fixed_point_decimal_core/
lib.rs1mod parser;
11mod powers_of_ten;
12
13pub const MAX_PREC: u8 = 9;
15
16use std::cmp::Ordering;
17
18pub use parser::{dec_repr_from_str, ParseDecimalError};
19pub use powers_of_ten::{checked_mul_pow_ten, mul_pow_ten, ten_pow};
20
21#[doc(hidden)]
22#[inline]
23pub fn adjust_prec(x: i128, p: u8, y: i128, q: u8) -> (i128, i128) {
24 match p.cmp(&q) {
25 Ordering::Equal => (x, y),
26 Ordering::Greater => (x, mul_pow_ten(y, p - q)),
27 Ordering::Less => (mul_pow_ten(x, q - p), y),
28 }
29}
30
31#[doc(hidden)]
32#[inline]
33pub fn checked_adjust_prec(
34 x: i128,
35 p: u8,
36 y: i128,
37 q: u8,
38) -> (Option<i128>, Option<i128>) {
39 match p.cmp(&q) {
40 Ordering::Equal => (Some(x), Some(y)),
41 Ordering::Greater => (Some(x), checked_mul_pow_ten(y, p - q)),
42 Ordering::Less => (checked_mul_pow_ten(x, q - p), Some(y)),
43 }
44}