}
/* |x| < 0.5 */
if (ix < 0x3fe00000) {
- if (ix < 0x3e500000) {
- /* |x|<0x1p-26, return x with inexact if x!=0*/
- FORCE_EVAL(x + 0x1p120f);
+ /* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
+ if (ix < 0x3e500000 && ix >= 0x00100000)
return x;
- }
return x + x*R(x*x);
}
/* 1 > |x| >= 0.5 */
return 0/(x-x); /* asin(|x|>1) is NaN */
}
if (ix < 0x3f000000) { /* |x| < 0.5 */
- if (ix < 0x39800000) { /* |x| < 2**-12 */
- FORCE_EVAL(x + 0x1p120f);
- return x; /* return x with inexact if x!=0 */
- }
+ /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
+ if (ix < 0x39800000 && ix >= 0x00800000)
+ return x;
return x + x*R(x*x);
}
/* 1 > |x| >= 0.5 */
}
if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
if (ix < 0x3e400000) { /* |x| < 2^-27 */
- /* raise inexact if x!=0 */
- FORCE_EVAL(x + 0x1p120f);
+ if (ix < 0x00100000)
+ /* raise underflow for subnormal x */
+ FORCE_EVAL((float)x);
return x;
}
id = -1;
}
if (ix < 0x3ee00000) { /* |x| < 0.4375 */
if (ix < 0x39800000) { /* |x| < 2**-12 */
- /* raise inexact if x!=0 */
- FORCE_EVAL(x + 0x1p120f);
+ if (ix < 0x00800000)
+ /* raise underflow for subnormal x */
+ FORCE_EVAL(x*x);
return x;
}
id = -1;
return (x-x)/(x-x); /* log1p(x<-1)=NaN */
}
if (ax < 0x3e200000) { /* |x| < 2**-29 */
- /* raise inexact */
- if (two54 + x > 0.0 && ax < 0x3c900000) /* |x| < 2**-54 */
+ /* if 0x1p-1022 <= |x| < 0x1p-54, avoid raising underflow */
+ if (ax < 0x3c900000 && ax >= 0x00100000)
return x;
+#if FLT_EVAL_METHOD != 0
+ FORCE_EVAL((float)x);
+#endif
return x - x*x*0.5;
}
if (hx > 0 || hx <= (int32_t)0xbfd2bec4) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
return (x-x)/(x-x); /* log1p(x<-1)=NaN */
}
if (ax < 0x38000000) { /* |x| < 2**-15 */
- /* raise inexact */
- if (two25 + x > 0.0f && ax < 0x33800000) /* |x| < 2**-24 */
+ /* if 0x1p-126 <= |x| < 0x1p-24, avoid raising underflow */
+ if (ax < 0x33800000 && ax >= 0x00800000)
return x;
+#if FLT_EVAL_METHOD != 0
+ FORCE_EVAL(x*x);
+#endif
return x - x*x*0.5f;
}
if (hx > 0 || hx <= (int32_t)0xbe95f619) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */
t = expm1(absx);
if (w < 0x3ff00000) {
if (w < 0x3ff00000 - (26<<20))
- /* note: inexact is raised by expm1 */
- /* note: this branch avoids underflow */
+ /* note: inexact and underflow are raised by expm1 */
+ /* note: this branch avoids spurious underflow */
return x;
return h*(2*t - t*t/(t+1));
}
union {double f; uint64_t i;} u = {.f = x};
uint32_t w;
int sign;
- double t;
+ double_t t;
/* x = |x| */
sign = u.i >> 63;
if (w > 0x40340000) {
/* |x| > 20 or nan */
/* note: this branch avoids raising overflow */
- /* raise inexact if x!=+-inf and handle nan */
- t = 1 + 0/(x + 0x1p-120f);
+ t = 1 - 0/x;
} else {
t = expm1(2*x);
t = 1 - 2/(t+2);
/* |x| > log(5/3)/2 ~= 0.2554 */
t = expm1(2*x);
t = t/(t+2);
- } else {
- /* |x| is small, up to 2ulp error in [0.1,0.2554] */
+ } else if (w >= 0x00100000) {
+ /* |x| >= 0x1p-1022, up to 2ulp error in [0.1,0.2554] */
t = expm1(-2*x);
t = -t/(t+2);
+ } else {
+ /* |x| is subnormal */
+ /* note: the branch above would not raise underflow in [0x1p-1023,0x1p-1022) */
+ FORCE_EVAL((float)x);
+ t = x;
}
return sign ? -t : t;
}
/* |x| > log(3)/2 ~= 0.5493 or nan */
if (w > 0x41200000) {
/* |x| > 10 */
- t = 1 + 0/(x + 0x1p-120f);
+ t = 1 + 0/x;
} else {
t = expm1f(2*x);
t = 1 - 2/(t+2);
/* |x| > log(5/3)/2 ~= 0.2554 */
t = expm1f(2*x);
t = t/(t+2);
- } else {
- /* |x| is small */
+ } else if (w >= 0x00800000) {
+ /* |x| >= 0x1p-126 */
t = expm1f(-2*x);
t = -t/(t+2);
+ } else {
+ /* |x| is subnormal */
+ FORCE_EVAL(x*x);
+ t = x;
}
return sign ? -t : t;
}