math.factorials: adding "factorials" word.

db4
John Benediktsson 2013-10-20 17:08:01 -07:00
parent edc3351ca8
commit 43905f3f3d
2 changed files with 7 additions and 0 deletions

View File

@ -6,6 +6,10 @@ IN: math.factorials
[ 1 ] [ 1 factorial ] unit-test [ 1 ] [ 1 factorial ] unit-test
[ 3628800 ] [ 10 factorial ] unit-test [ 3628800 ] [ 10 factorial ] unit-test
{ { 1 1 2 6 24 120 720 5040 40320 362880 3628800 } } [
10 factorials
] unit-test
{ {
{ {
1/0. 1/105 1/0. -1/15 1/0. 1/3 1/0. -1 1/0. 1/0. 1/105 1/0. -1/15 1/0. 1/3 1/0. -1 1/0.

View File

@ -11,6 +11,9 @@ MEMO: factorial ( n -- n! )
ALIAS: n! factorial ALIAS: n! factorial
: factorials ( n -- seq )
1 swap [0,b] [ dup 1 > [ * ] [ drop ] if dup ] map nip ;
MEMO: double-factorial ( n -- n!! ) MEMO: double-factorial ( n -- n!! )
dup [ even? ] [ 0 < ] bi [ dup [ even? ] [ 0 < ] bi [
[ drop 1/0. ] [ [ drop 1/0. ] [