| OLD | NEW |
| 1 #include "libm.h" | 1 #include "libm.h" |
| 2 | 2 |
| 3 float modff(float x, float *iptr) | 3 float modff(float x, float* iptr) { |
| 4 { | 4 union { |
| 5 » union {float f; uint32_t i;} u = {x}; | 5 float f; |
| 6 » uint32_t mask; | 6 uint32_t i; |
| 7 » int e = (int)(u.i>>23 & 0xff) - 0x7f; | 7 } u = {x}; |
| 8 uint32_t mask; |
| 9 int e = (int)(u.i >> 23 & 0xff) - 0x7f; |
| 8 | 10 |
| 9 » /* no fractional part */ | 11 /* no fractional part */ |
| 10 » if (e >= 23) { | 12 if (e >= 23) { |
| 11 » » *iptr = x; | 13 *iptr = x; |
| 12 » » if (e == 0x80 && u.i<<9 != 0) { /* nan */ | 14 if (e == 0x80 && u.i << 9 != 0) { /* nan */ |
| 13 » » » return x; | 15 return x; |
| 14 » » } | 16 } |
| 15 » » u.i &= 0x80000000; | 17 u.i &= 0x80000000; |
| 16 » » return u.f; | 18 return u.f; |
| 17 » } | 19 } |
| 18 » /* no integral part */ | 20 /* no integral part */ |
| 19 » if (e < 0) { | 21 if (e < 0) { |
| 20 » » u.i &= 0x80000000; | 22 u.i &= 0x80000000; |
| 21 » » *iptr = u.f; | 23 *iptr = u.f; |
| 22 » » return x; | 24 return x; |
| 23 » } | 25 } |
| 24 | 26 |
| 25 » mask = 0x007fffff>>e; | 27 mask = 0x007fffff >> e; |
| 26 » if ((u.i & mask) == 0) { | 28 if ((u.i & mask) == 0) { |
| 27 » » *iptr = x; | 29 *iptr = x; |
| 28 » » u.i &= 0x80000000; | 30 u.i &= 0x80000000; |
| 29 » » return u.f; | 31 return u.f; |
| 30 » } | 32 } |
| 31 » u.i &= ~mask; | 33 u.i &= ~mask; |
| 32 » *iptr = u.f; | 34 *iptr = u.f; |
| 33 » return x - u.f; | 35 return x - u.f; |
| 34 } | 36 } |
| OLD | NEW |