12
12
use crate :: num:: dec2flt:: common:: { ByteSlice , is_8digits} ;
13
13
14
14
#[ derive( Clone ) ]
15
- pub struct Decimal {
15
+ pub ( super ) struct Decimal {
16
16
/// The number of significant digits in the decimal.
17
17
pub num_digits : usize ,
18
18
/// The offset of the decimal point in the significant digits.
@@ -55,21 +55,21 @@ impl Decimal {
55
55
///
56
56
/// In Python:
57
57
/// `-emin + p2 + math.floor((emin+ 1)*math.log(2, b)-math.log(1-2**(-p2), b))`
58
- pub const MAX_DIGITS : usize = 768 ;
58
+ pub ( super ) const MAX_DIGITS : usize = 768 ;
59
59
/// The max digits that can be exactly represented in a 64-bit integer.
60
- pub const MAX_DIGITS_WITHOUT_OVERFLOW : usize = 19 ;
61
- pub const DECIMAL_POINT_RANGE : i32 = 2047 ;
60
+ pub ( super ) const MAX_DIGITS_WITHOUT_OVERFLOW : usize = 19 ;
61
+ pub ( super ) const DECIMAL_POINT_RANGE : i32 = 2047 ;
62
62
63
63
/// Append a digit to the buffer.
64
- pub fn try_add_digit ( & mut self , digit : u8 ) {
64
+ pub ( super ) fn try_add_digit ( & mut self , digit : u8 ) {
65
65
if self . num_digits < Self :: MAX_DIGITS {
66
66
self . digits [ self . num_digits ] = digit;
67
67
}
68
68
self . num_digits += 1 ;
69
69
}
70
70
71
71
/// Trim trailing zeros from the buffer.
72
- pub fn trim ( & mut self ) {
72
+ pub ( super ) fn trim ( & mut self ) {
73
73
// All of the following calls to `Decimal::trim` can't panic because:
74
74
//
75
75
// 1. `parse_decimal` sets `num_digits` to a max of `Decimal::MAX_DIGITS`.
@@ -83,7 +83,7 @@ impl Decimal {
83
83
}
84
84
}
85
85
86
- pub fn round ( & self ) -> u64 {
86
+ pub ( super ) fn round ( & self ) -> u64 {
87
87
if self . num_digits == 0 || self . decimal_point < 0 {
88
88
return 0 ;
89
89
} else if self . decimal_point > 18 {
@@ -111,7 +111,7 @@ impl Decimal {
111
111
}
112
112
113
113
/// Computes decimal * 2^shift.
114
- pub fn left_shift ( & mut self , shift : usize ) {
114
+ pub ( super ) fn left_shift ( & mut self , shift : usize ) {
115
115
if self . num_digits == 0 {
116
116
return ;
117
117
}
@@ -152,7 +152,7 @@ impl Decimal {
152
152
}
153
153
154
154
/// Computes decimal * 2^-shift.
155
- pub fn right_shift ( & mut self , shift : usize ) {
155
+ pub ( super ) fn right_shift ( & mut self , shift : usize ) {
156
156
let mut read_index = 0 ;
157
157
let mut write_index = 0 ;
158
158
let mut n = 0_u64 ;
@@ -202,7 +202,7 @@ impl Decimal {
202
202
}
203
203
204
204
/// Parse a big integer representation of the float as a decimal.
205
- pub fn parse_decimal ( mut s : & [ u8 ] ) -> Decimal {
205
+ pub ( super ) fn parse_decimal ( mut s : & [ u8 ] ) -> Decimal {
206
206
let mut d = Decimal :: default ( ) ;
207
207
let start = s;
208
208
0 commit comments