| ... |
... |
@@ -732,3 +732,203 @@ |
|
732
|
732
|
;; though the result is exactly x.
|
|
733
|
733
|
(assert-error 'floating-point-inexact
|
|
734
|
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))))) |