math: neg? needs to be defined for all reals

db4
Joe Groff 2011-11-26 15:37:58 -08:00
parent a97a9ede15
commit 90f34d092c
3 changed files with 13 additions and 2 deletions

View File

@ -8,8 +8,6 @@ IN: math.integers.private
: fixnum-min ( x y -- z ) [ fixnum< ] most ; foldable : fixnum-min ( x y -- z ) [ fixnum< ] most ; foldable
: fixnum-max ( x y -- z ) [ fixnum> ] most ; foldable : fixnum-max ( x y -- z ) [ fixnum> ] most ; foldable
M: integer neg? 0 < ; inline
M: integer numerator ; inline M: integer numerator ; inline
M: integer denominator drop 1 ; inline M: integer denominator drop 1 ; inline

View File

@ -67,4 +67,15 @@ IN: math.tests
[ f ] [ -1/0. 0/0. >= ] unit-test [ f ] [ -1/0. 0/0. >= ] unit-test
[ f ] [ 1/0. 0/0. >= ] unit-test [ f ] [ 1/0. 0/0. >= ] unit-test
[ f ] [ 0 neg? ] unit-test
[ f ] [ 1/2 neg? ] unit-test
[ f ] [ 1 neg? ] unit-test
[ t ] [ -1/2 neg? ] unit-test
[ t ] [ -1 neg? ] unit-test
[ f ] [ 0.0 neg? ] unit-test
[ f ] [ 1.0 neg? ] unit-test
[ f ] [ 1/0. neg? ] unit-test
[ t ] [ -0.0 neg? ] unit-test
[ t ] [ -1.0 neg? ] unit-test
[ t ] [ -1/0. neg? ] unit-test

View File

@ -88,6 +88,8 @@ TUPLE: ratio { numerator integer read-only } { denominator integer read-only } ;
UNION: rational integer ratio ; UNION: rational integer ratio ;
M: rational neg? 0 < ; inline
UNION: real rational float ; UNION: real rational float ;
TUPLE: complex { real real read-only } { imaginary real read-only } ; TUPLE: complex { real real read-only } { imaginary real read-only } ;