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:
Stefan Farfeleder 2004-10-09 17:14:28 +00:00
parent e2494b93fc
commit 552ebda9dd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136332
2 changed files with 13 additions and 6 deletions

View file

@ -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;
}

View file

@ -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;
}