Debian Codegraph @

modules/fdlibm/src/s_scalbnf.cpp

raw
1 /*
2 * Copyright (c) 2005-2020 Rich Felker, et al.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
7 * for all contributors to musl.
8 */
9 #include <stdint.h>
10
11 #include "math_private.h"
12
13 float scalbnf(float x, int n)
14 {
15 union {float f; uint32_t i;} u;
16 float y = x;
17
18 if (n > 127) {
19 y *= 0x1p127f;
20 n -= 127;
21 if (n > 127) {
22 y *= 0x1p127f;
23 n -= 127;
24 if (n > 127)
25 n = 127;
26 }
27 } else if (n < -126) {
28 y *= 0x1p-126f * 0x1p24f;
29 n += 126 - 24;
30 if (n < -126) {
31 y *= 0x1p-126f * 0x1p24f;
32 n += 126 - 24;
33 if (n < -126)
34 n = -126;
35 }
36 }
37 u.i = (uint32_t)(0x7f+n)<<23;
38 x = y * u.f;
39 return x;
40 }