From bd30c83c9503bf6b5cb3f569e9b842e72772ae9b Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Fri, 22 Aug 2014 20:44:31 -0700
Subject: [PATCH] Make asinh signal errors using fdlibm_setexception.

 * src/lisp/s_asinh.c
   * Use fdlibm_setexception
 * tests/trig.lisp:
   * Add tests for asinh
---
 src/lisp/s_asinh.c | 12 +++++++++++-
 tests/trig.lisp    | 19 ++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/lisp/s_asinh.c b/src/lisp/s_asinh.c
index 6cae81ff2..dc99e5b94 100644
--- a/src/lisp/s_asinh.c
+++ b/src/lisp/s_asinh.c
@@ -22,6 +22,8 @@
  *		 := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))  
  */
 
+#include <math.h>
+
 #include "fdlibm.h"
 
 #ifdef __STDC__
@@ -47,7 +49,15 @@ huge=  1.00000000000000000000e+300;
         ux.d = x;
 	hx = ux.i[HIWORD];
 	ix = hx&0x7fffffff;
-	if(ix>=0x7ff00000) return x+x;	/* x is inf or NaN */
+	if(ix>=0x7ff00000) {
+            /* x is inf or NaN */
+            if (isnan(x)) {
+                return fdlibm_setexception(x, FDLIBM_INVALID);
+            } else {
+                return fdlibm_setexception(x, FDLIBM_OVERFLOW);
+            }
+        }
+        
 	if(ix< 0x3e300000) {	/* |x|<2**-28 */
 	    if(huge+x>one) return x;	/* return x inexact except 0 */
 	} 
diff --git a/tests/trig.lisp b/tests/trig.lisp
index b4163b7ba..d95db71c9 100644
--- a/tests/trig.lisp
+++ b/tests/trig.lisp
@@ -870,7 +870,24 @@
 		  (kernel:%acosh ext:double-float-positive-infinity)))
   (kernel::with-float-traps-masked (:invalid)
     (assert-true (ext:float-nan-p (kernel:%acosh 0d0)))))
-  
+
+(define-test asinh.exceptions
+  (:tag :fdlibm)
+  (assert-error 'floating-point-invalid-operation
+		(kernel:%asinh *snan*))
+  (assert-error 'floating-point-overflow
+		(kernel:%asinh ext:double-float-positive-infinity))
+  (assert-error 'floating-point-overflow
+		(kernel:%asinh ext:double-float-negative-infinity))
+  (assert-true (ext:float-nan-p (kernel:%asinh *qnan*)))
+  (kernel::with-float-traps-masked (:overflow)
+    (assert-equal ext:double-float-positive-infinity
+		  (kernel:%asinh ext:double-float-positive-infinity))
+    (assert-error ext:double-float-negative-infinity
+		  (kernel:%asinh ext:double-float-negative-infinity)))
+  (kernel::with-float-traps-masked (:invalid)
+    (assert-true (ext:float-nan-p (kernel:%asinh *snan*)))))
+
 (define-test expm1.exceptions
   (:tag :fdlibm)
   (assert-error 'floating-point-overflow
-- 
GitLab