use num_bigint::{BigUint, RandBigInt}; use test::Bencher;
mod rng; use rng::get_rng;
// The `big64` cases demonstrate the speed of cases where the value // can be converted to a `u64` primitive for faster calculation. // // The `big1k` cases demonstrate those that can convert to `f64` for // a better initial guess of the actual value. // // The `big2k` and `big4k` cases are too big for `f64`, and use a simpler guess.
fn check(x: &BigUint, n: u32) { let root = x.nth_root(n); if n == 2 {
assert_eq!(root, x.sqrt())
} elseif n == 3 {
assert_eq!(root, x.cbrt())
}
let lo = root.pow(n);
assert!(lo <= *x);
assert_eq!(lo.nth_root(n), root);
assert_eq!((&lo - 1u32).nth_root(n), &root - 1u32);
let hi = (&root + 1u32).pow(n);
assert!(hi > *x);
assert_eq!(hi.nth_root(n), &root + 1u32);
assert_eq!((&hi - 1u32).nth_root(n), root);
}
fn bench_sqrt(b: &mut Bencher, bits: u64) { let x = get_rng().gen_biguint(bits);
eprintln!("bench_sqrt({})", x);
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.