Subject: Re: Large numbers - which Scheme is best?
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 10 Feb 2003 23:23:48 -0600
Newsgroups: comp.lang.scheme
Message-ID: <_8ecncM5N9Z5FdWjXTWc-w@speakeasy.net>
Phil Bewig <pbewig@swbell.net> wrote:
+---------------
| Does this work?
| 
| (define (isqrt a)
|   (if (<= a 0)
|       0 ; punt
|       (let loop ((x 1))
|           (let ((new-x (quotient (+ x (quotient a x)) 2)))
|               (if (= x new-x)
|                   x
|                   (loop new-x))))))
+---------------

Unfortunately, it loops forever when given an argument of
"(- (* x x) 1)", for any "x", e.g., try (isqrt 99).

[Why is left as an exercise for the reader...]


-Rob

-----
Rob Warnock, PP-ASEL-IA		<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607