Change clamp to have a more realistic stack effect.
parent
b7ed0bc727
commit
01a1e8b6ee
|
@ -18,6 +18,6 @@ HELP: negmin
|
||||||
{ $description "Returns the most-negative value, or zero if both are positive." } ;
|
{ $description "Returns the most-negative value, or zero if both are positive." } ;
|
||||||
|
|
||||||
HELP: clamp
|
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" } "." } ;
|
{ $description "Returns the value when between " { $snippet "a" } " and " { $snippet "b" } ", " { $snippet "a" } " if <= " { $snippet "a" } ", or " { $snippet "b" } " if >= " { $snippet "b" } "." } ;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ IN: math.compare.tests
|
||||||
[ -3 ] [ 1 -3 negmin ] unit-test
|
[ -3 ] [ 1 -3 negmin ] unit-test
|
||||||
[ -1 ] [ -1 3 negmin ] unit-test
|
[ -1 ] [ -1 3 negmin ] unit-test
|
||||||
|
|
||||||
[ 0 ] [ 0 -1 2 clamp ] unit-test
|
[ 0 ] [ -1 0 2 clamp ] unit-test
|
||||||
[ 1 ] [ 0 1 2 clamp ] unit-test
|
[ 1 ] [ 1 0 2 clamp ] unit-test
|
||||||
[ 2 ] [ 0 3 2 clamp ] unit-test
|
[ 2 ] [ 3 0 2 clamp ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
! Copyright (C) 2008 John Benediktsson.
|
! Copyright (C) 2008 John Benediktsson.
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
USING: math math.order kernel ;
|
USING: math math.order kernel ;
|
||||||
|
|
||||||
IN: math.compare
|
IN: math.compare
|
||||||
|
|
||||||
: absmin ( a b -- x )
|
: absmin ( a b -- x )
|
||||||
|
@ -15,5 +17,5 @@ IN: math.compare
|
||||||
: negmin ( a b -- x )
|
: negmin ( a b -- x )
|
||||||
0 min min ;
|
0 min min ;
|
||||||
|
|
||||||
: clamp ( a value b -- x )
|
: clamp ( value a b -- x )
|
||||||
min max ;
|
[ max ] [ min ] bi* ;
|
||||||
|
|
Loading…
Reference in New Issue