mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 21:40:12 +00:00
da2f4f2dd5
As noted in bug 6803, scalbn fails to set errno on overflow and underflow. This patch fixes this by making scalbn an alias of ldexp, which has exactly the same semantics (for floating-point types with radix 2) and already has wrappers that deal with setting errno, instead of an alias of the internal __scalbn (which ldexp calls). Notes: * Where compat symbols were defined for scalbn functions, I didn't change what they point to (to keep the patch minimal), so such compat symbols continue to go directly to the non-errno-setting functions. * Mike, I didn't do anything with the IA64 versions of these functions, where I think both the ldexp and scalbn functions already deal with setting errno. As a cleanup (not needed to fix this bug) however you might want to make those functions into aliases for IA64; there is no need for them to be separate function implementations at all. * This concludes the fix for bug 6803 since the scalb and scalbln cases of that bug were fixed some time ago. Tested for x86_64, x86, mips64 and powerpc. [BZ #6803] * math/s_ldexp.c (scalbn): Define as weak alias of __ldexp. [NO_LONG_DOUBLE] (scalbnl): Define as weak alias of __ldexp. * math/s_ldexpf.c (scalbnf): Define as weak alias of __ldexpf. * math/s_ldexpl.c (scalbnl): Define as weak alias of __ldexpl. * sysdeps/i386/fpu/s_scalbn.S (scalbn): Remove alias. * sysdeps/i386/fpu/s_scalbnf.S (scalbnf): Likewise. * sysdeps/i386/fpu/s_scalbnl.S (scalbnl): Likewise. * sysdeps/ieee754/dbl-64/s_scalbn.c (scalbn): Likewise. [NO_LONG_DOUBLE] (scalbnl): Likewise. * sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c (scalbn): Likewise. [NO_LONG_DOUBLE] (scalbnl): Likewise. * sysdeps/ieee754/flt-32/s_scalbnf.c (scalbnf): Likewise. * sysdeps/ieee754/ldbl-128/s_scalbnl.c (scalbnl): Likewise. * sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c (scalbnl): Remove long_double_symbol calls. * sysdeps/ieee754/ldbl-64-128/s_scalbnl.c (scalbnl): Likewise. * sysdeps/ieee754/ldbl-opt/s_ldexpl.c (__ldexpl_2): Define as strong alias of __ldexpl. (scalbnl): Define using long_double_symbol. * sysdeps/m68k/m680x0/fpu/s_scalbn.c (__CONCATX(scalbn,suffix)): Remove alias. * sysdeps/sparc/sparc64/soft-fp/s_scalbnl.c (scalbnl): Likewise. * sysdeps/x86_64/fpu/s_scalbnl.S (scalbnl): Likewise. * math/libm-test.inc (scalbn_test_data): Add errno expectations. (scalbln_test_data): Add more errno expectations.
105 lines
2.8 KiB
C
105 lines
2.8 KiB
C
/* s_scalbnl.c -- long double version of s_scalbn.c.
|
|
* Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
|
|
*/
|
|
|
|
/* @(#)s_scalbn.c 5.1 93/09/24 */
|
|
/*
|
|
* ====================================================
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
*
|
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
* Permission to use, copy, modify, and distribute this
|
|
* software is freely granted, provided that this notice
|
|
* is preserved.
|
|
* ====================================================
|
|
*/
|
|
|
|
#if defined(LIBM_SCCS) && !defined(lint)
|
|
static char rcsid[] = "$NetBSD: $";
|
|
#endif
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include <math.h>
|
|
#include <math_private.h>
|
|
#include <math_ldbl_opt.h>
|
|
|
|
static const long double
|
|
twolm54 = 5.55111512312578270212e-17, /* 0x3C90000000000000, 0 */
|
|
huge = 1.0E+300L,
|
|
tiny = 1.0E-300L;
|
|
static const double
|
|
two54 = 1.80143985094819840000e+16, /* 0x4350000000000000 */
|
|
twom54 = 5.55111512312578270212e-17; /* 0x3C90000000000000 */
|
|
|
|
long double __scalbnl (long double x, int n)
|
|
{
|
|
int64_t k,l,hx,lx;
|
|
union { int64_t i; double d; } u;
|
|
double xhi, xlo;
|
|
|
|
ldbl_unpack (x, &xhi, &xlo);
|
|
EXTRACT_WORDS64 (hx, xhi);
|
|
EXTRACT_WORDS64 (lx, xlo);
|
|
k = (hx>>52)&0x7ff; /* extract exponent */
|
|
l = (lx>>52)&0x7ff;
|
|
if (k==0) { /* 0 or subnormal x */
|
|
if ((hx&0x7fffffffffffffffULL)==0) return x; /* +-0 */
|
|
u.i = hx;
|
|
u.d *= two54;
|
|
hx = u.i;
|
|
k = ((hx>>52)&0x7ff) - 54;
|
|
}
|
|
else if (k==0x7ff) return x+x; /* NaN or Inf */
|
|
if (n< -50000) return tiny*__copysignl(tiny,x); /*underflow */
|
|
if (n> 50000 || k+n > 0x7fe)
|
|
return huge*__copysignl(huge,x); /* overflow */
|
|
/* Now k and n are bounded we know that k = k+n does not
|
|
overflow. */
|
|
k = k+n;
|
|
if (k > 0) { /* normal result */
|
|
hx = (hx&0x800fffffffffffffULL)|(k<<52);
|
|
if ((lx & 0x7fffffffffffffffULL) == 0) { /* low part +-0 */
|
|
INSERT_WORDS64 (xhi, hx);
|
|
INSERT_WORDS64 (xlo, lx);
|
|
x = ldbl_pack (xhi, xlo);
|
|
return x;
|
|
}
|
|
if (l == 0) { /* low part subnormal */
|
|
u.i = lx;
|
|
u.d *= two54;
|
|
lx = u.i;
|
|
l = ((lx>>52)&0x7ff) - 54;
|
|
}
|
|
l = l + n;
|
|
if (l > 0)
|
|
lx = (lx&0x800fffffffffffffULL)|(l<<52);
|
|
else if (l <= -54)
|
|
lx = (lx&0x8000000000000000ULL);
|
|
else {
|
|
l += 54;
|
|
u.i = (lx&0x800fffffffffffffULL)|(l<<52);
|
|
u.d *= twom54;
|
|
lx = u.i;
|
|
}
|
|
INSERT_WORDS64 (xhi, hx);
|
|
INSERT_WORDS64 (xlo, lx);
|
|
x = ldbl_pack (xhi, xlo);
|
|
return x;
|
|
}
|
|
if (k <= -54)
|
|
return tiny*__copysignl(tiny,x); /*underflow*/
|
|
k += 54; /* subnormal result */
|
|
lx &= 0x8000000000000000ULL;
|
|
hx &= 0x800fffffffffffffULL;
|
|
INSERT_WORDS64 (xhi, hx|(k<<52));
|
|
INSERT_WORDS64 (xlo, lx);
|
|
x = ldbl_pack (xhi, xlo);
|
|
return x*twolm54;
|
|
}
|