Use the FP_ILOG macros from <math.h> rather than hardcoded return values.
Also be prepared for FP_ILOGBNAN != INT_MAX. Reviewed by: md5
This commit is contained in:
parent
6c266abf24
commit
5cd961bbfe
@ -16,10 +16,13 @@ static char rcsid[] = "$FreeBSD$";
|
||||
|
||||
/* ilogb(double x)
|
||||
* return the binary exponent of non-zero x
|
||||
* ilogb(0) = 0x80000001
|
||||
* ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
|
||||
* ilogb(0) = FP_ILOGB0
|
||||
* ilogb(NaN) = FP_ILOGBNAN (no signal is raised)
|
||||
* ilogb(inf) = INT_MAX (no signal is raised)
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
@ -31,7 +34,7 @@ static char rcsid[] = "$FreeBSD$";
|
||||
hx &= 0x7fffffff;
|
||||
if(hx<0x00100000) {
|
||||
if((hx|lx)==0)
|
||||
return 0x80000001; /* ilogb(0) = 0x80000001 */
|
||||
return FP_ILOGB0;
|
||||
else /* subnormal x */
|
||||
if(hx==0) {
|
||||
for (ix = -1043; lx>0; lx<<=1) ix -=1;
|
||||
@ -41,5 +44,6 @@ static char rcsid[] = "$FreeBSD$";
|
||||
return ix;
|
||||
}
|
||||
else if (hx<0x7ff00000) return (hx>>20)-1023;
|
||||
else return 0x7fffffff;
|
||||
else if (hx>0x7ff00000 || lx!=0) return FP_ILOGBNAN;
|
||||
else return INT_MAX;
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
@ -28,11 +30,12 @@ static char rcsid[] = "$FreeBSD$";
|
||||
hx &= 0x7fffffff;
|
||||
if(hx<0x00800000) {
|
||||
if(hx==0)
|
||||
return 0x80000001; /* ilogb(0) = 0x80000001 */
|
||||
return FP_ILOGB0;
|
||||
else /* subnormal x */
|
||||
for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
|
||||
return ix;
|
||||
}
|
||||
else if (hx<0x7f800000) return (hx>>23)-127;
|
||||
else return 0x7fffffff;
|
||||
else if (hx>0x7f800000) return FP_ILOGBNAN;
|
||||
else return INT_MAX;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user