about summary refs log tree commit diff
path: root/sysdeps/ieee754/flt-32/s_scalbnf.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/ieee754/flt-32/s_scalbnf.c')
-rw-r--r--sysdeps/ieee754/flt-32/s_scalbnf.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sysdeps/ieee754/flt-32/s_scalbnf.c b/sysdeps/ieee754/flt-32/s_scalbnf.c
index 3be2925a03..a7cb1a1a49 100644
--- a/sysdeps/ieee754/flt-32/s_scalbnf.c
+++ b/sysdeps/ieee754/flt-32/s_scalbnf.c
@@ -35,11 +35,13 @@ __scalbnf (float x, int n)
 	    k = ((ix&0x7f800000)>>23) - 25;
 	    }
 	if (__builtin_expect(k==0xff, 0)) return x+x;	/* NaN or Inf */
-	k = k+n;
-	if (__builtin_expect(n> 50000 || k >  0xfe, 0))
-	  return huge*__copysignf(huge,x); /* overflow  */
 	if (__builtin_expect(n< -50000, 0))
 	  return tiny*__copysignf(tiny,x);	/*underflow*/
+	if (__builtin_expect(n> 50000 || k+n > 0xfe, 0))
+	  return huge*__copysignf(huge,x); /* overflow  */
+	/* Now k and n are bounded we know that k = k+n does not
+	   overflow.  */
+	k = k+n;
 	if (__builtin_expect(k > 0, 1))		/* normal result */
 	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
 	if (k <= -25)