Test ordered and unordered comparisons with sNaN raise exceptions.
authorTaylor R Campbell <campbell@mumble.net>
Sat, 15 Dec 2018 03:48:26 +0000 (03:48 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Sat, 15 Dec 2018 22:33:22 +0000 (22:33 +0000)
tests/runtime/test-flonum.scm

index 87fbf0e1cfb6b39fb9ded0ef2fe049296051db88..e19151625526cc5f346b8f457cc2956747342663 100644 (file)
@@ -82,7 +82,7 @@ USA.
 (define assert-eqv-nan
   (simple-binary-assertion eqv-nan? #f))
 
-(define (assert-only-except/no-traps except procedure)
+(define (assert-only-except/no-traps except procedure #!optional mask)
   (assert-eqv
    (flo:preserving-environment
     (lambda ()
@@ -90,7 +90,10 @@ USA.
       (no-traps
        (lambda ()
          (procedure)
-         (flo:test-exceptions (flo:supported-exceptions))))))
+         (flo:test-exceptions
+          (if (default-object? mask)
+              (flo:supported-exceptions)
+              mask))))))
    except))
 
 (define (assert-no-except/yes-traps procedure)
@@ -642,6 +645,56 @@ USA.
                    cases))
             cases)))))
 
+(define-syntax define-snan-comparison-test
+  (syntax-rules ()
+    ((define-snan-comparison-test name safe-compare unsafe-compare cases)
+     (define-test name
+       (map (lambda (x)
+              (lambda ()
+                (with-test-properties
+                    (lambda ()
+                      (let ((snan (identity-procedure (flo:snan 1234)))
+                            (mask
+                             (fix:andc (flo:supported-exceptions)
+                                       ;; Not reliable.
+                                       (flo:exception:subnormal-operand))))
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (safe-compare x snan))
+                         mask)
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (safe-compare snan x))
+                         mask)
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (safe-compare snan snan)))
+                        (assert-false
+                         (no-traps (lambda () (safe-compare x snan))))
+                        (assert-false
+                         (no-traps (lambda () (safe-compare snan x))))
+                        (assert-false
+                         (no-traps (lambda () (safe-compare snan snan))))
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (unsafe-compare x snan))
+                         mask)
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (unsafe-compare snan x))
+                         mask)
+                        (assert-only-except/no-traps
+                         (flo:exception:invalid-operation)
+                         (lambda () (unsafe-compare snan snan)))
+                        (assert-false
+                         (no-traps (lambda () (unsafe-compare x snan))))
+                        (assert-false
+                         (no-traps (lambda () (unsafe-compare snan x))))
+                        (assert-false
+                         (no-traps (lambda () (unsafe-compare snan snan))))))
+                  'SEED x)))
+            cases)))))
+
 (let* ((subnormal+ flo:smallest-positive-subnormal)
        (subnormal- (no-traps (lambda () (- subnormal+))))
        (cases
@@ -652,6 +705,12 @@ USA.
   (define-comparison-test '<= flo:safe<= flo:<= cases)
   (define-comparison-test '<> flo:safe<> flo:<> cases)
   (define-comparison-test '= flo:safe= flo:= cases)
+  (define-snan-comparison-test '</snan flo:safe< flo:< cases)
+  (define-snan-comparison-test '>/snan flo:safe> flo:> cases)
+  (define-snan-comparison-test '>=/snan flo:safe>= flo:>= cases)
+  (define-snan-comparison-test '<=/snan flo:safe<= flo:<= cases)
+  (define-snan-comparison-test '<>/snan flo:safe<> flo:<> cases)
+  (define-snan-comparison-test '=/snan flo:safe= flo:= cases)
   (define-test 'unordered?
     (map (lambda (x)
            (map (lambda (y)