abacus: bignum: simplify is_canonicalized
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a382b299b0
commit
c9460c09d5
|
@ -385,15 +385,15 @@ bool BigNum::is_canonicalized() const {
|
||||||
return sign_ == 0;
|
return sign_ == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const leading_zeros = std::find_if(digits_.rbegin(), digits_.rend(),
|
// `back` is valid since there is at least one element
|
||||||
[](auto v) { return v != 0; });
|
auto const has_leading_zero = digits_.back() == 0;
|
||||||
if (leading_zeros != digits_.rbegin()) {
|
if (has_leading_zero) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const overflow = std::find_if(digits_.begin(), digits_.end(),
|
auto const has_overflow = std::any_of(digits_.begin(), digits_.end(),
|
||||||
[](auto v) { return v >= BASE; });
|
[](auto v) { return v >= BASE; });
|
||||||
if (overflow != digits_.end()) {
|
if (has_overflow) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue