Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement pow function for integer exponent. #638

Merged
merged 6 commits into from
Jan 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix x.powu(0)
schungx committed Jan 13, 2024
commit 822cc0c9ffd7bf0ad28de0521c47d85f6b40452a
5 changes: 4 additions & 1 deletion src/maths.rs
Original file line number Diff line number Diff line change
@@ -227,6 +227,9 @@ impl MathematicalOps for Decimal {
}

fn checked_powu(&self, exp: u64) -> Option<Decimal> {
if exp == 0 {
return Some(Decimal::ONE);
}
if self.is_zero() {
return Some(Decimal::ZERO);
}
@@ -235,7 +238,7 @@ impl MathematicalOps for Decimal {
}

match exp {
0 => Some(Decimal::ONE),
0 => unreachable!(),
1 => Some(*self),
2 => self.checked_mul(*self),
// Do the exponentiation by multiplying squares: