最適化

This commit is contained in:
mii8080
2022-05-11 07:05:01 +00:00
committed by GitHub
parent 62640ba448
commit e12a7d40df
4 changed files with 11 additions and 8 deletions

5
.gitignore vendored
View File

@ -7,4 +7,7 @@
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
**/*.rs.bk
flamegraph.svg
perf.data
perf.data.old

View File

@ -78,8 +78,7 @@ impl Sub for FiniteFieldElement {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
let rhs = FiniteFieldElement::new(-rhs.value, rhs.p);
self + rhs
Self::new(self.value - rhs.value, rhs.p)
}
}

View File

@ -1,4 +1,4 @@
use bigdecimal::{BigDecimal, FromPrimitive, Zero, One};
use bigdecimal::{BigDecimal, FromPrimitive, Zero, One, ToPrimitive};
pub fn ext_gcd(a: BigDecimal, b: BigDecimal) -> (BigDecimal, BigDecimal, BigDecimal) {
let mut a = a;
@ -50,11 +50,10 @@ pub fn pow(a: BigDecimal, b: BigDecimal) -> BigDecimal {
}
pub fn down(a: BigDecimal) -> BigDecimal {
return a.clone() - a % BigDecimal::one();
return a.clone() - BigDecimal::from_u128(a.to_u128().unwrap()).unwrap();
}
pub fn floor(a: BigDecimal) -> BigDecimal {
let m = a.clone() % BigDecimal::one();
if a > BigDecimal::zero() {

View File

@ -22,8 +22,10 @@ fn main() {
infinity: false
};
println!("{:?}", ec.add(ecp1.clone(), ecp2));
/*
for x in 0..1000 {
println!("{:?}", ec.clone().add(ecp1.clone(), ecp2.clone()));
}
/*
for x in 1..101 {
for y in 1..101 {
println!("{}, {}: {}", x, y, encrypt::common::math::plusMod(BigDecimal::from_i32(x).unwrap(), BigDecimal::from_i32(y).unwrap()));