1#include "libm.h"
2
3#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
4long double scalbnl(long double x, int n) {
5    return scalbn(x, n);
6}
7#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
8long double scalbnl(long double x, int n) {
9    union ldshape u;
10
11    if (n > 16383) {
12        x *= 0x1p16383L;
13        n -= 16383;
14        if (n > 16383) {
15            x *= 0x1p16383L;
16            n -= 16383;
17            if (n > 16383)
18                n = 16383;
19        }
20    } else if (n < -16382) {
21        x *= 0x1p-16382L;
22        n += 16382;
23        if (n < -16382) {
24            x *= 0x1p-16382L;
25            n += 16382;
26            if (n < -16382)
27                n = -16382;
28        }
29    }
30    u.f = 1.0;
31    u.i.se = 0x3fff + n;
32    return x * u.f;
33}
34#endif
35