libc/match: Use of exp() vs expf() in logf() caused function to be slow.
This commit is contained in:
parent
1182702b80
commit
0ef127e273
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Ported by: Darcy Gong
|
||||
*
|
||||
* It derives from the Rhombus OS math library by Nick Johnson which has
|
||||
@ -38,19 +38,26 @@
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: logf
|
||||
****************************************************************************/
|
||||
|
||||
float logf(float x)
|
||||
{
|
||||
float y, y_old, ey, epsilon;
|
||||
float y;
|
||||
float y_old;
|
||||
float ey;
|
||||
float epsilon;
|
||||
|
||||
y = 0.0F;
|
||||
y_old = 1.0F;
|
||||
y = 0.0F;
|
||||
y_old = 1.0F;
|
||||
epsilon = FLT_EPSILON;
|
||||
|
||||
while (y > y_old + epsilon || y < y_old - epsilon)
|
||||
{
|
||||
y_old = y;
|
||||
ey = exp(y);
|
||||
y -= (ey - x) / ey;
|
||||
ey = expf(y);
|
||||
y -= (ey - x) / ey;
|
||||
|
||||
if (y > FLT_MAX_EXP_X)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Ported by: Darcy Gong
|
||||
*
|
||||
* It derives from the Rhombus OS math library by Nick Johnson which has
|
||||
@ -42,17 +42,20 @@
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double logl(long double x)
|
||||
{
|
||||
long double y, y_old, ey, epsilon;
|
||||
long double y;
|
||||
long double y_old;
|
||||
long double ey;
|
||||
long double epsilon;
|
||||
|
||||
y = 0.0;
|
||||
y_old = 1.0;
|
||||
y = 0.0;
|
||||
y_old = 1.0;
|
||||
epsilon = LDBL_EPSILON;
|
||||
|
||||
while (y > y_old + epsilon || y < y_old - epsilon)
|
||||
{
|
||||
y_old = y;
|
||||
ey = expl(y);
|
||||
y -= (ey - x) / ey;
|
||||
ey = expl(y);
|
||||
y -= (ey - x) / ey;
|
||||
|
||||
if (y > 700.0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user