mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
added spqlios as submodule
This commit is contained in:
31
rns/src/num_bigint.rs
Normal file
31
rns/src/num_bigint.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use num_bigint::BigInt;
|
||||
use num_integer::Integer;
|
||||
use num_traits::{One, Signed, Zero};
|
||||
|
||||
pub trait Div {
|
||||
fn div_floor(&self, other: &Self) -> Self;
|
||||
fn div_round(&self, other: &Self) -> Self;
|
||||
}
|
||||
|
||||
impl Div for BigInt {
|
||||
fn div_floor(&self, other: &Self) -> Self {
|
||||
let quo: BigInt = self / other;
|
||||
if self.sign() != other.sign() {
|
||||
return quo - BigInt::one();
|
||||
}
|
||||
return quo;
|
||||
}
|
||||
|
||||
fn div_round(&self, other: &Self) -> Self {
|
||||
let (quo, mut rem) = self.div_rem(other);
|
||||
rem <<= 1;
|
||||
if rem != BigInt::zero() && &rem.abs() > other {
|
||||
if self.sign() == other.sign() {
|
||||
return quo + BigInt::one();
|
||||
} else {
|
||||
return quo - BigInt::one();
|
||||
}
|
||||
}
|
||||
return quo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user