libs/libm/libm: apply epsilon relax factor only if epsilon is small
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
9cfb10069c
commit
02b1e895e2
|
@ -64,15 +64,15 @@ double log(double x)
|
|||
double y_old;
|
||||
double ey;
|
||||
double epsilon;
|
||||
double relax_factor;
|
||||
double rf; /* epsilon relax factor */
|
||||
int iter;
|
||||
|
||||
y = 0.0;
|
||||
y_old = 1.0;
|
||||
epsilon = DBL_EPSILON;
|
||||
|
||||
iter = 0;
|
||||
relax_factor = 1.0;
|
||||
iter = 0;
|
||||
rf = 1.0;
|
||||
|
||||
while (y > y_old + epsilon || y < y_old - epsilon)
|
||||
{
|
||||
|
@ -90,18 +90,13 @@ double log(double x)
|
|||
y = -DBL_MAX_EXP_X;
|
||||
}
|
||||
|
||||
epsilon = (fabs(y) > 1.0) ? fabs(y) * DBL_EPSILON : DBL_EPSILON;
|
||||
epsilon = ((fabs(y) > rf) ? fabs(y) : rf) * DBL_EPSILON;
|
||||
|
||||
if (++iter >= LOG_MAX_ITER)
|
||||
{
|
||||
relax_factor *= LOG_RELAX_MULTIPLIER;
|
||||
rf *= LOG_RELAX_MULTIPLIER;
|
||||
iter = 0;
|
||||
}
|
||||
|
||||
if (relax_factor > 1.0)
|
||||
{
|
||||
epsilon *= relax_factor;
|
||||
}
|
||||
}
|
||||
|
||||
if (y == DBL_MAX_EXP_X)
|
||||
|
|
|
@ -60,15 +60,15 @@ float logf(float x)
|
|||
float y_old;
|
||||
float ey;
|
||||
float epsilon;
|
||||
float relax_factor;
|
||||
float rf; /* epsilon relax factor */
|
||||
int iter;
|
||||
|
||||
y = 0.0F;
|
||||
y_old = 1.0F;
|
||||
y = 0.0F;
|
||||
y_old = 1.0F;
|
||||
epsilon = FLT_EPSILON;
|
||||
|
||||
iter = 0;
|
||||
relax_factor = 1.0F;
|
||||
iter = 0;
|
||||
rf = 1.0F;
|
||||
|
||||
while (y > y_old + epsilon || y < y_old - epsilon)
|
||||
{
|
||||
|
@ -86,18 +86,13 @@ float logf(float x)
|
|||
y = -FLT_MAX_EXP_X;
|
||||
}
|
||||
|
||||
epsilon = (fabsf(y) > 1.0F) ? fabsf(y) * FLT_EPSILON : FLT_EPSILON;
|
||||
epsilon = ((fabsf(y) > rf) ? fabsf(y) : rf) * FLT_EPSILON;
|
||||
|
||||
if (++iter >= LOGF_MAX_ITER)
|
||||
{
|
||||
relax_factor *= LOGF_RELAX_MULTIPLIER;
|
||||
rf *= LOGF_RELAX_MULTIPLIER;
|
||||
iter = 0;
|
||||
}
|
||||
|
||||
if (relax_factor > 1.0F)
|
||||
{
|
||||
epsilon *= relax_factor;
|
||||
}
|
||||
}
|
||||
|
||||
if (y == FLT_MAX_EXP_X)
|
||||
|
|
Loading…
Reference in New Issue