factor/library/test/benchmark/fib.factor

23 lines
449 B
Factor
Raw Normal View History

2004-08-23 23:27:55 -04:00
IN: scratchpad
2004-10-27 21:21:31 -04:00
USE: compiler
USE: kernel
2004-08-23 23:27:55 -04:00
USE: math
USE: test
USE: math-internals
: fixnum-fib ( n -- nth fibonacci number )
dup 1 fixnum<= [
drop 1
] [
1 fixnum- dup fixnum-fib swap 1 fixnum- fixnum-fib fixnum+
] ifte ;
compiled
[ 9227465 ] [ 34 fixnum-fib ] unit-test
2004-10-27 21:21:31 -04:00
: fib ( n -- nth fibonacci number )
dup 1 <= [ drop 1 ] [ 1 - dup fib swap 1 - fib + ] ifte ;
2004-12-05 23:00:52 -05:00
compiled
2004-08-23 23:27:55 -04:00
[ 9227465 ] [ 34 fib ] unit-test