Skip to content

Commit

Permalink
Improve implementation of exp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCG-coder committed Aug 17, 2024
1 parent 686aa03 commit d2e9796
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/calc/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,21 @@ namespace steppable::__internals::arithmetic

std::string exp(const std::string& x, const size_t decimals)
{
constexpr size_t iter = 200;
std::string sum = "1";
std::string term = "1";
for (size_t i = 1; i < iter; i++)
if (compare(x, "20", 0) == "0")
{
std::string frac = divide(x, std::to_string(i), 0, static_cast<int>(decimals));
term = multiply(term, frac, 0);
sum = add(sum, term, 0);
constexpr size_t iter = 200;
std::string sum = "1";
std::string term = "1";
for (size_t i = 1; i < iter; i++)
{
std::string frac = divide(x, std::to_string(i), 0, static_cast<int>(decimals));
term = multiply(term, frac, 0);
sum = add(sum, term, 0);
}
return sum;
}

return sum;
return power(exp(divide(x, "4", 0, decimals)), "4", 0);
}
} // namespace steppable::__internals::arithmetic

Expand Down

0 comments on commit d2e9796

Please sign in to comment.