Change clamp to have a more realistic stack effect.

db4
John Benediktsson 2009-02-26 05:23:49 -08:00
parent b7ed0bc727
commit 01a1e8b6ee
3 changed files with 8 additions and 6 deletions

View File

@ -18,6 +18,6 @@ HELP: negmin
{ $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" } "." } ;

View File

@ -15,7 +15,7 @@ IN: math.compare.tests
[ -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

View File

@ -1,6 +1,8 @@
! 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 )
@ -15,5 +17,5 @@ IN: math.compare
: negmin ( a b -- x )
0 min min ;
: clamp ( a value b -- x )
min max ;
: clamp ( value a b -- x )
[ max ] [ min ] bi* ;