Skip to content
Snippets Groups Projects
Commit f61fb859 authored by Raymond Toy's avatar Raymond Toy
Browse files

Fix a couple of issues in the code.

 * Use fdlibm_setexception to handle the case when the arg is NaN or
   Inf. (Previously depended on x+x doing the right thing.)
 * Fix a compiler warning about possible dangling else by adding
   braces as needed.
parent 33adf3d4
No related branches found
No related tags found
No related merge requests found
......@@ -52,15 +52,24 @@ tiny = 1.0e-300;
k = ((hx&0x7ff00000)>>20) - 54;
if (n< -50000) return fdlibm_setexception(x, FDLIBM_UNDERFLOW);; /*underflow*/
}
if (k==0x7ff) return x+x; /* NaN or Inf */
if (k==0x7ff) {
/* NaN or Inf */
if(((hx&0xfffff)|lx)!=0) {
return fdlibm_setexception(x, FDLIBM_INVALID);
} else {
return fdlibm_setexception(x, FDLIBM_OVERFLOW);
}
}
k = k+n;
if (k > 0x7fe) return fdlibm_setexception(x, FDLIBM_OVERFLOW); /* overflow */
if (k > 0) /* normal result */
{ux.i[HIWORD] = (hx&0x800fffff)|(k<<20); return x;}
if (k <= -54)
if (k <= -54) {
if (n > 50000) /* in case integer overflow in n+k */
return fdlibm_setexception(x, FDLIBM_OVERFLOW); /*overflow*/
else return fdlibm_setexception(x, FDLIBM_UNDERFLOW); /*underflow*/
}
k += 54; /* subnormal result */
ux.i[HIWORD] = (hx&0x800fffff)|(k<<20);
return x*twom54;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment