factor/extra/math/compare/compare.factor

25 lines
527 B
Factor
Raw Normal View History

2008-11-07 01:24:32 -05:00
! Copyright (C) 2008 John Benediktsson.
2008-09-23 17:50:28 -04:00
! See http://factorcode.org/license.txt for BSD license
2008-09-23 17:36:21 -04:00
USING: math math.order kernel ;
2008-11-07 01:24:32 -05:00
IN: math.compare
2008-09-23 17:36:21 -04:00
2008-11-07 01:24:32 -05:00
: absmin ( a b -- x )
2011-10-15 22:19:44 -04:00
[ [ abs ] bi@ < ] most ;
2008-09-23 17:36:21 -04:00
2008-11-07 01:24:32 -05:00
: absmax ( a b -- x )
2011-10-15 22:19:44 -04:00
[ [ abs ] bi@ > ] most ;
2008-09-23 17:36:21 -04:00
2008-11-07 01:24:32 -05:00
: posmax ( a b -- x )
0 max max ;
2008-09-23 17:36:21 -04:00
2008-11-07 01:24:32 -05:00
: negmin ( a b -- x )
0 min min ;
: max-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
[ bi@ dupd max = ] curry most ; inline
: min-by ( obj1 obj2 quot: ( obj -- n ) -- obj1/obj2 )
[ bi@ dupd min = ] curry most ; inline