2012-03-13 01:17:53 -04:00
|
|
|
#include "libm.h"
|
|
|
|
|
|
|
|
float modff(float x, float *iptr)
|
|
|
|
{
|
2012-03-19 23:27:45 +01:00
|
|
|
uint32_t u, mask;
|
|
|
|
int e;
|
2012-03-13 01:17:53 -04:00
|
|
|
|
2012-03-19 23:27:45 +01:00
|
|
|
GET_FLOAT_WORD(u, x);
|
|
|
|
e = (int)(u>>23 & 0xff) - 0x7f;
|
|
|
|
|
|
|
|
/* no fractional part */
|
|
|
|
if (e >= 23) {
|
|
|
|
*iptr = x;
|
|
|
|
if (e == 0x80 && u<<9 != 0) /* nan */
|
2012-03-13 01:17:53 -04:00
|
|
|
return x;
|
2012-03-19 23:27:45 +01:00
|
|
|
SET_FLOAT_WORD(x, u & 0x80000000);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
/* no integral part */
|
|
|
|
if (e < 0) {
|
|
|
|
SET_FLOAT_WORD(*iptr, u & 0x80000000);
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = 0x007fffff>>e;
|
|
|
|
if ((u & mask) == 0) {
|
|
|
|
*iptr = x;
|
|
|
|
SET_FLOAT_WORD(x, u & 0x80000000);
|
2012-03-13 01:17:53 -04:00
|
|
|
return x;
|
|
|
|
}
|
2012-03-19 23:27:45 +01:00
|
|
|
SET_FLOAT_WORD(*iptr, u & ~mask);
|
|
|
|
return x - *iptr;
|
2012-03-13 01:17:53 -04:00
|
|
|
}
|