Debian Codegraph @

third_party/rust/rust_decimal/src/constants.rs

raw
1 // Sign mask for the flags field. A value of zero in this bit indicates a
2 // positive Decimal value, and a value of one in this bit indicates a
3 // negative Decimal value.
4 pub const SIGN_MASK: u32 = 0x8000_0000;
5 pub const UNSIGN_MASK: u32 = 0x4FFF_FFFF;
6
7 // Scale mask for the flags field. This byte in the flags field contains
8 // the power of 10 to divide the Decimal value by. The scale byte must
9 // contain a value between 0 and 28 inclusive.
10 pub const SCALE_MASK: u32 = 0x00FF_0000;
11 pub const U8_MASK: u32 = 0x0000_00FF;
12 pub const U32_MASK: u64 = u32::MAX as _;
13
14 // Number of bits scale is shifted by.
15 pub const SCALE_SHIFT: u32 = 16;
16 // Number of bits sign is shifted by.
17 pub const SIGN_SHIFT: u32 = 31;
18
19 // The maximum string buffer size used for serialization purposes. 31 is optimal, however we align
20 // to the byte boundary for simplicity.
21 pub const MAX_STR_BUFFER_SIZE: usize = 32;
22
23 // The maximum supported precision
24 pub const MAX_PRECISION: u8 = 28;
25 #[cfg(not(feature = "legacy-ops"))]
26 // u8 to i32 is infallible, therefore, this cast will never overflow
27 pub const MAX_PRECISION_I32: i32 = MAX_PRECISION as _;
28 // u8 to u32 is infallible, therefore, this cast will never overflow
29 pub const MAX_PRECISION_U32: u32 = MAX_PRECISION as _;
30 // 79,228,162,514,264,337,593,543,950,335
31 pub const MAX_I128_REPR: i128 = 0x0000_0000_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF;
32
33 // Fast access for 10^n where n is 0-9
34 pub const POWERS_10: [u32; 10] = [
35 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000,
36 ];
37 // Fast access for 10^n where n is 1-19
38 pub const BIG_POWERS_10: [u64; 19] = [
39 10,
40 100,
41 1000,
42 10000,
43 100000,
44 1000000,
45 10000000,
46 100000000,
47 1000000000,
48 10000000000,
49 100000000000,
50 1000000000000,
51 10000000000000,
52 100000000000000,
53 1000000000000000,
54 10000000000000000,
55 100000000000000000,
56 1000000000000000000,
57 10000000000000000000,
58 ];
59
60 #[cfg(not(feature = "legacy-ops"))]
61 // The maximum power of 10 that a 32 bit integer can store
62 pub const MAX_I32_SCALE: i32 = 9;
63 #[cfg(not(feature = "legacy-ops"))]
64 // The maximum power of 10 that a 64 bit integer can store
65 pub const MAX_I64_SCALE: u32 = 19;
66 #[cfg(not(feature = "legacy-ops"))]
67 pub const U32_MAX: u64 = u32::MAX as u64;
68
69 // Determines potential overflow for 128 bit operations
70 pub const OVERFLOW_U96: u128 = 1u128 << 96;
71 pub const WILL_OVERFLOW_U64: u64 = u64::MAX / 10 - u8::MAX as u64;
72 pub const BYTES_TO_OVERFLOW_U64: usize = 18; // We can probably get away with less