nuttx/libm: Fix powf wrong if first parameter is negative

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
This commit is contained in:
yanghuatao 2023-12-15 14:35:20 +08:00 committed by Xiang Xiao
parent 347154c01e
commit 7cd38dca6a
1 changed files with 17 additions and 1 deletions

View File

@ -37,5 +37,21 @@
float powf(float b, float e)
{
return expf(e * logf(b));
if (b > 0.0)
{
return expf(e * logf(b));
}
else if (b < 0.0 && e == (int)e)
{
if ((int)e % 2 == 0)
{
return expf(e * logf(fabsf(b)));
}
else
{
return -expf(e * logf(fabsf(b)));
}
}
return 0.0;
}