From: Taylor R Campbell Date: Thu, 3 Oct 2019 14:49:34 +0000 (+0000) Subject: Fix floating-point min/max tests, and mark them xfail. X-Git-Tag: mit-scheme-pucked-10.1.20~11^2~40 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=3551710b4964a2908956ebd32daceedbc1aaadbf;p=mit-scheme.git Fix floating-point min/max tests, and mark them xfail. I misread IEEE 754 semantics on min/max for _signalling_ NaN. If given a number and a _quiet_ NaN, min/max are to return the _number_. But if given a _signalling_ NaN, min/max are to return a quiet version of the NaN. References: Sec. 5.3 `Homogeneous general-computational operations', subsec. 5.3.1 `General operations', on minNum/maxNum/minNumMag/maxNumMag reads: `minNum(x, y) is...the canonicalized number if one operand is a number and the other is a quiet NaN.' `When either x or y is a signaling NaN, then the result is according to 6.2.' Sec. 6.2 `Operations with NaNs' reads: `Under default exception handling, any operation signaling an invalid operation exception and for which a floating-point result is to be delivered shall deliver a quiet NaN.' [Consequently, _if_ min/max raise invalid-operation and nevertheless return a result, they shall return a quiet NaN.] `Signaling NaNs shall be reserved operands that, under default exception handling, signal the invalid operation exception (see 7.2) for every general-computational and signaling-computational operation except for the conversions described in 5.12.' [min/max (i.e., minNum/maxNum/minNumMag/maxNumMag) are listed under homogeneous general-computational, so this clause applies.] Subsec. 6.2.3 `NaN propagation' further reads: `An operation that propagates a NaN operand to its result and has a single NaN as an input should produce a NaN with the payload of the input NaN.' `If two or more inputs are NaN, then the payload of the resulting NaN should be identical to the payload of one of the input NaNs if representable in the destination format.' --- diff --git a/tests/runtime/test-flonum.scm b/tests/runtime/test-flonum.scm index 91b43ca21..92a49a86c 100644 --- a/tests/runtime/test-flonum.scm +++ b/tests/runtime/test-flonum.scm @@ -1042,42 +1042,78 @@ USA. (assert-eqv-nan (yes-traps (lambda () (flo:max-mag x y))) max-mag))) (define-enumerated-test 'min-snan-left inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:min (flo:snan) x))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:min (flo:snan 123) x))) + (flo:qnan 123)))))) (define-enumerated-test 'max-snan-left inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:max (flo:snan) x))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:max (flo:snan 123) x))) + (flo:qnan 123)))))) (define-enumerated-test 'min-snan-right inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:min x (flo:snan)))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:min x (flo:snan 123)))) + (flo:qnan 123)))))) (define-enumerated-test 'max-snan-right inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:max x (flo:snan)))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:max x (flo:snan 123)))) + (flo:qnan 123)))))) (define-test 'min-snan-both (lambda () - (assert-nan (no-traps (lambda () (flo:min (flo:snan) (flo:snan))))))) + (expect-failure + (lambda () + (assert-qnan + (no-traps (lambda () (flo:min (flo:snan 123) (flo:snan 456))))))))) (define-test 'max-snan-both (lambda () - (assert-nan (no-traps (lambda () (flo:max (flo:snan) (flo:snan))))))) + (expect-failure + (lambda () + (assert-qnan + (no-traps (lambda () (flo:max (flo:snan 123) (flo:snan 456))))))))) (define-enumerated-test 'min-mag-snan-left inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:min-mag (flo:snan) x))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:min-mag (flo:snan 123) x))) + (flo:qnan 123)))))) (define-enumerated-test 'max-mag-snan-left inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:max-mag (flo:snan) x))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:max-mag (flo:snan 123) x))) + (flo:qnan 123)))))) (define-enumerated-test 'min-mag-snan-right inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:min-mag x (flo:snan)))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:min-mag x (flo:snan 123)))) + (flo:qnan 123)))))) (define-enumerated-test 'max-mag-snan-right inputs (lambda (x) - (assert-eqv (no-traps (lambda () (flo:max-mag x (flo:snan)))) x))) + (expect-failure + (lambda () + (assert-eqv-nan (no-traps (lambda () (flo:max-mag x (flo:snan 123)))) + (flo:qnan 123)))))) (define-test 'min-mag-snan-both (lambda () - (assert-nan - (no-traps (lambda () (flo:min-mag (flo:snan) (flo:snan))))))) + (expect-failure + (lambda () + (assert-qnan + (no-traps + (lambda () (flo:min-mag (flo:snan 123) (flo:snan 456))))))))) (define-test 'max-mag-snan-both (lambda () - (assert-nan - (no-traps (lambda () (flo:max-mag (flo:snan) (flo:snan)))))))) + (expect-failure + (lambda () + (assert-qnan + (no-traps + (lambda () (flo:max-mag (flo:snan 123) (flo:snan 456)))))))))) (define-enumerated-test 'abs `((-inf.0)