| ... |
... |
@@ -90,12 +90,8 @@ |
|
90
|
90
|
|
|
91
|
91
|
(define-test %acosh.exceptions
|
|
92
|
92
|
(:tag :fdlibm)
|
|
93
|
|
- ;; Core-math returns infinity instead of signaling overflow.
|
|
94
|
|
- #-core-math
|
|
95
|
93
|
(assert-error 'floating-point-overflow
|
|
96
|
94
|
(kernel:%acosh ext:double-float-positive-infinity))
|
|
97
|
|
- ;; Core-math currently returns QNaN
|
|
98
|
|
- #-core-math
|
|
99
|
95
|
(assert-error 'floating-point-invalid-operation
|
|
100
|
96
|
(kernel:%acosh 0d0))
|
|
101
|
97
|
(ext:with-float-traps-masked (:overflow)
|
| ... |
... |
@@ -108,12 +104,8 @@ |
|
108
|
104
|
(:tag :fdlibm)
|
|
109
|
105
|
(assert-error 'floating-point-invalid-operation
|
|
110
|
106
|
(kernel:%asinh *snan*))
|
|
111
|
|
- ;; Core-math returns the signed infinity instead of signaling an
|
|
112
|
|
- ;; overflow.
|
|
113
|
|
- #-core-math
|
|
114
|
107
|
(assert-error 'floating-point-overflow
|
|
115
|
108
|
(kernel:%asinh ext:double-float-positive-infinity))
|
|
116
|
|
- #-core-math
|
|
117
|
109
|
(assert-error 'floating-point-overflow
|
|
118
|
110
|
(kernel:%asinh ext:double-float-negative-infinity))
|
|
119
|
111
|
(assert-true (ext:float-nan-p (kernel:%asinh *qnan*)))
|
| ... |
... |
@@ -218,7 +210,6 @@ |
|
218
|
210
|
(ext:with-float-traps-masked (:overflow)
|
|
219
|
211
|
(assert-equal ext:double-float-positive-infinity
|
|
220
|
212
|
(kernel:%exp 710d0)))
|
|
221
|
|
- #-core-math
|
|
222
|
213
|
(let ((modes (ext:get-floating-point-modes)))
|
|
223
|
214
|
(unwind-protect
|
|
224
|
215
|
(progn
|
| ... |
... |
@@ -675,6 +666,14 @@ |
|
675
|
666
|
|
|
676
|
667
|
(define-test %cos.exceptions
|
|
677
|
668
|
(:tag :fdlibm)
|
|
|
669
|
+ ;; cos(inf) signals invalid operation
|
|
|
670
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
671
|
+ (kernel:%cos ext:double-float-positive-infinity))
|
|
|
672
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
673
|
+ (kernel:%cos ext:double-float-negative-infinity))
|
|
|
674
|
+ ;; cos(nan) is NaN
|
|
|
675
|
+ (assert-true (ext:float-nan-p (kernel:%cos *qnan*)))
|
|
|
676
|
+
|
|
678
|
677
|
;; cos(x) = 1 for |x| < 2^-27. Signal inexact unless x = 0
|
|
679
|
678
|
(let ((x (scale-float 1d0 -28))
|
|
680
|
679
|
(x0 0d0))
|
| ... |
... |
@@ -690,6 +689,14 @@ |
|
690
|
689
|
|
|
691
|
690
|
(define-test %sin.exceptions
|
|
692
|
691
|
(:tag :fdlibm)
|
|
|
692
|
+ ;; sin(inf) signals invalid operation
|
|
|
693
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
694
|
+ (kernel:%sin ext:double-float-positive-infinity))
|
|
|
695
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
696
|
+ (kernel:%sin ext:double-float-negative-infinity))
|
|
|
697
|
+ ;; sin(nan) is NaN
|
|
|
698
|
+ (assert-true (ext:float-nan-p (kernel:%sin *qnan*)))
|
|
|
699
|
+
|
|
693
|
700
|
;; sin(x) = x for |x| < 2^-27. Signal inexact unless x = 0
|
|
694
|
701
|
(let ((x (scale-float 1d0 -28))
|
|
695
|
702
|
(x0 0d0))
|
| ... |
... |
@@ -705,6 +712,14 @@ |
|
705
|
712
|
|
|
706
|
713
|
(define-test %tan.exceptions
|
|
707
|
714
|
(:tag :fdlibm)
|
|
|
715
|
+ ;; tan(inf) signals invalid operation
|
|
|
716
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
717
|
+ (kernel:%tan ext:double-float-positive-infinity))
|
|
|
718
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
719
|
+ (kernel:%tan ext:double-float-negative-infinity))
|
|
|
720
|
+ ;; tan(nan) is NaN
|
|
|
721
|
+ (assert-true (ext:float-nan-p (kernel:%sin *qnan*)))
|
|
|
722
|
+
|
|
708
|
723
|
;; tan(x) = x for |x| < 2^-28. Signal inexact unless x = 0
|
|
709
|
724
|
(let ((x (scale-float 1d0 -29))
|
|
710
|
725
|
(x0 0d0))
|
| ... |
... |
@@ -717,3 +732,203 @@ |
|
717
|
732
|
;; though the result is exactly x.
|
|
718
|
733
|
(assert-error 'floating-point-inexact
|
|
719
|
734
|
(kernel:%tan x)))))
|
|
|
735
|
+
|
|
|
736
|
+;; Test cases from e_pow.c for fdlibm.
|
|
|
737
|
+(define-test %pow.case.1
|
|
|
738
|
+ (:tag :fdlibm)
|
|
|
739
|
+ ;; anything ^ 0 is 1
|
|
|
740
|
+ (assert-equal 1d0
|
|
|
741
|
+ (kernel:%pow ext:double-float-positive-infinity 0d0))
|
|
|
742
|
+ (assert-equal 1d0
|
|
|
743
|
+ (kernel:%pow ext:double-float-negative-infinity 0d0)))
|
|
|
744
|
+
|
|
|
745
|
+(define-test %pow.case.2
|
|
|
746
|
+ (:tag :fdlibm)
|
|
|
747
|
+ ;; anything ^ 1 is itself
|
|
|
748
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
749
|
+ (kernel:%pow ext:double-float-positive-infinity 1d0))
|
|
|
750
|
+ (assert-equal ext:double-float-negative-infinity
|
|
|
751
|
+ (kernel:%pow ext:double-float-negative-infinity 1d0)))
|
|
|
752
|
+
|
|
|
753
|
+(define-test %pow.case.3
|
|
|
754
|
+ (:tag :fdlibm)
|
|
|
755
|
+ ;; anything ^ NaN is NaN
|
|
|
756
|
+ (assert-true (ext:float-nan-p
|
|
|
757
|
+ (kernel:%pow pi *qnan*)))
|
|
|
758
|
+ (assert-true (ext:float-nan-p
|
|
|
759
|
+ (kernel:%pow ext:double-float-positive-infinity *qnan*))))
|
|
|
760
|
+
|
|
|
761
|
+(define-test %pow.case.4
|
|
|
762
|
+ (:tag :fdlibm)
|
|
|
763
|
+ ;; NaN ^ non-zero is NaN
|
|
|
764
|
+ (assert-true (ext:float-nan-p
|
|
|
765
|
+ (kernel:%pow *qnan* pi)))
|
|
|
766
|
+ (assert-true (ext:float-nan-p
|
|
|
767
|
+ (kernel:%pow *qnan* ext:double-float-positive-infinity))))
|
|
|
768
|
+
|
|
|
769
|
+(define-test %pow.case.5
|
|
|
770
|
+ (:tag :fdlibm)
|
|
|
771
|
+ ;; (|x| > 1) ^ +inf is +inf
|
|
|
772
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
773
|
+ (kernel:%pow pi ext:double-float-positive-infinity))
|
|
|
774
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
775
|
+ (kernel:%pow (- pi) ext:double-float-positive-infinity)))
|
|
|
776
|
+
|
|
|
777
|
+(define-test %pow.case.6
|
|
|
778
|
+ (:tag :fdlibm)
|
|
|
779
|
+ ;; (|x| > 1) ^ -inf is +0
|
|
|
780
|
+ (assert-equal +0d0
|
|
|
781
|
+ (kernel:%pow pi ext:double-float-negative-infinity))
|
|
|
782
|
+ (assert-equal +0d0
|
|
|
783
|
+ (kernel:%pow (- pi) ext:double-float-negative-infinity)))
|
|
|
784
|
+
|
|
|
785
|
+(define-test %pow.case.7
|
|
|
786
|
+ (:tag :fdlibm)
|
|
|
787
|
+ ;; (|x| < 1) ^ +inf is +0
|
|
|
788
|
+ (assert-equal +0d0
|
|
|
789
|
+ (kernel:%pow 0.5d0 ext:double-float-positive-infinity))
|
|
|
790
|
+ (assert-equal +0d0
|
|
|
791
|
+ (kernel:%pow -0.5d0 ext:double-float-positive-infinity)))
|
|
|
792
|
+
|
|
|
793
|
+(define-test %pow.case.8
|
|
|
794
|
+ (:tag :fdlibm)
|
|
|
795
|
+ ;; (|x| < 1) ^ -inf is +inf
|
|
|
796
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
797
|
+ (kernel:%pow 0.5d0 ext:double-float-negative-infinity))
|
|
|
798
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
799
|
+ (kernel:%pow -0.5d0 ext:double-float-negative-infinity)))
|
|
|
800
|
+
|
|
|
801
|
+(define-test %pow.case.9
|
|
|
802
|
+ (:tag :fdlibm)
|
|
|
803
|
+ ;; std::pow says 1^exp is 1 for any exp, including NaN. (-1)^(+/-inf)
|
|
|
804
|
+ ;; is 1. No errors signaled.
|
|
|
805
|
+ #+core-math
|
|
|
806
|
+ (progn
|
|
|
807
|
+ (assert-equal 1d0
|
|
|
808
|
+ (kernel:%pow 1d0 ext:double-float-positive-infinity))
|
|
|
809
|
+ (assert-equal 1d0
|
|
|
810
|
+ (kernel:%pow 1d0 ext:double-float-negative-infinity))
|
|
|
811
|
+ (assert-equal 1d0
|
|
|
812
|
+ (kernel:%pow 1d0 *qnan*))
|
|
|
813
|
+ (assert-equal 1d0
|
|
|
814
|
+ (kernel:%pow -1d0 ext:double-float-positive-infinity))
|
|
|
815
|
+ (assert-equal 1d0
|
|
|
816
|
+ (kernel:%pow -1d0 ext:double-float-negative-infinity)))
|
|
|
817
|
+ #-core-math
|
|
|
818
|
+ ;; +-1 ^ +-inf is NaN.
|
|
|
819
|
+ ;;
|
|
|
820
|
+ ;; But the implementation signals invalid operation, so we need to
|
|
|
821
|
+ ;; check for that.
|
|
|
822
|
+ ;;
|
|
|
823
|
+ (progn
|
|
|
824
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
825
|
+ (kernel:%pow 1d0 ext:double-float-positive-infinity))
|
|
|
826
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
827
|
+ (kernel:%pow 1d0 ext:double-float-negative-infinity))
|
|
|
828
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
829
|
+ (kernel:%pow -1d0 ext:double-float-positive-infinity))
|
|
|
830
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
831
|
+ (kernel:%pow -1d0 ext:double-float-negative-infinity))
|
|
|
832
|
+ (ext:with-float-traps-masked (:invalid)
|
|
|
833
|
+ (assert-true (ext:float-nan-p
|
|
|
834
|
+ (kernel:%pow 1d0 ext:double-float-positive-infinity)))
|
|
|
835
|
+ (assert-true (ext:float-nan-p
|
|
|
836
|
+ (kernel:%pow 1d0 ext:double-float-negative-infinity)))
|
|
|
837
|
+ (assert-true (ext:float-nan-p
|
|
|
838
|
+ (kernel:%pow -1d0 ext:double-float-positive-infinity)))
|
|
|
839
|
+ (assert-true (ext:float-nan-p
|
|
|
840
|
+ (kernel:%pow -1d0 ext:double-float-negative-infinity))))))
|
|
|
841
|
+
|
|
|
842
|
+(define-test %pow.case.10
|
|
|
843
|
+ (:tag :fdlibm)
|
|
|
844
|
+ ;; +0 ^ (+anything except 0, Nan) is +0
|
|
|
845
|
+ (assert-equal +0d0
|
|
|
846
|
+ (kernel:%pow +0d0 10d0))
|
|
|
847
|
+ (assert-equal +0d0
|
|
|
848
|
+ (kernel:%pow +0d0 ext:double-float-positive-infinity)))
|
|
|
849
|
+
|
|
|
850
|
+(define-test %pow.case.11
|
|
|
851
|
+ (:tag :fdlibm)
|
|
|
852
|
+ ;; +0 ^ (+anything except 0, Nan, odd integer) is +0
|
|
|
853
|
+ (assert-equal +0d0
|
|
|
854
|
+ (kernel:%pow -0d0 10d0))
|
|
|
855
|
+ (assert-equal +0d0
|
|
|
856
|
+ (kernel:%pow -0d0 ext:double-float-positive-infinity)))
|
|
|
857
|
+
|
|
|
858
|
+(define-test %pow.case.12
|
|
|
859
|
+ (:tag :fdlibm)
|
|
|
860
|
+ ;; +0 ^ (-anything except 0, Nan) is +inf
|
|
|
861
|
+ ;;
|
|
|
862
|
+ ;; But fdlibm signals error for (+0)^(-10) instead of returning inf. Check this.
|
|
|
863
|
+ (assert-error 'division-by-zero
|
|
|
864
|
+ (kernel:%pow +0d0 -10d0))
|
|
|
865
|
+ (ext:with-float-traps-masked (:divide-by-zero)
|
|
|
866
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
867
|
+ (kernel:%pow +0d0 -10d0)))
|
|
|
868
|
+ ;; No signals here.
|
|
|
869
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
870
|
+ (kernel:%pow +0d0 ext:double-float-negative-infinity)))
|
|
|
871
|
+
|
|
|
872
|
+(define-test %pow.case.13
|
|
|
873
|
+ (:tag :fdlibm)
|
|
|
874
|
+ ;; -0 ^ (-anything except 0, Nan, odd integer) is +inf
|
|
|
875
|
+ ;;
|
|
|
876
|
+ ;; But (-0)^(-10) signals division by zero
|
|
|
877
|
+ (assert-error 'division-by-zero
|
|
|
878
|
+ (kernel:%pow -0d0 -10d0))
|
|
|
879
|
+ (ext:with-float-traps-masked (:divide-by-zero)
|
|
|
880
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
881
|
+ (kernel:%pow -0d0 -10d0)))
|
|
|
882
|
+ ;; But no error here.
|
|
|
883
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
884
|
+ (kernel:%pow +0d0 ext:double-float-negative-infinity)))
|
|
|
885
|
+
|
|
|
886
|
+(define-test %pow.case.14
|
|
|
887
|
+ (:tag :fdlibm)
|
|
|
888
|
+ ;; -0 ^ (odd integer) = -( +0 ^ (odd integer))
|
|
|
889
|
+ (assert-equal (- (kernel:%pow +0d0 5d0))
|
|
|
890
|
+ (kernel:%pow -0d0 5d0)))
|
|
|
891
|
+
|
|
|
892
|
+(define-test %pow.case.15
|
|
|
893
|
+ (:tag :fdlibm)
|
|
|
894
|
+ ;; +inf ^ (+anything except 0, NaN) is +inf
|
|
|
895
|
+ (assert-equal ext:double-float-positive-infinity
|
|
|
896
|
+ (kernel:%pow ext:double-float-positive-infinity pi)))
|
|
|
897
|
+
|
|
|
898
|
+(define-test %pow.case.16
|
|
|
899
|
+ (:tag :fdlibm)
|
|
|
900
|
+ ;; +inf ^ (-anything except 0, NaN) is +0
|
|
|
901
|
+ (assert-equal +0d0
|
|
|
902
|
+ (kernel:%pow ext:double-float-positive-infinity (- pi))))
|
|
|
903
|
+
|
|
|
904
|
+(define-test %pow.case.17
|
|
|
905
|
+ (:tag :fdlibm)
|
|
|
906
|
+ ;; -inf ^ (anything) = -0 ^ (-anything)
|
|
|
907
|
+ (assert-equal (ext:with-float-traps-masked (:divide-by-zero)
|
|
|
908
|
+ ;; This produces a divide-by-zero error so mask it
|
|
|
909
|
+ ;; to get a value.
|
|
|
910
|
+ (kernel:%pow -0d0 (- pi)))
|
|
|
911
|
+ (kernel:%pow ext:double-float-negative-infinity pi))
|
|
|
912
|
+ (assert-equal (kernel:%pow -0d0 pi)
|
|
|
913
|
+ (kernel:%pow ext:double-float-negative-infinity (- pi))))
|
|
|
914
|
+
|
|
|
915
|
+(define-test %pow.case.18
|
|
|
916
|
+ (:tag :fdlibm)
|
|
|
917
|
+ ;; (-anything) ^ integer is (-1)^integer * (+anything ^ integer)
|
|
|
918
|
+ (dolist (base '(-2d0 -10d0))
|
|
|
919
|
+ (dolist (power '(5 -5))
|
|
|
920
|
+ (assert-equal (* (expt -1 power)
|
|
|
921
|
+ (kernel:%pow (- base) (coerce power 'double-float)))
|
|
|
922
|
+ (kernel:%pow base (coerce power 'double-float))
|
|
|
923
|
+ base power))))
|
|
|
924
|
+
|
|
|
925
|
+(define-test %pow.case.19
|
|
|
926
|
+ (:tag :fdlibm)
|
|
|
927
|
+ ;; (-anything except 0 and inf) ^ non-integer is NaN
|
|
|
928
|
+ ;;
|
|
|
929
|
+ ;; But this signals invalid, so check for that too.
|
|
|
930
|
+ (assert-error 'floating-point-invalid-operation
|
|
|
931
|
+ (kernel:%pow -2d0 1.5d0))
|
|
|
932
|
+ (ext:with-float-traps-masked (:invalid)
|
|
|
933
|
+ (assert-true (ext:float-nan-p
|
|
|
934
|
+ (kernel:%pow -2d0 1.5d0))))) |