[ t ] [ "[####monkey]" "monkey" "[%'#10s]" sprintf = ] unit-test
[ t ] [ "[many monke]" "many monkeys" "[%10.10s]" sprintf = ] unit-test
+[ t ] [ "{ 1, 2, 3 }" { 1 2 3 } "%[%s, %]" sprintf = ] unit-test
+[ t ] [ "{ 1:2, 3:4 }" H{ { 1 2 } { 3 4 } } "%[%s: %s %]" sprintf = ] unit-test
+
[ "%H:%M:%S" strftime ] must-infer
[ t ] [ "Thu Oct 09 12:03:15 2008" testtime "%c" strftime = ] unit-test
[ t ] [ "PM" testtime "%p" strftime = ] unit-test
+
{ $description "Returns the most-negative value, or zero if both are positive." } ;
HELP: clamp
-{ $values { "a" number } { "value" number } { "b" number } { "x" number } }
+{ $values { "value" number } { "a" number } { "b" number } { "x" number } }
{ $description "Returns the value when between " { $snippet "a" } " and " { $snippet "b" } ", " { $snippet "a" } " if <= " { $snippet "a" } ", or " { $snippet "b" } " if >= " { $snippet "b" } "." } ;
[ -3 ] [ 1 -3 negmin ] unit-test
[ -1 ] [ -1 3 negmin ] unit-test
-[ 0 ] [ 0 -1 2 clamp ] unit-test
-[ 1 ] [ 0 1 2 clamp ] unit-test
-[ 2 ] [ 0 3 2 clamp ] unit-test
+[ 0 ] [ -1 0 2 clamp ] unit-test
+[ 1 ] [ 1 0 2 clamp ] unit-test
+[ 2 ] [ 3 0 2 clamp ] unit-test
! Copyright (C) 2008 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license
+
USING: math math.order kernel ;
+
IN: math.compare
: absmin ( a b -- x )
: negmin ( a b -- x )
0 min min ;
-: clamp ( a value b -- x )
- min max ;
+: clamp ( value a b -- x )
+ [ max ] [ min ] bi* ;