diff --git a/lib/msun/src/s_scalbn.c b/lib/msun/src/s_scalbn.c index 3de663f8b670..2d4f7a3c6164 100644 --- a/lib/msun/src/s_scalbn.c +++ b/lib/msun/src/s_scalbn.c @@ -1,39 +1,47 @@ +/* + * Copyright (c) 2005-2020 Rich Felker, et al. + * + * SPDX-License-Identifier: MIT + * + * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT + * for all contributors to musl. + */ #include #include #include double scalbn(double x, int n) { union {double f; uint64_t i;} u; double_t y = x; if (n > 1023) { y *= 0x1p1023; n -= 1023; if (n > 1023) { y *= 0x1p1023; n -= 1023; if (n > 1023) n = 1023; } } else if (n < -1022) { /* make sure final n < -53 to avoid double rounding in the subnormal range */ y *= 0x1p-1022 * 0x1p53; n += 1022 - 53; if (n < -1022) { y *= 0x1p-1022 * 0x1p53; n += 1022 - 53; if (n < -1022) n = -1022; } } u.i = (uint64_t)(0x3ff+n)<<52; x = y * u.f; return x; } #if (LDBL_MANT_DIG == 53) && !defined(scalbn) __weak_reference(scalbn, ldexpl); __weak_reference(scalbn, scalbnl); #endif diff --git a/lib/msun/src/s_scalbnf.c b/lib/msun/src/s_scalbnf.c index 3a46470b5661..8cf1e01150da 100644 --- a/lib/msun/src/s_scalbnf.c +++ b/lib/msun/src/s_scalbnf.c @@ -1,33 +1,41 @@ +/* + * Copyright (c) 2005-2020 Rich Felker, et al. + * + * SPDX-License-Identifier: MIT + * + * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT + * for all contributors to musl. + */ #include #include float scalbnf(float x, int n) { union {float f; uint32_t i;} u; float_t y = x; if (n > 127) { y *= 0x1p127f; n -= 127; if (n > 127) { y *= 0x1p127f; n -= 127; if (n > 127) n = 127; } } else if (n < -126) { y *= 0x1p-126f * 0x1p24f; n += 126 - 24; if (n < -126) { y *= 0x1p-126f * 0x1p24f; n += 126 - 24; if (n < -126) n = -126; } } u.i = (uint32_t)(0x7f+n)<<23; x = y * u.f; return x; } __strong_reference(scalbnf, ldexpf); diff --git a/lib/msun/src/s_scalbnl.c b/lib/msun/src/s_scalbnl.c index a79f79b33480..6044c1b1d4f7 100644 --- a/lib/msun/src/s_scalbnl.c +++ b/lib/msun/src/s_scalbnl.c @@ -1,41 +1,49 @@ +/* + * Copyright (c) 2005-2020 Rich Felker, et al. + * + * SPDX-License-Identifier: MIT + * + * Please see https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT + * for all contributors to musl. + */ #include #include #include "math_private.h" #include "fpmath.h" /* * scalbnl (long double x, int n) * scalbnl(x,n) returns x* 2**n computed by exponent * manipulation rather than by actually performing an * exponentiation or a multiplication. */ #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 long double scalbnl(long double x, int n) { union IEEEl2bits u; if (n > 16383) { x *= 0x1p16383L; n -= 16383; if (n > 16383) { x *= 0x1p16383L; n -= 16383; if (n > 16383) n = 16383; } } else if (n < -16382) { x *= 0x1p-16382L * 0x1p113L; n += 16382 - 113; if (n < -16382) { x *= 0x1p-16382L * 0x1p113L; n += 16382 - 113; if (n < -16382) n = -16382; } } u.e = 1.0; u.xbits.expsign = 0x3fff + n; return x * u.e; } __strong_reference(scalbnl, ldexpl); #endif