From f61fb8591ba745046f96770093330be7d12e45d2 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Tue, 30 Sep 2014 21:11:36 -0700
Subject: [PATCH] Fix a couple of issues in the code.

 * Use fdlibm_setexception to handle the case when the arg is NaN or
   Inf. (Previously depended on x+x doing the right thing.)
 * Fix a compiler warning about possible dangling else by adding
   braces as needed.
---
 src/lisp/s_scalbn.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/lisp/s_scalbn.c b/src/lisp/s_scalbn.c
index 4889385f9..1993bbb3f 100644
--- a/src/lisp/s_scalbn.c
+++ b/src/lisp/s_scalbn.c
@@ -52,15 +52,24 @@ tiny   = 1.0e-300;
 	    k = ((hx&0x7ff00000)>>20) - 54; 
             if (n< -50000) return fdlibm_setexception(x, FDLIBM_UNDERFLOW);; 	/*underflow*/
 	    }
-        if (k==0x7ff) return x+x;		/* NaN or Inf */
+        if (k==0x7ff) {
+            /* NaN or Inf */
+            if(((hx&0xfffff)|lx)!=0) {
+                return fdlibm_setexception(x, FDLIBM_INVALID);
+            } else {
+                return fdlibm_setexception(x, FDLIBM_OVERFLOW);
+            }
+        }
+        
         k = k+n; 
         if (k >  0x7fe) return fdlibm_setexception(x, FDLIBM_OVERFLOW); /* overflow  */
         if (k > 0) 				/* normal result */
 	    {ux.i[HIWORD] = (hx&0x800fffff)|(k<<20); return x;}
-        if (k <= -54)
+        if (k <= -54) {
             if (n > 50000) 	/* in case integer overflow in n+k */
               return fdlibm_setexception(x, FDLIBM_OVERFLOW);	/*overflow*/
             else return fdlibm_setexception(x, FDLIBM_UNDERFLOW); 	/*underflow*/
+        }
         k += 54;				/* subnormal result */
         ux.i[HIWORD] = (hx&0x800fffff)|(k<<20);
         return x*twom54;
-- 
GitLab