I have the following code snippet:
use num_bigint::*; // 0.2.2
use num_traits::*; // 0.2.8
use std::ops::*;
fn xgcd(b: &BigInt, a: &BigInt) -> (BigInt, BigInt, BigInt) {
let mut x0: BigInt = One::one();
let mut x1: BigInt = Zero::zero();
let mut y0: BigInt = Zero::zero();
let mut y1: BigInt = One::one();
let mut q = 0;
while a != Zero::zero() {
q = b.div(a);
b = a;
a = &b.rem(a);
x0 = x1;
x1 = x0 - q * x1;
y0 = y1;
y1 = y0 - q * y1;
}
return (*b, x0, y0);
}
It gives the following error:
error[E0308]: mismatched types
--> src/lib.rs:12:13
|
12 | q = b.div(a);
| ^^^^^^^^ expected integer, found struct `num_bigint::bigint::BigInt`
|
= note: expected type `{integer}`
found type `num_bigint::bigint::BigInt`
I've looked up the documentation of num::BigInt
and it states that there is in fact a div
method with a BigInt
as a parameter, but somehow the compiler decides not to use it and instead tells me that I can't divide a BigInt
with a BigInt
. Is there any way to fix this?