fix incorrect quadrants code

cvs
Slava Pestov 2005-10-04 01:04:07 +00:00
parent 764cf6d314
commit e2409a14db
3 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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 )