]> gitweb.factorcode.org Git - factor.git/commitdiff
math.functions: make sure zero zero ^ is always nan, regardless of the type of zero
authorJoe Groff <arcata@gmail.com>
Mon, 1 Aug 2011 17:26:53 +0000 (10:26 -0700)
committerJoe Groff <arcata@gmail.com>
Mon, 1 Aug 2011 17:26:53 +0000 (10:26 -0700)
basis/math/functions/functions-tests.factor
basis/math/functions/functions.factor

index 73f08e2665ae559253b50535a5373fb62431e06d..507258f0d1bd730bf91f5332b08d208c5a4a243f 100644 (file)
@@ -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
index 0a9b73fe0c72c419ce4a72e57aac4079bb57b0ae..1b120831c0355d3ff2138c68215b629b77ded4df 100644 (file)
@@ -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 ]