aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/ieee754/ldbl-128ibm
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-03-02 15:32:56 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-03-02 15:32:56 +0000
commita6d06d7b86f724046b462115556d0df682f9f703 (patch)
tree640870a7d978c8a224fe317e862b65fddba6f40e /sysdeps/ieee754/ldbl-128ibm
parent07e12bb391ae84eb74817d42feda42cff7f687e5 (diff)
downloadglibc-a6d06d7b86f724046b462115556d0df682f9f703.zip
glibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.gz
glibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.bz2
Fix scalbn, scalbln integer overflow.
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm')
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c8
-rw-r--r--sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c b/sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c
index a1632e7..2c30d1c 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_scalblnl.c
@@ -52,10 +52,12 @@ long double __scalblnl (long double x, long int n)
k = ((hx>>52)&0x7ff) - 54;
}
else if (k==0x7ff) return x+x; /* NaN or Inf */
- k = k+n;
- if (n> 50000 || k > 0x7fe)
- return huge*__copysignl(huge,x); /* overflow */
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 */
diff --git a/sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c b/sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c
index a52cd42..48102ef 100644
--- a/sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/s_scalbnl.c
@@ -52,10 +52,12 @@ long double __scalbnl (long double x, int n)
k = ((hx>>52)&0x7ff) - 54;
}
else if (k==0x7ff) return x+x; /* NaN or Inf */
- k = k+n;
- if (n> 50000 || k > 0x7fe)
- return huge*__copysignl(huge,x); /* overflow */
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 */