]> git.proxmox.com Git - rustc.git/blobdiff - vendor/ryu/src/common.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / vendor / ryu / src / common.rs
index 29e5cc591bc153e9e34305897575245102004141..9613036a256ff19c0c3011d648a1ff35e3c37743 100644 (file)
@@ -18,6 +18,8 @@
 // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 // KIND, either express or implied.
 
+// Returns the number of decimal digits in v, which must not contain more than 9
+// digits.
 #[cfg_attr(feature = "no-panic", inline)]
 pub fn decimal_length9(v: u32) -> u32 {
     // Function precondition: v is not a 10-digit number.
@@ -45,29 +47,47 @@ pub fn decimal_length9(v: u32) -> u32 {
     }
 }
 
-// Returns e == 0 ? 1 : ceil(log_2(5^e)).
+// Returns e == 0 ? 1 : [log_2(5^e)]; requires 0 <= e <= 3528.
 #[cfg_attr(feature = "no-panic", inline)]
-pub fn pow5bits(e: i32) -> i32 {
-    // 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.
+#[allow(dead_code)]
+pub fn log2_pow5(e: i32) -> i32 /* or u32 -> 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.
+    debug_assert!(e >= 0);
+    debug_assert!(e <= 3528);
+    ((e as u32 * 1217359) >> 19) as i32
+}
+
+// Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528.
+#[cfg_attr(feature = "no-panic", inline)]
+pub fn pow5bits(e: i32) -> i32 /* or u32 -> 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.
     debug_assert!(e >= 0);
     debug_assert!(e <= 3528);
     (((e as u32 * 1217359) >> 19) + 1) as i32
 }
 
-// Returns floor(log_10(2^e)).
 #[cfg_attr(feature = "no-panic", inline)]
-pub fn log10_pow2(e: i32) -> u32 {
+#[allow(dead_code)]
+pub fn ceil_log2_pow5(e: i32) -> i32 /* or u32 -> u32 */ {
+    log2_pow5(e) + 1
+}
+
+// Returns floor(log_10(2^e)); requires 0 <= e <= 1650.
+#[cfg_attr(feature = "no-panic", inline)]
+pub fn log10_pow2(e: i32) -> u32 /* or u32 -> u32 */ {
     // 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);
     (e as u32 * 78913) >> 18
 }
 
-// Returns floor(log_10(5^e)).
+// Returns floor(log_10(5^e)); requires 0 <= e <= 2620.
 #[cfg_attr(feature = "no-panic", inline)]
-pub fn log10_pow5(e: i32) -> u32 {
+pub fn log10_pow5(e: i32) -> u32 /* or u32 -> u32 */ {
     // 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);