rework langinfo code for ABI compat and for use by time code
[musl] / src / math / scalbnf.c
1 #include "libm.h"
2
3 float scalbnf(float x, int n)
4 {
5         float scale;
6
7         if (n > 127) {
8                 x *= 0x1p127f;
9                 n -= 127;
10                 if (n > 127) {
11                         x *= 0x1p127f;
12                         n -= 127;
13                         if (n > 127) {
14                                 STRICT_ASSIGN(float, x, x * 0x1p127f);
15                                 return x;
16                         }
17                 }
18         } else if (n < -126) {
19                 x *= 0x1p-126f;
20                 n += 126;
21                 if (n < -126) {
22                         x *= 0x1p-126f;
23                         n += 126;
24                         if (n < -126) {
25                                 STRICT_ASSIGN(float, x, x * 0x1p-126f);
26                                 return x;
27                         }
28                 }
29         }
30         SET_FLOAT_WORD(scale, (uint32_t)(0x7f+n)<<23);
31         STRICT_ASSIGN(float, x, x * scale);
32         return x;
33 }