(count-digits) ( digits n -- digits' )


Vocabulary
math.parser.private

Inputs and outputs
digitsan object
nan object
digits'an object


Definition


: (count-digits) ( digits n -- digits' )
{
{ [ dup 10 < ] [ drop ] }
{ [ dup 100 < ] [ drop 1 fixnum+fast ] }
{ [ dup 1000 < ] [ drop 2 fixnum+fast ] }
[
dup 1000000000000 < [
dup 100000000 < [
dup 1000000 <
[ dup 10000 < ~quotation~ ~quotation~ if ]
[ 10000000 >= 7 6 ? ] if
] [
dup 10000000000 <
[ 1000000000 >= 9 8 ? ]
[ 100000000000 >= 11 10 ? ] if
] if fixnum+fast
] [
[ 12 fixnum+fast ] [ 1000000000000 /i ] bi*
(count-digits)
] if
]
} cond ; inline recursive