diff --git a/src/common.rs b/src/common.rs index e28288e..e0a41ab 100644 --- a/src/common.rs +++ b/src/common.rs @@ -22,7 +22,7 @@ use core::ptr; // Returns e == 0 ? 1 : ceil(log_2(5^e)). #[cfg_attr(feature = "no-panic", inline)] -pub fn pow5bits(e: i32) -> u32 { +pub(crate) fn pow5bits(e: i32) -> u32 { // This approximation works up to the point that the multiplication overflows at e = 3529. // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater // than 2^9297. @@ -33,7 +33,7 @@ pub fn pow5bits(e: i32) -> u32 { // Returns floor(log_10(2^e)). #[cfg_attr(feature = "no-panic", inline)] -pub fn log10_pow2(e: i32) -> i32 { +pub(crate) fn log10_pow2(e: i32) -> i32 { // The first value this approximation fails for is 2^1651 which is just greater than 10^297. debug_assert!(e >= 0); debug_assert!(e <= 1650); @@ -42,7 +42,7 @@ pub fn log10_pow2(e: i32) -> i32 { // Returns floor(log_10(5^e)). #[cfg_attr(feature = "no-panic", inline)] -pub fn log10_pow5(e: i32) -> i32 { +pub(crate) fn log10_pow5(e: i32) -> i32 { // The first value this approximation fails for is 5^2621 which is just greater than 10^1832. debug_assert!(e >= 0); debug_assert!(e <= 2620); @@ -50,7 +50,7 @@ pub fn log10_pow5(e: i32) -> i32 { } #[cfg_attr(feature = "no-panic", inline)] -pub unsafe fn copy_special_str(result: *mut u8, sign: bool) -> usize { +pub(crate) unsafe fn copy_special_str(result: *mut u8, sign: bool) -> usize { if sign { ptr::write(result, b'-'); } diff --git a/src/d2s.rs b/src/d2s.rs index 74f8898..8193629 100644 --- a/src/d2s.rs +++ b/src/d2s.rs @@ -27,8 +27,8 @@ use digit_table::*; #[cfg(feature = "no-panic")] use no_panic::no_panic; -pub const DOUBLE_MANTISSA_BITS: u32 = 52; -pub const DOUBLE_EXPONENT_BITS: u32 = 11; +pub(crate) const DOUBLE_MANTISSA_BITS: u32 = 52; +pub(crate) const DOUBLE_EXPONENT_BITS: u32 = 11; const DOUBLE_POW5_INV_BITCOUNT: i32 = 122; const DOUBLE_POW5_BITCOUNT: i32 = 121; @@ -84,7 +84,7 @@ fn mul_shift_all( } #[cfg_attr(feature = "no-panic", inline)] -pub fn decimal_length(v: u64) -> u32 { +pub(crate) fn decimal_length(v: u64) -> u32 { // This is slightly faster than a loop. // The average output length is 16.38 digits, so we check high-to-low. // Function precondition: v is not an 18, 19, or 20-digit number. @@ -129,13 +129,13 @@ pub fn decimal_length(v: u64) -> u32 { } // A floating decimal representing m * 10^e. -pub struct FloatingDecimal64 { +pub(crate) struct FloatingDecimal64 { pub mantissa: u64, pub exponent: i32, } #[cfg_attr(feature = "no-panic", inline)] -pub fn d2d(ieee_mantissa: u64, ieee_exponent: u32) -> FloatingDecimal64 { +pub(crate) fn d2d(ieee_mantissa: u64, ieee_exponent: u32) -> FloatingDecimal64 { let bias = (1u32 << (DOUBLE_EXPONENT_BITS - 1)) - 1; let (e2, m2) = if ieee_exponent == 0 { diff --git a/src/d2s_full_table.rs b/src/d2s_full_table.rs index eac50dc..d9e0bad 100644 --- a/src/d2s_full_table.rs +++ b/src/d2s_full_table.rs @@ -18,7 +18,7 @@ // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. -pub static DOUBLE_POW5_INV_SPLIT: [(u64, u64); 292] = [ +pub(crate) static DOUBLE_POW5_INV_SPLIT: [(u64, u64); 292] = [ (1, 288230376151711744), (3689348814741910324, 230584300921369395), (2951479051793528259, 184467440737095516), @@ -313,7 +313,7 @@ pub static DOUBLE_POW5_INV_SPLIT: [(u64, u64); 292] = [ (14258051472207991719, 179769313486231590), ]; -pub static DOUBLE_POW5_SPLIT: [(u64, u64); 326] = [ +pub(crate) static DOUBLE_POW5_SPLIT: [(u64, u64); 326] = [ (0, 72057594037927936), (0, 90071992547409920), (0, 112589990684262400), diff --git a/src/digit_table.rs b/src/digit_table.rs index d871f03..ee12929 100644 --- a/src/digit_table.rs +++ b/src/digit_table.rs @@ -20,7 +20,7 @@ // A table of all two-digit numbers. This is used to speed up decimal digit // generation by copying pairs of digits into the final output. -pub static DIGIT_TABLE: [u8; 200] = *b"\ +pub(crate) static DIGIT_TABLE: [u8; 200] = *b"\ 0001020304050607080910111213141516171819\ 2021222324252627282930313233343536373839\ 4041424344454647484950515253545556575859\ diff --git a/src/f2s.rs b/src/f2s.rs index fbb2b56..3d931fe 100644 --- a/src/f2s.rs +++ b/src/f2s.rs @@ -26,8 +26,8 @@ use digit_table::*; #[cfg(feature = "no-panic")] use no_panic::no_panic; -pub const FLOAT_MANTISSA_BITS: u32 = 23; -pub const FLOAT_EXPONENT_BITS: u32 = 8; +pub(crate) const FLOAT_MANTISSA_BITS: u32 = 23; +pub(crate) const FLOAT_EXPONENT_BITS: u32 = 8; const FLOAT_POW5_INV_BITCOUNT: i32 = 59; const FLOAT_POW5_BITCOUNT: i32 = 61; @@ -170,7 +170,7 @@ fn mul_pow5_div_pow2(m: u32, i: u32, j: i32) -> u32 { } #[cfg_attr(feature = "no-panic", inline)] -pub fn decimal_length(v: u32) -> u32 { +pub(crate) fn decimal_length(v: u32) -> u32 { // Function precondition: v is not a 10-digit number. // (9 digits are sufficient for round-tripping.) debug_assert!(v < 1000000000); @@ -197,13 +197,13 @@ pub fn decimal_length(v: u32) -> u32 { } // A floating decimal representing m * 10^e. -pub struct FloatingDecimal32 { +pub(crate) struct FloatingDecimal32 { pub mantissa: u32, pub exponent: i32, } #[cfg_attr(feature = "no-panic", inline)] -pub fn f2d(ieee_mantissa: u32, ieee_exponent: u32) -> FloatingDecimal32 { +pub(crate) fn f2d(ieee_mantissa: u32, ieee_exponent: u32) -> FloatingDecimal32 { let bias = (1u32 << (FLOAT_EXPONENT_BITS - 1)) - 1; let (e2, m2) = if ieee_exponent == 0 { diff --git a/src/pretty/exponent.rs b/src/pretty/exponent.rs index ab20825..9644142 100644 --- a/src/pretty/exponent.rs +++ b/src/pretty/exponent.rs @@ -3,7 +3,7 @@ use core::ptr; use digit_table::*; #[cfg_attr(feature = "no-panic", inline)] -pub unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { +pub(crate) unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { let sign = k < 0; if sign { *result = b'-'; @@ -28,7 +28,7 @@ pub unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { } #[cfg_attr(feature = "no-panic", inline)] -pub unsafe fn write_exponent2(mut k: isize, mut result: *mut u8) -> usize { +pub(crate) unsafe fn write_exponent2(mut k: isize, mut result: *mut u8) -> usize { let sign = k < 0; if sign { *result = b'-'; diff --git a/src/pretty/mantissa.rs b/src/pretty/mantissa.rs index 4280232..e083cf4 100644 --- a/src/pretty/mantissa.rs +++ b/src/pretty/mantissa.rs @@ -3,7 +3,7 @@ use core::ptr; use digit_table::*; #[cfg_attr(feature = "no-panic", inline)] -pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { +pub(crate) unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { if (output >> 32) != 0 { // One expensive 64-bit division. let mut output2 = (output - 100_000_000 * (output / 100_000_000)) as u32; @@ -26,7 +26,7 @@ pub unsafe fn write_mantissa_long(mut output: u64, mut result: *mut u8) { } #[cfg_attr(feature = "no-panic", inline)] -pub unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { +pub(crate) unsafe fn write_mantissa(mut output: u32, mut result: *mut u8) { while output >= 10_000 { let c = (output - 10_000 * (output / 10_000)) as u32; output /= 10_000; diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index b68bc36..fb6e592 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -13,7 +13,7 @@ use no_panic::no_panic; #[must_use] #[cfg_attr(feature = "no-panic", no_panic)] -pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { +pub(crate) unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { let bits = f.to_bits().to_le(); let sign = ((bits >> (DOUBLE_MANTISSA_BITS + DOUBLE_EXPONENT_BITS)) & 1) != 0; let ieee_mantissa = bits & ((1u64 << DOUBLE_MANTISSA_BITS) - 1); @@ -85,7 +85,7 @@ pub unsafe fn d2s_buffered_n(f: f64, result: *mut u8) -> usize { #[must_use] #[cfg_attr(feature = "no-panic", no_panic)] -pub unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { +pub(crate) unsafe fn f2s_buffered_n(f: f32, result: *mut u8) -> usize { let bits = f.to_bits().to_le(); let sign = ((bits >> (FLOAT_MANTISSA_BITS + FLOAT_EXPONENT_BITS)) & 1) != 0; let ieee_mantissa = bits & ((1u32 << FLOAT_MANTISSA_BITS) - 1);