diff --git a/libs/libm/libm/lib_log.c b/libs/libm/libm/lib_log.c index 9b8e23b97d477..87a1744972c5d 100644 --- a/libs/libm/libm/lib_log.c +++ b/libs/libm/libm/lib_log.c @@ -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) diff --git a/libs/libm/libm/lib_logf.c b/libs/libm/libm/lib_logf.c index 35672915b44e3..73b0afbaf145a 100644 --- a/libs/libm/libm/lib_logf.c +++ b/libs/libm/libm/lib_logf.c @@ -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)