fix BasicParser power function

This commit is contained in:
MihailRis 2026-07-06 12:44:09 +03:00
parent 26d4801da4
commit c45d994216
2 changed files with 25 additions and 2 deletions

View file

@ -22,9 +22,26 @@ namespace {
}
inline double power(double base, int64_t power) {
if (power == 0) {
return 1.0;
}
uint64_t exp;
if (power < 0) {
base = 1.0 / base;
exp = static_cast<uint64_t>(-(power + 1)) + 1;
} else {
exp = static_cast<uint64_t>(power);
}
double result = 1.0;
for (int64_t i = 0; i < power; i++) {
result *= base;
while (exp > 0) {
if (exp & 1)
result *= base;
base *= base;
exp >>= 1;
}
return result;
}