2012-03-13 01:17:53 -04:00
|
|
|
#include <limits.h>
|
|
|
|
#include "libm.h"
|
|
|
|
|
|
|
|
int ilogbf(float x)
|
|
|
|
{
|
|
|
|
union fshape u = {x};
|
|
|
|
int e = u.bits>>23 & 0xff;
|
|
|
|
|
|
|
|
if (!e) {
|
|
|
|
u.bits <<= 9;
|
2012-11-12 23:58:18 +01:00
|
|
|
if (u.bits == 0) {
|
|
|
|
FORCE_EVAL(0/0.0f);
|
2012-03-13 01:17:53 -04:00
|
|
|
return FP_ILOGB0;
|
2012-11-12 23:58:18 +01:00
|
|
|
}
|
2012-03-13 01:17:53 -04:00
|
|
|
/* subnormal x */
|
|
|
|
for (e = -0x7f; u.bits < (uint32_t)1<<31; e--, u.bits<<=1);
|
|
|
|
return e;
|
|
|
|
}
|
2012-11-12 23:58:18 +01:00
|
|
|
if (e == 0xff) {
|
|
|
|
FORCE_EVAL(0/0.0f);
|
2012-03-13 01:17:53 -04:00
|
|
|
return u.bits<<9 ? FP_ILOGBNAN : INT_MAX;
|
2012-11-12 23:58:18 +01:00
|
|
|
}
|
2012-03-13 01:17:53 -04:00
|
|
|
return e - 0x7f;
|
|
|
|
}
|