; integer logarithm
(define (leftmost-digit base n)
(if (< n base)
n
(let ((leftmost-pair (leftmost-digit (* base base) n)))
(if (< leftmost-pair base)
leftmost-pair
(quotient leftmost-pair base)))))
(define (leftmost-digit+ base n)
(if (< n base)
(values n 0)
(call-with-values (lambda () (leftmost-digit+ (* base base) n))
(lambda (leftmost-pair count)
(if (< leftmost-pair base)
(values leftmost-pair (* count 2))
(values (quotient leftmost-pair base) (+ (* count 2) 1)))))))
(display (leftmost-digit 10 816305093398751331727331379663195459013258742431006753294691576)) (newline)
(call-with-values
(lambda () (leftmost-digit+ 10 46729885))
(lambda (leftmost-digit discard-count)
(display leftmost-digit) (newline)
(display discard-count) (newline)))