TODO update
[libm] / src / math / frexpl.c
1 #include <math.h>
2 #include <stdint.h>
3 #include <float.h>
4
5 #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
6
7 /* This version is for 80-bit little endian long double */
8
9 long double frexpl(long double x, int *e)
10 {
11         union { long double ld; uint16_t hw[5]; } y = { x };
12         int ee = y.hw[4]&0x7fff;
13
14         if (!ee) {
15                 if (x) {
16                         x = frexpl(x*0x1p64, e);
17                         *e -= 64;
18                 } else *e = 0;
19                 return x;
20         } else if (ee == 0x7fff) {
21                 return x;
22         }
23
24         *e = ee - 0x3ffe;
25         y.hw[4] &= 0x8000;
26         y.hw[4] |= 0x3ffe;
27         return y.ld;
28 }
29
30 #else
31
32 long double frexpl(long double x, int *e)
33 {
34         return frexp(x, e);
35 }
36
37 #endif