initial check-in, version 0.5.0
[musl] / src / stdlib / frexpl.c
1 #include <math.h>
2 #include <inttypes.h>
3
4 /* This version is for 80-bit little endian long double */
5
6 long double frexpl(long double x, int *e)
7 {
8         union { long double ld; uint16_t hw[5]; } y = { x };
9         int ee = y.hw[4]&0x7fff;
10
11         if (!ee) {
12                 if (x) {
13                         x = frexpl(x*0x1p64, e);
14                         *e -= 64;
15                 } else *e = 0;
16                 return x;
17         } else if (ee == 0x7fff) {
18                 return x;
19         }
20
21         *e = ee - 0x3ffe;
22         y.hw[4] &= 0x8000;
23         y.hw[4] |= 0x3ffe;
24         return y.ld;
25 }