Fixed pow() for negative bases.

This commit is contained in:
Fotis Panagiotopoulos 2022-09-02 18:50:54 +03:00 committed by Xiang Xiao
parent 4cd4303c32
commit 985710665a
1 changed files with 17 additions and 1 deletions

View File

@ -41,6 +41,22 @@
#ifdef CONFIG_HAVE_DOUBLE
double pow(double b, double e)
{
return exp(e * log(b));
if (b > 0)
{
return exp(e * log(b));
}
else if (b < 0 && e == (int)e)
{
if ((int)e % 2 == 0)
{
return exp(e * log(fabs(b)));
}
else
{
return -exp(e * log(fabs(b)));
}
}
return 0;
}
#endif