We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In function Bigint::pow there are two indentical recruisive calls, that could be replaced by just one call Consider changing
Bigint Bigint::pow(int const &power, std::map<int, Bigint> &lookup) { if (power == 1) return *this; if (lookup.count(power)) return lookup[power]; int closestPower = 1; while (closestPower < power) closestPower <<= 1; closestPower >>= 1; //here pow(power / 2, lookup) is called twice if (power == closestPower) lookup[power] = pow(power / 2, lookup) * pow(power / 2, lookup); else lookup[power] = pow(closestPower, lookup) * pow(power - closestPower, lookup); return lookup[power]; }
to
Bigint Bigint::pow(int const &power, std::map<int, Bigint> &lookup) { if (power == 1) return *this; if (lookup.count(power)) return lookup[power]; int closestPower = 1; while (closestPower < power) closestPower <<= 1; closestPower >>= 1; if (power == closestPower) { auto tmp = pow(power / 2, lookup); lookup[power] = tmp * tmp; } else { lookup[power] = pow(closestPower, lookup) * pow(power - closestPower, lookup); } return lookup[power]; }
The text was updated successfully, but these errors were encountered:
fix kasparsklavins#28 - replaces extra pow recursive call with simple…
3db8095
… multiplication as suggested in issue
No branches or pull requests
In function Bigint::pow there are two indentical recruisive calls, that could be replaced by just one call
Consider changing
to
The text was updated successfully, but these errors were encountered: