]> gitweb.factorcode.org Git - factor.git/commitdiff
math: add neg? word
authorJoe Groff <arcata@gmail.com>
Thu, 24 Nov 2011 03:51:05 +0000 (19:51 -0800)
committerJoe Groff <arcata@gmail.com>
Thu, 24 Nov 2011 03:51:05 +0000 (19:51 -0800)
Do the right thing with integers or floats

core/math/floats/floats.factor
core/math/integers/integers.factor
core/math/math.factor

index b441276a886631046fcb2952f45fdace1a8a5d99..47ecdab1258e50ed6dd47c107f821dc94a635457 100644 (file)
@@ -74,4 +74,6 @@ M: float prev-float
 
 M: float fp-sign double>bits 63 bit? ; inline
 
+M: float neg? fp-sign ; inline
+
 M: float abs double>bits 63 2^ bitnot bitand bits>double ; inline
index 3cab1dd4e83c06adb12d466555e3eb4def6c1bdd..0457165fac9ab067240fb58140368523d940e900 100644 (file)
@@ -8,6 +8,8 @@ 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
 
index 81e488cb19b3fb5c23739b7ccc3411601d79dff0..94a0db98c3fc28b56c1ad1ad4072ac061b41cc54 100644 (file)
@@ -73,6 +73,8 @@ ERROR: log2-expects-positive x ;
 : even? ( n -- ? ) 1 bitand zero? ; inline
 : odd? ( n -- ? ) 1 bitand 1 number= ; inline
 
+GENERIC: neg? ( x -- -x )
+
 : if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )
     [ dup zero? ] [ [ drop ] prepose ] [ ] tri* if ; inline