From efe79cf6d331bc0ddc3fa588d6e262e1907285a0 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 1 Aug 2011 10:26:53 -0700 Subject: [PATCH] math.functions: make sure zero zero ^ is always nan, regardless of the type of zero --- basis/math/functions/functions-tests.factor | 1 + basis/math/functions/functions.factor | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index 73f08e2665..507258f0d1 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -32,6 +32,7 @@ IN: math.functions.tests [ 0.0 ] [ 0.0 1.0 ^ ] unit-test [ 1/0. ] [ 0 -2 ^ ] unit-test [ t ] [ 0 0.0 ^ fp-nan? ] unit-test +[ t ] [ 0.0 0.0 ^ fp-nan? ] unit-test [ 1/0. ] [ 0 -2.0 ^ ] unit-test [ 0 ] [ 0 3.0 ^ ] unit-test [ 0 ] [ 0 3 ^ ] unit-test diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 0a9b73fe0c..1b120831c0 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -82,8 +82,8 @@ M: complex exp >rect [ exp ] dip polar> ; inline : real^? ( x y -- ? ) 2dup [ real? ] both? [ drop 0 >= ] [ 2drop f ] if ; inline -: 0^ ( x -- z ) - [ 0/0. ] [ 0 < 1/0. 0 ? ] if-zero ; inline +: 0^ ( zero x -- z ) + swap [ 0/0. ] swap '[ 0 < 1/0. _ ? ] if-zero ; inline : (^mod) ( x y n -- z ) [ make-bits 1 ] dip dup @@ -100,7 +100,7 @@ PRIVATE> : ^ ( x y -- z ) { - { [ over 0 = ] [ nip 0^ ] } + { [ over zero? ] [ 0^ ] } { [ dup integer? ] [ integer^ ] } { [ 2dup real^? ] [ [ >float ] bi@ fpow ] } [ ^complex ]