Browse Source

math: fix logb(-0.0) in downward rounding mode

use -1/(x*x) instead of -1/(x+0) to return -inf, -0+0 is -0 in
downward rounding mode
rs-1.0
Szabolcs Nagy 13 years ago
parent
commit
98be442ee8
  1. 4
      src/math/logb.c
  2. 4
      src/math/logbf.c
  3. 4
      src/math/logbl.c

4
src/math/logb.c

@ -1,4 +1,4 @@
#include "libm.h" #include <math.h>
/* /*
special cases: special cases:
@ -12,6 +12,6 @@ double logb(double x)
if (!isfinite(x)) if (!isfinite(x))
return x * x; return x * x;
if (x == 0) if (x == 0)
return -1/(x+0); return -1/(x*x);
return ilogb(x); return ilogb(x);
} }

4
src/math/logbf.c

@ -1,10 +1,10 @@
#include "libm.h" #include <math.h>
float logbf(float x) float logbf(float x)
{ {
if (!isfinite(x)) if (!isfinite(x))
return x * x; return x * x;
if (x == 0) if (x == 0)
return -1/(x+0); return -1/(x*x);
return ilogbf(x); return ilogbf(x);
} }

4
src/math/logbl.c

@ -1,4 +1,4 @@
#include "libm.h" #include <math.h>
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double logbl(long double x) long double logbl(long double x)
{ {
@ -10,7 +10,7 @@ long double logbl(long double x)
if (!isfinite(x)) if (!isfinite(x))
return x * x; return x * x;
if (x == 0) if (x == 0)
return -1/(x+0); return -1/(x*x);
return ilogbl(x); return ilogbl(x);
} }
#endif #endif

Loading…
Cancel
Save