math: add neg? word

Do the right thing with integers or floats
db4
Joe Groff 2011-11-23 19:51:05 -08:00
parent 9123360547
commit 4e8a1d0bb4
3 changed files with 6 additions and 0 deletions

View File

@ -74,4 +74,6 @@ M: float prev-float
M: float fp-sign double>bits 63 bit? ; inline 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 M: float abs double>bits 63 2^ bitnot bitand bits>double ; inline

View File

@ -8,6 +8,8 @@ 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

@ -73,6 +73,8 @@ ERROR: log2-expects-positive x ;
: even? ( n -- ? ) 1 bitand zero? ; inline : even? ( n -- ? ) 1 bitand zero? ; inline
: odd? ( n -- ? ) 1 bitand 1 number= ; inline : odd? ( n -- ? ) 1 bitand 1 number= ; inline
GENERIC: neg? ( x -- -x )
: if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b ) : if-zero ( ..a n quot1: ( ..a -- ..b ) quot2: ( ..a n -- ..b ) -- ..b )
[ dup zero? ] [ [ drop ] prepose ] [ ] tri* if ; inline [ dup zero? ] [ [ drop ] prepose ] [ ] tri* if ; inline