diff --git a/src/lisp/s_asinh.c b/src/lisp/s_asinh.c index 6cae81ff299c4763a5d5511e017e36e9bd605338..dc99e5b943a4fac47e2d44596481eb7e0da05522 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 b4163b7bab29f9af4b5fb6f6f5c506a2572ae4ad..d95db71c929ef01367c6e0d3ef5f060274d41a78 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