Raymond Toy pushed to branch issue-468-core-math-signals at cmucl / cmucl

Commits:

2 changed files:

Changes:

  • src/lisp/irrat.c
    ... ... @@ -43,6 +43,11 @@ double
    43 43
     lisp_sin(double x)
    
    44 44
     {
    
    45 45
     #ifdef FEATURE_CORE_MATH
    
    46
    +    /* Signals invalid if x is infinite */
    
    47
    +    if (isinf(x)) {
    
    48
    +	return fdlibm_setexception(x, FDLIBM_INVALID);
    
    49
    +    }
    
    50
    +
    
    46 51
         return cr_sin(x);
    
    47 52
     #else    
    
    48 53
         return fdlibm_sin(x);
    
    ... ... @@ -53,6 +58,11 @@ double
    53 58
     lisp_cos(double x)
    
    54 59
     {
    
    55 60
     #ifdef FEATURE_CORE_MATH
    
    61
    +    /* Signals invalid if x is infinite */
    
    62
    +    if (isinf(x)) {
    
    63
    +	return fdlibm_setexception(x, FDLIBM_INVALID);
    
    64
    +    }
    
    65
    +
    
    56 66
         return cr_cos(x);
    
    57 67
     #else    
    
    58 68
         return fdlibm_cos(x);
    
    ... ... @@ -63,6 +73,11 @@ double
    63 73
     lisp_tan(double x)
    
    64 74
     {
    
    65 75
     #ifdef FEATURE_CORE_MATH
    
    76
    +    /* Signals invalid if x is infinite */
    
    77
    +    if (isinf(x)) {
    
    78
    +	return fdlibm_setexception(x, FDLIBM_INVALID);
    
    79
    +    }
    
    80
    +
    
    66 81
         return cr_tan(x);
    
    67 82
     #else    
    
    68 83
         return fdlibm_tan(x);
    

  • tests/fdlibm.lisp
    ... ... @@ -214,7 +214,6 @@
    214 214
       (ext:with-float-traps-masked (:overflow)
    
    215 215
         (assert-equal ext:double-float-positive-infinity
    
    216 216
     		  (kernel:%exp 710d0)))
    
    217
    -  #-core-math
    
    218 217
       (let ((modes (ext:get-floating-point-modes)))
    
    219 218
         (unwind-protect
    
    220 219
     	 (progn
    
    ... ... @@ -671,6 +670,14 @@
    671 670
     
    
    672 671
     (define-test %cos.exceptions
    
    673 672
         (:tag :fdlibm)
    
    673
    +  ;; cos(inf) signals invalid operation
    
    674
    +  (assert-error 'floating-point-invalid-operation
    
    675
    +		(kernel:%cos ext:double-float-positive-infinity))
    
    676
    +  (assert-error 'floating-point-invalid-operation
    
    677
    +		(kernel:%cos ext:double-float-negative-infinity))
    
    678
    +  ;; cos(nan) is NaN
    
    679
    +  (assert-true (ext:float-nan-p (kernel:%cos *qnan*)))
    
    680
    +  
    
    674 681
       ;; cos(x) = 1 for |x| < 2^-27.  Signal inexact unless x = 0
    
    675 682
       (let ((x (scale-float 1d0 -28))
    
    676 683
     	(x0 0d0))
    
    ... ... @@ -686,6 +693,14 @@
    686 693
     
    
    687 694
     (define-test %sin.exceptions
    
    688 695
         (:tag :fdlibm)
    
    696
    +  ;; sin(inf) signals invalid operation
    
    697
    +  (assert-error 'floating-point-invalid-operation
    
    698
    +		(kernel:%sin ext:double-float-positive-infinity))
    
    699
    +  (assert-error 'floating-point-invalid-operation
    
    700
    +		(kernel:%sin ext:double-float-negative-infinity))
    
    701
    +  ;; sin(nan) is NaN
    
    702
    +  (assert-true (ext:float-nan-p (kernel:%sin *qnan*)))
    
    703
    +
    
    689 704
       ;; sin(x) = x for |x| < 2^-27.  Signal inexact unless x = 0
    
    690 705
       (let ((x (scale-float 1d0 -28))
    
    691 706
     	(x0 0d0))
    
    ... ... @@ -701,6 +716,14 @@
    701 716
     
    
    702 717
     (define-test %tan.exceptions
    
    703 718
         (:tag :fdlibm)
    
    719
    +  ;; tan(inf) signals invalid operation
    
    720
    +  (assert-error 'floating-point-invalid-operation
    
    721
    +		(kernel:%tan ext:double-float-positive-infinity))
    
    722
    +  (assert-error 'floating-point-invalid-operation
    
    723
    +		(kernel:%tan ext:double-float-negative-infinity))
    
    724
    +  ;; tan(nan) is NaN
    
    725
    +  (assert-true (ext:float-nan-p (kernel:%sin *qnan*)))
    
    726
    +
    
    704 727
       ;; tan(x) = x for |x| < 2^-28.  Signal inexact unless x = 0
    
    705 728
       (let ((x (scale-float 1d0 -29))
    
    706 729
     	(x0 0d0))