// Translated from C to Rust. The original C code can be found at // https://github.com/ulfjack/ryu and carries the following license: // // Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied.
// Computes 5^i in the form required by Ryū. #[cfg_attr(feature = "no-panic", inline)] pubunsafefn compute_pow5(i: u32) -> (u64, u64) { let base = i / DOUBLE_POW5_TABLE.len() as u32; let base2 = base * DOUBLE_POW5_TABLE.len() as u32; let offset = i - base2;
debug_assert!(base < DOUBLE_POW5_SPLIT2.len() as u32); let mul = *DOUBLE_POW5_SPLIT2.get_unchecked(base as usize); if offset == 0 { return mul;
}
debug_assert!(offset < DOUBLE_POW5_TABLE.len() as u32); let m = *DOUBLE_POW5_TABLE.get_unchecked(offset as usize); let b0 = m as u128 * mul.0as u128; let b2 = m as u128 * mul.1as u128; let delta = pow5bits(i as i32) - pow5bits(base2 as i32);
debug_assert!(i / 16 < POW5_OFFSETS.len() as u32); let shifted_sum = (b0 >> delta)
+ (b2 << (64 - delta))
+ ((*POW5_OFFSETS.get_unchecked((i / 16) as usize) >> ((i % 16) << 1)) & 3) as u128;
(shifted_sum as u64, (shifted_sum >> 64) as u64)
}
// Computes 5^-i in the form required by Ryū. #[cfg_attr(feature = "no-panic", inline)] pubunsafefn compute_inv_pow5(i: u32) -> (u64, u64) { let base = (i + DOUBLE_POW5_TABLE.len() as u32 - 1) / DOUBLE_POW5_TABLE.len() as u32; let base2 = base * DOUBLE_POW5_TABLE.len() as u32; let offset = base2 - i;
debug_assert!(base < DOUBLE_POW5_INV_SPLIT2.len() as u32); let mul = *DOUBLE_POW5_INV_SPLIT2.get_unchecked(base as usize); // 1/5^base2 if offset == 0 { return mul;
}
debug_assert!(offset < DOUBLE_POW5_TABLE.len() as u32); let m = *DOUBLE_POW5_TABLE.get_unchecked(offset as usize); // 5^offset let b0 = m as u128 * (mul.0 - 1) as u128; let b2 = m as u128 * mul.1as u128; // 1/5^base2 * 5^offset = 1/5^(base2-offset) = 1/5^i let delta = pow5bits(base2 as i32) - pow5bits(i as i32);
debug_assert!(base < POW5_INV_OFFSETS.len() as u32); let shifted_sum = ((b0 >> delta) + (b2 << (64 - delta)))
+ 1
+ ((*POW5_INV_OFFSETS.get_unchecked((i / 16) as usize) >> ((i % 16) << 1)) & 3) as u128;
(shifted_sum as u64, (shifted_sum >> 64) as u64)
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-22)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.