Skip to content

Commit

Permalink
use maximum of exponents rather than sum
Browse files Browse the repository at this point in the history
  • Loading branch information
hudson-ai committed Jan 6, 2025
1 parent 974ad4b commit 1b2f294
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions parser/src/json/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ impl Decimal {
if self.coef == 0 || other.coef == 0 {
return Decimal::new(0, 0);
}
let a = self.coef * 10u32.pow(other.exp);
let b = other.coef * 10u32.pow(self.exp);
let a = self.coef * 10u32.pow(other.exp.saturating_sub(self.exp));
let b = other.coef * 10u32.pow(self.exp.saturating_sub(other.exp));
let coef = (a * b) / gcd(a, b);
Decimal::new(coef, self.exp + other.exp)
Decimal::new(coef, self.exp.max(other.exp))
}
}

Expand Down

0 comments on commit 1b2f294

Please sign in to comment.