math: clean up atan2.c
[oweals/musl.git] / 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                                 n = 127;
15                 }
16         } else if (n < -126) {
17                 x *= 0x1p-126f;
18                 n += 126;
19                 if (n < -126) {
20                         x *= 0x1p-126f;
21                         n += 126;
22                         if (n < -126)
23                                 n = -126;
24                 }
25         }
26         SET_FLOAT_WORD(scale, (uint32_t)(0x7f+n)<<23);
27         STRICT_ASSIGN(float, x, x * scale);
28         return x;
29 }