Thanks Eric,
I am going to have to play with those two particular built-in functions a
bit more. Their use, especially '*/ was not intuitive to me. At first, or
second, reading.

## Advertising

Having just tried it... I am surprised that the 'sqrt* I implemented is
quite a bit faster! than the built-in 'sqrt. I'll try the long division
later.
: (scl 100000) (bench (nil (sqrt 2.0))) # Built-in
30.917 sec
-> NIL
: (scl 100000) (bench (nil (sqrt* 2.0))) #
2.906 sec
-> NIL
: (scl 10000) (bench (nil (sqrt 2.0))) # Built-in
0.253 sec
-> NIL
: (scl 10000) (bench (nil (sqrt* 2.0)))
0.044 sec
-> NIL
1 Miiiiillion digits of sqrt(2):
--------------------------------
The 'sqrt* function implemented does need more than 13 iterations to
converge accurately when the number of digits are > 300K or so. The
corrected version is below. It now checks for convergence. 1M digits of
the sqrt(2) takes 20 iterations to converge. The results, dumped to a file,
are the same as the first 1M digits here...
https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
I'll say it again.. I am really impressed by picolisp. I have not had this
much fun expressing ideas in code in some time.
/Lindsay
: (scl 1000000) (bench (nil (sqrt* 2.0)))
323.805 sec
: (scl 1000000) (bench (out "sqrt2-1M.txt" (nil (prin (sqrt* 2.0)))))
932.620 sec
# Scaled fixed point sqrt()
# ... check for convergence added.
(de sqrt* (N S)
(let (P (/ N 2) M 63 C (0 0 .))
(default S *Scl)
(set C P (cdr C) 0)
(setq N (* N (** 10 S)))
(while
(and
(ge0 (dec 'M))
(<> (car C) (cadr C) P) )
(setq P (/ (+ P (/ N P)) 2))
(pop 'C)
(set C P))
(set C 0 (cdr C) 0)
P ) )