From e2409a14dbdfb95e33cbed21964d365ffc6af1a4 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 4 Oct 2005 01:04:07 +0000 Subject: [PATCH] fix incorrect quadrants code --- library/math/complex.factor | 3 +++ library/test/math/complex.factor | 5 +++++ library/tools/describe.factor | 5 +---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/math/complex.factor b/library/math/complex.factor index 8c68fa0364..c6d46dbe07 100644 --- a/library/math/complex.factor +++ b/library/math/complex.factor @@ -41,6 +41,9 @@ M: number = ( n n -- ? ) number= ; : polar> ( abs arg -- z ) cis * ; inline +: quadrant ( z -- n ) + >rect >r 0 >= 0 1 ? r> 0 >= 0 3 ? bitxor ; + M: complex absq >rect [ sq ] 2apply + ; IN: math-internals diff --git a/library/test/math/complex.factor b/library/test/math/complex.factor index 92706174fd..4cd82b00ba 100644 --- a/library/test/math/complex.factor +++ b/library/test/math/complex.factor @@ -59,3 +59,8 @@ USE: test [ 1 0 ] [ 1 >polar ] unit-test [ 1 ] [ -1 >polar drop ] unit-test [ t ] [ -1 >polar nip 3.14 3.15 between? ] unit-test + +[ 0 ] [ #{ 1 1 }# quadrant ] unit-test +[ 1 ] [ #{ -1 1 }# quadrant ] unit-test +[ 2 ] [ #{ -1 -1 }# quadrant ] unit-test +[ 3 ] [ #{ 1 -1 }# quadrant ] unit-test diff --git a/library/tools/describe.factor b/library/tools/describe.factor index 4dfa276545..e7d191f6da 100644 --- a/library/tools/describe.factor +++ b/library/tools/describe.factor @@ -16,12 +16,9 @@ M: integer summary M: real summary dup sign-string swap class word-name append ; -: quadrant ( z -- n ) - >rect >r 0 >= 2 0 ? r> 0 >= 1 0 ? + ; - M: complex summary "a complex number in the " - swap quadrant { "first" "second" "third" "fourth" } nth + swap quadrant { "first" "second" "fourth" "third" } nth " quadrant" append3 ; GENERIC: sheet ( obj -- sheet )