From f1ce5ca191df18a9d7e060b57a6d38b308cc8083 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 29 Sep 2009 23:41:08 -0500 Subject: [PATCH] math.functions: ~ now raises an invalid operation FP trap if one of the inputs is NaN --- basis/math/floats/env/env-tests.factor | 1 + basis/math/functions/functions-tests.factor | 6 ++++++ basis/math/functions/functions.factor | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/basis/math/floats/env/env-tests.factor b/basis/math/floats/env/env-tests.factor index 7f5a20efd0..61552e8e82 100644 --- a/basis/math/floats/env/env-tests.factor +++ b/basis/math/floats/env/env-tests.factor @@ -29,6 +29,7 @@ set-default-fp-env [ t ] +fp-overflow+ [ 1.0e250 1.0e100 ] [ * ] test-fp-exception-compiled unit-test [ t ] +fp-underflow+ [ 1.0e-250 1.0e-100 ] [ * ] test-fp-exception-compiled unit-test [ t ] +fp-overflow+ [ 2.0 100,000.0 ] [ fpow ] test-fp-exception-compiled unit-test +[ t ] +fp-invalid-operation+ [ 2.0 0/0. 1.0e-9 ] [ ~ ] test-fp-exception-compiled unit-test ! No underflow on Linux with this test, just inexact. Reported as an Ubuntu bug: ! https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/429113 diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index 4502e993a3..1914bae008 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -44,8 +44,14 @@ IN: math.functions.tests [ 4.0 ] [ 10000.0 log10 ] unit-test [ t ] [ 1 exp e 1.e-10 ~ ] unit-test +[ f ] [ 1 exp 0/0. 1.e-10 ~ ] unit-test +[ f ] [ 0/0. 1 exp 1.e-10 ~ ] unit-test [ t ] [ 1.0 exp e 1.e-10 ~ ] unit-test [ t ] [ -1 exp e * 1.0 1.e-10 ~ ] unit-test +[ f ] [ 1/0. 1/0. 1.e-10 ~ ] unit-test +[ f ] [ 1/0. -1/0. 1.e-10 ~ ] unit-test +[ f ] [ 1/0. 0/0. 1.e-10 ~ ] unit-test +[ f ] [ 0/0. -1/0. 1.e-10 ~ ] unit-test [ 1.0 ] [ 0 cosh ] unit-test [ 1.0 ] [ 0.0 cosh ] unit-test diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index a31b6ee7cc..a9ad003411 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -141,7 +141,6 @@ M: real absq sq ; inline : ~ ( x y epsilon -- ? ) { - { [ 2over [ fp-nan? ] either? ] [ 3drop f ] } { [ dup zero? ] [ drop number= ] } { [ dup 0 < ] [ neg ~rel ] } [ ~abs ]