Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / modules / fdlibm / src / s_scalbn.cpp
blob13fa7f129dd65f067c7ce7c6200dfa439333f627
1 /*
2 * Copyright (c) 2005-2020 Rich Felker, et al.
4 * SPDX-License-Identifier: MIT
6 * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
7 * for all contributors to musl.
8 */
9 #include <float.h>
10 #include <stdint.h>
12 #include "math_private.h"
14 double scalbn(double x, int n)
16 union {double f; uint64_t i;} u;
17 double_t y = x;
19 if (n > 1023) {
20 y *= 0x1p1023;
21 n -= 1023;
22 if (n > 1023) {
23 y *= 0x1p1023;
24 n -= 1023;
25 if (n > 1023)
26 n = 1023;
28 } else if (n < -1022) {
29 /* make sure final n < -53 to avoid double
30 rounding in the subnormal range */
31 y *= 0x1p-1022 * 0x1p53;
32 n += 1022 - 53;
33 if (n < -1022) {
34 y *= 0x1p-1022 * 0x1p53;
35 n += 1022 - 53;
36 if (n < -1022)
37 n = -1022;
40 u.i = (uint64_t)(0x3ff+n)<<52;
41 x = y * u.f;
42 return x;