projects
/
musl
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
floating point environment/exceptions support for mips
[musl]
/
src
/
math
/
modff.c
1
#include <math.h>
2
#include <stdint.h>
3
4
float modff(float x, float *iptr)
5
{
6
union {float x; uint32_t n;} u = {x};
7
uint32_t mask;
8
int e;
9
10
e = (int)(u.n>>23 & 0xff) - 0x7f;
11
12
/* no fractional part */
13
if (e >= 23) {
14
*iptr = x;
15
if (e == 0x80 && u.n<<9 != 0) { /* nan */
16
return x;
17
}
18
u.n &= 0x80000000;
19
return u.x;
20
}
21
/* no integral part */
22
if (e < 0) {
23
u.n &= 0x80000000;
24
*iptr = u.x;
25
return x;
26
}
27
28
mask = 0x007fffff>>e;
29
if ((u.n & mask) == 0) {
30
*iptr = x;
31
u.n &= 0x80000000;
32
return u.x;
33
}
34
u.n &= ~mask;
35
*iptr = u.x;
36
return x - *iptr;
37
}