blob: 6044c1b1d4f7aedf5da0cc169144cdf305b26b22 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
Elliott Hughes99ef4472022-01-12 17:51:20 -08002 * Copyright (c) 2005-2020 Rich Felker, et al.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 *
Elliott Hughes99ef4472022-01-12 17:51:20 -08004 * SPDX-License-Identifier: MIT
5 *
6 * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
7 * for all contributors to musl.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08008 */
Elliott Hughes99ef4472022-01-12 17:51:20 -08009#include <math.h>
10#include <float.h>
11#include "math_private.h"
12#include "fpmath.h"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080013/*
14 * scalbnl (long double x, int n)
15 * scalbnl(x,n) returns x* 2**n computed by exponent
16 * manipulation rather than by actually performing an
17 * exponentiation or a multiplication.
18 */
Elliott Hughes99ef4472022-01-12 17:51:20 -080019#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
20long double scalbnl(long double x, int n)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080021{
22 union IEEEl2bits u;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080023
Elliott Hughes99ef4472022-01-12 17:51:20 -080024 if (n > 16383) {
25 x *= 0x1p16383L;
26 n -= 16383;
27 if (n > 16383) {
28 x *= 0x1p16383L;
29 n -= 16383;
30 if (n > 16383)
31 n = 16383;
32 }
33 } else if (n < -16382) {
34 x *= 0x1p-16382L * 0x1p113L;
35 n += 16382 - 113;
36 if (n < -16382) {
37 x *= 0x1p-16382L * 0x1p113L;
38 n += 16382 - 113;
39 if (n < -16382)
40 n = -16382;
41 }
42 }
43 u.e = 1.0;
44 u.xbits.expsign = 0x3fff + n;
45 return x * u.e;
46}
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080047__strong_reference(scalbnl, ldexpl);
Elliott Hughes99ef4472022-01-12 17:51:20 -080048#endif
49