nuttx/libm: fix powl wrong if first parameter is negative

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2024-09-29 23:12:33 +02:00 committed by Xiang Xiao
parent 6b3f51986d
commit 776035ee9e

View file

@ -41,6 +41,22 @@
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double powl(long double b, long double e)
{
return expl(e * logl(b));
if (b > 0.0)
{
return expl(e * logl(b));
}
else if (b < 0.0 && e == (int)e)
{
if ((int)e % 2 == 0)
{
return expl(e * logl(fabsl(b)));
}
else
{
return -expl(e * logl(fabsl(b)));
}
}
return 0.0;
}
#endif