Skip to content

Commit

Permalink
refactor: switch branch order
Browse files Browse the repository at this point in the history
  • Loading branch information
rflechtner committed Mar 10, 2025
1 parent 58f9ad0 commit faf1dab
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pallets/pallet-bonded-coins/src/curves/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ where
.ok_or(ArithmeticError::Overflow)?;

// Calculate m * (high^2 + high * low + low^2)
let term1 = if self.m != Coefficient::from_num(0u8) {
let term1 = if self.m == Coefficient::from_num(0u8) {
// if m is 0 the product is 0
Ok(self.m)
} else {
let high_low_mul = high.checked_mul(low).ok_or(ArithmeticError::Overflow)?;
let high_square = square(high)?;
let low_square = square(low)?;
Expand All @@ -166,18 +169,15 @@ where
.ok_or(ArithmeticError::Overflow)?;

self.m.checked_mul(cubic_term).ok_or(ArithmeticError::Overflow)
} else {
// if m is 0 the product is 0
Ok(self.m)
}?;

// Calculate n * (high + low)
let term2 = if self.n != Coefficient::from_num(0u8) {
let high_plus_low = high.checked_add(low).ok_or(ArithmeticError::Overflow)?;
self.n.checked_mul(high_plus_low).ok_or(ArithmeticError::Overflow)
} else {
let term2 = if self.n == Coefficient::from_num(0u8) {
// if n is 0 the product is 0
Ok(self.n)
} else {
let high_plus_low = high.checked_add(low).ok_or(ArithmeticError::Overflow)?;
self.n.checked_mul(high_plus_low).ok_or(ArithmeticError::Overflow)
}?;

// Final calculation with factored (high - low)
Expand Down

0 comments on commit faf1dab

Please sign in to comment.