From c3f4282efea6950979a2393dfd590045c7921b78 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sat, 26 Nov 2011 15:37:58 -0800 Subject: [PATCH] math: neg? needs to be defined for all reals --- core/math/integers/integers.factor | 2 -- core/math/math-tests.factor | 11 +++++++++++ core/math/math.factor | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/math/integers/integers.factor b/core/math/integers/integers.factor index 0457165fac..3cab1dd4e8 100644 --- a/core/math/integers/integers.factor +++ b/core/math/integers/integers.factor @@ -8,8 +8,6 @@ IN: math.integers.private : fixnum-min ( 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 denominator drop 1 ; inline diff --git a/core/math/math-tests.factor b/core/math/math-tests.factor index 8ed5495106..8cbc951a36 100644 --- a/core/math/math-tests.factor +++ b/core/math/math-tests.factor @@ -67,4 +67,15 @@ IN: math.tests [ 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 diff --git a/core/math/math.factor b/core/math/math.factor index 94a0db98c3..150f508cdb 100644 --- a/core/math/math.factor +++ b/core/math/math.factor @@ -88,6 +88,8 @@ TUPLE: ratio { numerator integer read-only } { denominator integer read-only } ; UNION: rational integer ratio ; +M: rational neg? 0 < ; inline + UNION: real rational float ; TUPLE: complex { real real read-only } { imaginary real read-only } ;