Skip to content

Commit

Permalink
Remove while loop in constant case for sub_op
Browse files Browse the repository at this point in the history
  • Loading branch information
wwared committed Feb 17, 2024
1 parent 4582eb6 commit 8a6ed04
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/emulated/src/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bellpepper_core::num::{AllocatedNum, Num};
use bellpepper_core::{ConstraintSystem, LinearCombination, SynthesisError};
use ff::{PrimeField, PrimeFieldBits};
use num_bigint::BigInt;
use num_traits::{One, Zero};
use num_traits::One;

use crate::field_element::{EmulatedFieldElement, EmulatedFieldParams, EmulatedLimbs};
use crate::util::{bigint_to_scalar, decompose, recompose};
Expand Down Expand Up @@ -435,11 +435,11 @@ where
if a.is_constant() && b.is_constant() {
let a_int = BigInt::from(a);
let b_int = BigInt::from(b);
let mut res_int = a_int - b_int;
while res_int < BigInt::zero() {
res_int += P::modulus();
}
res_int = res_int.rem(P::modulus());
let res_int = if a_int > b_int {
(a_int - b_int).rem(P::modulus())
} else {
P::modulus() - (b_int - a_int).rem(P::modulus())
};
return Ok(Self::from(&res_int));
}

Expand Down

0 comments on commit 8a6ed04

Please sign in to comment.