chore(math): replace malachite lib with dashu (#542)

This commit is contained in:
Andrew Westberg 2024-12-14 19:45:32 +00:00 committed by GitHub
parent fcfc5af253
commit 1e5c267823
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 102 additions and 102 deletions

View file

@ -12,8 +12,8 @@ authors = ["Andrew Westberg <andrewwestberg@gmail.com>"]
exclude = ["tests/data/*"] exclude = ["tests/data/*"]
[dependencies] [dependencies]
malachite = "0.4.16" dashu-int = "0.4.1"
malachite-base = "0.4.16" dashu-base = "0.4.1"
regex = "1.10.5" regex = "1.10.5"
thiserror = "1.0.61" thiserror = "1.0.61"

View file

@ -1,2 +1,2 @@
pub mod math; pub mod math;
pub mod math_malachite; pub mod math_dashu;

View file

@ -7,7 +7,7 @@ use std::ops::{Div, Mul, Neg, Sub};
use std::sync::LazyLock; use std::sync::LazyLock;
use thiserror::Error; use thiserror::Error;
pub type FixedDecimal = crate::math_malachite::Decimal; pub type FixedDecimal = crate::math_dashu::Decimal;
pub static ZERO: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(0u64)); pub static ZERO: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(0u64));
pub static MINUS_ONE: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(-1i64)); pub static MINUS_ONE: LazyLock<FixedDecimal> = LazyLock::new(|| FixedDecimal::from(-1i64));
@ -95,7 +95,7 @@ pub struct ExpCmpOrdering {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use malachite_base::num::arithmetic::traits::Abs; use dashu_base::Abs;
use proptest::prelude::Strategy; use proptest::prelude::Strategy;
use proptest::proptest; use proptest::proptest;
use std::fs::File; use std::fs::File;

View file

@ -3,12 +3,8 @@
*/ */
use crate::math::{Error, ExpCmpOrdering, ExpOrdering, FixedPrecision, DEFAULT_PRECISION}; use crate::math::{Error, ExpCmpOrdering, ExpOrdering, FixedPrecision, DEFAULT_PRECISION};
use malachite::num::arithmetic::traits::{Abs, DivRem, DivRound, Pow, PowAssign}; use dashu_base::{Abs, DivRem, Sign};
use malachite::num::basic::traits::One; use dashu_int::{IBig, UBig};
use malachite::platform_64::Limb;
use malachite::rounding_modes::RoundingMode;
use malachite::{Integer, Natural};
use malachite_base::num::arithmetic::traits::{Parity, Sign};
use regex::Regex; use regex::Regex;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
@ -19,8 +15,8 @@ use std::sync::LazyLock;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Decimal { pub struct Decimal {
precision: u64, precision: u64,
precision_multiplier: Integer, precision_multiplier: IBig,
data: Integer, data: IBig,
} }
impl PartialEq for Decimal { impl PartialEq for Decimal {
@ -59,7 +55,7 @@ impl Display for Decimal {
impl From<u64> for Decimal { impl From<u64> for Decimal {
fn from(n: u64) -> Self { fn from(n: u64) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = Integer::from(n) * &result.precision_multiplier; result.data = IBig::from(n) * &result.precision_multiplier;
result result
} }
} }
@ -67,50 +63,46 @@ impl From<u64> for Decimal {
impl From<i64> for Decimal { impl From<i64> for Decimal {
fn from(n: i64) -> Self { fn from(n: i64) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = Integer::from(n) * &result.precision_multiplier; result.data = IBig::from(n) * &result.precision_multiplier;
result result
} }
} }
impl From<Integer> for Decimal { impl From<IBig> for Decimal {
fn from(n: Integer) -> Self { fn from(n: IBig) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = n * &result.precision_multiplier; result.data = n * &result.precision_multiplier;
result result
} }
} }
impl From<&Integer> for Decimal { impl From<&IBig> for Decimal {
fn from(n: &Integer) -> Self { fn from(n: &IBig) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = n * &result.precision_multiplier; result.data = n * &result.precision_multiplier;
result result
} }
} }
impl From<Natural> for Decimal { impl From<UBig> for Decimal {
fn from(n: Natural) -> Self { fn from(n: UBig) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = Integer::from(n) * &result.precision_multiplier; result.data = IBig::from(n) * &result.precision_multiplier;
result result
} }
} }
impl From<&Natural> for Decimal { impl From<&UBig> for Decimal {
fn from(n: &Natural) -> Self { fn from(n: &UBig) -> Self {
let mut result = Decimal::new(DEFAULT_PRECISION); let mut result = Decimal::new(DEFAULT_PRECISION);
result.data = Integer::from(n) * &result.precision_multiplier; result.data = IBig::from(n.clone()) * &result.precision_multiplier;
result result
} }
} }
impl From<&[u8]> for Decimal { impl From<&[u8]> for Decimal {
fn from(n: &[u8]) -> Self { fn from(n: &[u8]) -> Self {
let limbs = n Decimal::from(UBig::from_be_bytes(n))
.chunks(size_of::<u64>())
.map(|chunk| Limb::from_be_bytes(chunk.try_into().expect("Infallible")))
.collect();
Decimal::from(Natural::from_owned_limbs_desc(limbs))
} }
} }
@ -296,9 +288,9 @@ impl<'a, 'b> AddAssign<&'b Decimal> for &'a mut Decimal {
impl FixedPrecision for Decimal { impl FixedPrecision for Decimal {
fn new(precision: u64) -> Self { fn new(precision: u64) -> Self {
let mut precision_multiplier = Integer::from(10); let mut precision_multiplier = IBig::from(10);
precision_multiplier.pow_assign(precision); precision_multiplier = precision_multiplier.pow(precision as usize);
let data = Integer::from(0); let data = IBig::from(0);
Decimal { Decimal {
precision, precision,
precision_multiplier, precision_multiplier,
@ -315,7 +307,7 @@ impl FixedPrecision for Decimal {
} }
let mut decimal = Decimal::new(precision); let mut decimal = Decimal::new(precision);
decimal.data = Integer::from_str(s).unwrap(); decimal.data = IBig::from_str(s).unwrap();
Ok(decimal) Ok(decimal)
} }
@ -359,10 +351,10 @@ impl FixedPrecision for Decimal {
fn round(&self) -> Self { fn round(&self) -> Self {
let mut result = self.clone(); let mut result = self.clone();
let half = &self.precision_multiplier / Integer::from(2); let half = &self.precision_multiplier / IBig::from(2);
let remainder = &self.data % &self.precision_multiplier; let remainder = &self.data % &self.precision_multiplier;
if (&remainder).abs() >= half { if (&remainder).abs() >= half {
if self.data.sign() == Ordering::Less { if self.data.sign() == Sign::Negative {
result.data -= &self.precision_multiplier + remainder; result.data -= &self.precision_multiplier + remainder;
} else { } else {
result.data += &self.precision_multiplier - remainder; result.data += &self.precision_multiplier - remainder;
@ -376,7 +368,7 @@ impl FixedPrecision for Decimal {
fn floor(&self) -> Self { fn floor(&self) -> Self {
let mut result = self.clone(); let mut result = self.clone();
let remainder = &self.data % &self.precision_multiplier; let remainder = &self.data % &self.precision_multiplier;
if self.data.sign() == Ordering::Less && remainder != 0 { if self.data.sign() == Sign::Negative && remainder != ZERO.value {
result.data -= &self.precision_multiplier; result.data -= &self.precision_multiplier;
} }
result.data -= remainder; result.data -= remainder;
@ -386,7 +378,7 @@ impl FixedPrecision for Decimal {
fn ceil(&self) -> Self { fn ceil(&self) -> Self {
let mut result = self.clone(); let mut result = self.clone();
let remainder = &self.data % &self.precision_multiplier; let remainder = &self.data % &self.precision_multiplier;
if self.data.sign() == Ordering::Greater && remainder != 0 { if self.data.sign() == Sign::Positive && remainder != ZERO.value {
result.data += &self.precision_multiplier; result.data += &self.precision_multiplier;
} }
result.data -= remainder; result.data -= remainder;
@ -400,7 +392,7 @@ impl FixedPrecision for Decimal {
} }
} }
fn print_fixedp(n: &Integer, precision: &Integer, width: usize) -> String { fn print_fixedp(n: &IBig, precision: &IBig, width: usize) -> String {
let (mut temp_q, mut temp_r) = n.div_rem(precision); let (mut temp_q, mut temp_r) = n.div_rem(precision);
let is_negative_q = temp_q < ZERO.value; let is_negative_q = temp_q < ZERO.value;
@ -430,11 +422,11 @@ fn print_fixedp(n: &Integer, precision: &Integer, width: usize) -> String {
} }
struct Constant { struct Constant {
value: Integer, value: IBig,
} }
impl Constant { impl Constant {
pub fn new(init: fn() -> Integer) -> Constant { pub fn new(init: fn() -> IBig) -> Constant {
Constant { value: init() } Constant { value: init() }
} }
} }
@ -443,24 +435,33 @@ unsafe impl Sync for Constant {}
unsafe impl Send for Constant {} unsafe impl Send for Constant {}
static DIGITS_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^-?\d+$").unwrap()); static DIGITS_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^-?\d+$").unwrap());
static TEN: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| Integer::from(10))); static TEN: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| IBig::from(10)));
static PRECISION: LazyLock<Constant> = static PRECISION: LazyLock<Constant> =
LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34))); LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34)));
static EPS: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34 - 24))); static EPS: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| TEN.value.clone().pow(34 - 24)));
static ONE: LazyLock<Constant> = static ONE: LazyLock<Constant> =
LazyLock::new(|| Constant::new(|| Integer::from(1) * &PRECISION.value)); LazyLock::new(|| Constant::new(|| IBig::from(1) * &PRECISION.value));
static ZERO: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| Integer::from(0))); static ZERO: LazyLock<Constant> = LazyLock::new(|| Constant::new(|| IBig::from(0)));
static E: LazyLock<Constant> = LazyLock::new(|| { static E: LazyLock<Constant> = LazyLock::new(|| {
Constant::new(|| { Constant::new(|| {
let mut e = Integer::from(0); let mut e = IBig::from(0);
ref_exp(&mut e, &ONE.value); ref_exp(&mut e, &ONE.value);
e e
}) })
}); });
fn div_round_ceil(x: &IBig, y: &IBig) -> IBig {
let (q, r) = x.div_rem(y);
if q.sign() == Sign::Positive && r != IBig::ZERO {
q + IBig::ONE
} else {
q
}
}
/// Entry point for 'exp' approximation. First does the scaling of 'x' to [0,1] /// Entry point for 'exp' approximation. First does the scaling of 'x' to [0,1]
/// and then calls the continued fraction approximation function. /// and then calls the continued fraction approximation function.
fn ref_exp(rop: &mut Integer, x: &Integer) -> i32 { fn ref_exp(rop: &mut IBig, x: &IBig) -> i32 {
let mut iterations = 0; let mut iterations = 0;
match x.cmp(&ZERO.value) { match x.cmp(&ZERO.value) {
Ordering::Equal => { Ordering::Equal => {
@ -469,13 +470,13 @@ fn ref_exp(rop: &mut Integer, x: &Integer) -> i32 {
} }
Ordering::Less => { Ordering::Less => {
let x_ = -x; let x_ = -x;
let mut temp = Integer::from(0); let mut temp = IBig::from(0);
iterations = ref_exp(&mut temp, &x_); iterations = ref_exp(&mut temp, &x_);
// rop = 1 / temp // rop = 1 / temp
div(rop, &ONE.value, &temp); div(rop, &ONE.value, &temp);
} }
Ordering::Greater => { Ordering::Greater => {
let (n_exponent, _) = x.div_round(&PRECISION.value, RoundingMode::Ceiling); let n_exponent = div_round_ceil(x, &PRECISION.value);
let x_ = x / &n_exponent; let x_ = x / &n_exponent;
iterations = mp_exp_taylor(rop, 1000, &x_, &EPS.value); iterations = mp_exp_taylor(rop, 1000, &x_, &EPS.value);
@ -490,15 +491,15 @@ fn ref_exp(rop: &mut Integer, x: &Integer) -> i32 {
/// Division with quotent and remainder /// Division with quotent and remainder
#[inline] #[inline]
fn div_qr(q: &mut Integer, r: &mut Integer, x: &Integer, y: &Integer) { fn div_qr(q: &mut IBig, r: &mut IBig, x: &IBig, y: &IBig) {
(*q, *r) = x.div_rem(y); (*q, *r) = x.div_rem(y);
} }
/// Division /// Division
pub fn div(rop: &mut Integer, x: &Integer, y: &Integer) { pub fn div(rop: &mut IBig, x: &IBig, y: &IBig) {
let mut temp_q = Integer::from(0); let mut temp_q = IBig::from(0);
let mut temp_r = Integer::from(0); let mut temp_r = IBig::from(0);
let mut temp: Integer; let mut temp: IBig;
div_qr(&mut temp_q, &mut temp_r, x, y); div_qr(&mut temp_q, &mut temp_r, x, y);
temp = &temp_q * &PRECISION.value; temp = &temp_q * &PRECISION.value;
@ -509,8 +510,9 @@ pub fn div(rop: &mut Integer, x: &Integer, y: &Integer) {
temp += &temp_q; temp += &temp_q;
*rop = temp; *rop = temp;
} }
/// Taylor / MacLaurin series approximation /// Taylor / MacLaurin series approximation
fn mp_exp_taylor(rop: &mut Integer, max_n: i32, x: &Integer, epsilon: &Integer) -> i32 { fn mp_exp_taylor(rop: &mut IBig, max_n: i32, x: &IBig, epsilon: &IBig) -> i32 {
let mut divisor = ONE.value.clone(); let mut divisor = ONE.value.clone();
let mut last_x = ONE.value.clone(); let mut last_x = ONE.value.clone();
rop.clone_from(&ONE.value); rop.clone_from(&ONE.value);
@ -534,27 +536,27 @@ fn mp_exp_taylor(rop: &mut Integer, max_n: i32, x: &Integer, epsilon: &Integer)
n n
} }
pub(crate) fn scale(rop: &mut Integer) { pub(crate) fn scale(rop: &mut IBig) {
let mut temp = Integer::from(0); let mut temp = IBig::from(0);
let mut a = Integer::from(0); let mut a = IBig::from(0);
div_qr(&mut a, &mut temp, rop, &PRECISION.value); div_qr(&mut a, &mut temp, rop, &PRECISION.value);
if *rop < ZERO.value && temp != ZERO.value { if *rop < ZERO.value && temp != ZERO.value {
a -= Integer::ONE; a -= IBig::ONE;
} }
*rop = a; *rop = a;
} }
/// Integer power internal function /// Integer power internal function
fn ipow_(rop: &mut Integer, x: &Integer, n: i64) { fn ipow_(rop: &mut IBig, x: &IBig, n: i64) {
if n == 0 { if n == 0 {
rop.clone_from(&ONE.value); rop.clone_from(&ONE.value);
} else if n % 2 == 0 { } else if n % 2 == 0 {
let mut res = Integer::from(0); let mut res = IBig::from(0);
ipow_(&mut res, x, n / 2); ipow_(&mut res, x, n / 2);
*rop = &res * &res; *rop = &res * &res;
scale(rop); scale(rop);
} else { } else {
let mut res = Integer::from(0); let mut res = IBig::from(0);
ipow_(&mut res, x, n - 1); ipow_(&mut res, x, n - 1);
*rop = res * x; *rop = res * x;
scale(rop); scale(rop);
@ -562,9 +564,9 @@ fn ipow_(rop: &mut Integer, x: &Integer, n: i64) {
} }
/// Integer power /// Integer power
fn ipow(rop: &mut Integer, x: &Integer, n: i64) { fn ipow(rop: &mut IBig, x: &IBig, n: i64) {
if n < 0 { if n < 0 {
let mut temp = Integer::from(0); let mut temp = IBig::from(0);
ipow_(&mut temp, x, -n); ipow_(&mut temp, x, -n);
div(rop, &ONE.value, &temp); div(rop, &ONE.value, &temp);
} else { } else {
@ -576,32 +578,32 @@ fn ipow(rop: &mut Integer, x: &Integer, n: i64) {
/// maximum of 'maxN' iterations or until the absolute difference between two /// maximum of 'maxN' iterations or until the absolute difference between two
/// succeeding convergents is smaller than 'eps'. Assumes 'x' to be within /// succeeding convergents is smaller than 'eps'. Assumes 'x' to be within
/// [1,e). /// [1,e).
fn mp_ln_n(rop: &mut Integer, max_n: i32, x: &Integer, epsilon: &Integer) { fn mp_ln_n(rop: &mut IBig, max_n: i32, x: &IBig, epsilon: &IBig) {
let mut ba: Integer; let mut ba: IBig;
let mut aa: Integer; let mut aa: IBig;
let mut ab: Integer; let mut ab: IBig;
let mut bb: Integer; let mut bb: IBig;
let mut a_: Integer; let mut a_: IBig;
let mut b_: Integer; let mut b_: IBig;
let mut diff: Integer; let mut diff: IBig;
let mut convergent: Integer = Integer::from(0); let mut convergent: IBig = IBig::from(0);
let mut last: Integer = Integer::from(0); let mut last: IBig = IBig::from(0);
let mut first = true; let mut first = true;
let mut n = 1; let mut n = 1;
let mut a: Integer; let mut a: IBig;
let mut b = ONE.value.clone(); let mut b = ONE.value.clone();
let mut an_m2 = ONE.value.clone(); let mut an_m2 = ONE.value.clone();
let mut bn_m2 = Integer::from(0); let mut bn_m2 = IBig::from(0);
let mut an_m1 = Integer::from(0); let mut an_m1 = IBig::from(0);
let mut bn_m1 = ONE.value.clone(); let mut bn_m1 = ONE.value.clone();
let mut curr_a = 1; let mut curr_a = 1;
while n <= max_n + 2 { while n <= max_n + 2 {
let curr_a_2 = curr_a * curr_a; let curr_a_2 = curr_a * curr_a;
a = x * Integer::from(curr_a_2); a = x * IBig::from(curr_a_2);
if n > 1 && n % 2 == 1 { if n > 1 && n % 2 == 1 {
curr_a += 1; curr_a += 1;
} }
@ -643,9 +645,9 @@ fn mp_ln_n(rop: &mut Integer, max_n: i32, x: &Integer, epsilon: &Integer) {
*rop = convergent; *rop = convergent;
} }
fn find_e(x: &Integer) -> i64 { fn find_e(x: &IBig) -> i64 {
let mut x_: Integer = Integer::from(0); let mut x_: IBig = IBig::from(0);
let mut x__: Integer = E.value.clone(); let mut x__: IBig = E.value.clone();
div(&mut x_, &ONE.value, &E.value); div(&mut x_, &ONE.value, &E.value);
@ -678,16 +680,16 @@ fn find_e(x: &Integer) -> i64 {
/// Entry point for 'ln' approximation. First does the necessary scaling, and /// Entry point for 'ln' approximation. First does the necessary scaling, and
/// then calls the continued fraction calculation. For any value outside the /// then calls the continued fraction calculation. For any value outside the
/// domain, i.e., 'x in (-inf,0]', the function returns '-INFINITY'. /// domain, i.e., 'x in (-inf,0]', the function returns '-INFINITY'.
fn ref_ln(rop: &mut Integer, x: &Integer) -> bool { fn ref_ln(rop: &mut IBig, x: &IBig) -> bool {
let mut factor = Integer::from(0); let mut factor = IBig::from(0);
let mut x_ = Integer::from(0); let mut x_ = IBig::from(0);
if x <= &ZERO.value { if x <= &ZERO.value {
return false; return false;
} }
let n = find_e(x); let n = find_e(x);
*rop = Integer::from(n); *rop = IBig::from(n);
*rop = &*rop * &PRECISION.value; *rop = &*rop * &PRECISION.value;
ref_exp(&mut factor, rop); ref_exp(&mut factor, rop);
@ -702,9 +704,9 @@ fn ref_ln(rop: &mut Integer, x: &Integer) -> bool {
true true
} }
fn ref_pow(rop: &mut Integer, base: &Integer, exponent: &Integer) { fn ref_pow(rop: &mut IBig, base: &IBig, exponent: &IBig) {
/* x^y = exp(y * ln x) */ /* x^y = exp(y * ln x) */
let mut tmp: Integer = Integer::from(0); let mut tmp: IBig = IBig::from(0);
if exponent == &ZERO.value || base == &ONE.value { if exponent == &ZERO.value || base == &ONE.value {
// any base to the power of zero is one, or 1 to any power is 1 // any base to the power of zero is one, or 1 to any power is 1
@ -731,13 +733,11 @@ fn ref_pow(rop: &mut Integer, base: &Integer, exponent: &Integer) {
debug_assert!(ref_ln); debug_assert!(ref_ln);
tmp *= exponent; tmp *= exponent;
scale(&mut tmp); scale(&mut tmp);
let mut tmp_rop = Integer::from(0); let mut tmp_rop = IBig::from(0);
ref_exp(&mut tmp_rop, &tmp); ref_exp(&mut tmp_rop, &tmp);
*rop = if (exponent / &PRECISION.value).even() { let (_, rem) = (exponent / &PRECISION.value).div_rem(&IBig::from(2));
tmp_rop // check if rem is even
} else { *rop = if rem == IBig::ZERO { tmp_rop } else { -tmp_rop };
-tmp_rop
};
} else { } else {
// base is positive, ref_ln result is valid // base is positive, ref_ln result is valid
let ref_ln = ref_ln(&mut tmp, base); let ref_ln = ref_ln(&mut tmp, base);
@ -759,20 +759,20 @@ fn ref_pow(rop: &mut Integer, base: &Integer, exponent: &Integer) {
/// Lagrange remainder require knowledge of the maximum value to compute the /// Lagrange remainder require knowledge of the maximum value to compute the
/// maximal error of the remainder. /// maximal error of the remainder.
fn ref_exp_cmp( fn ref_exp_cmp(
rop: &mut Integer, rop: &mut IBig,
max_n: u64, max_n: u64,
x: &Integer, x: &IBig,
bound_x: i64, bound_x: i64,
compare: &Integer, compare: &IBig,
) -> ExpCmpOrdering { ) -> ExpCmpOrdering {
rop.clone_from(&ONE.value); rop.clone_from(&ONE.value);
let mut n = 0u64; let mut n = 0u64;
let mut divisor: Integer; let mut divisor: IBig;
let mut next_x: Integer; let mut next_x: IBig;
let mut error: Integer; let mut error: IBig;
let mut upper: Integer; let mut upper: IBig;
let mut lower: Integer; let mut lower: IBig;
let mut error_term: Integer; let mut error_term: IBig;
divisor = ONE.value.clone(); divisor = ONE.value.clone();
error = x.clone(); error = x.clone();
@ -792,7 +792,7 @@ fn ref_exp_cmp(
scale(&mut error); scale(&mut error);
let e2 = error.clone(); let e2 = error.clone();
div(&mut error, &e2, &divisor); div(&mut error, &e2, &divisor);
error_term = &error * Integer::from(bound_x); error_term = &error * IBig::from(bound_x);
*rop = &*rop + &next_x; *rop = &*rop + &next_x;
/* compare is guaranteed to be above overall result */ /* compare is guaranteed to be above overall result */