scheme/MIT/sqrt.scm

15 lines
257 B
Scheme
Raw Normal View History

2024-09-02 08:58:30 +02:00
(define (sqrt x)
(define tolerance 0.00001)
(define (good-enough? y)
(< (abs (- (* y y) x)) tolerance))
(define (improve y)
(average (/ x y) y))
(define (try y)
(if (good-enough? y)
y
(try (improve y))))
(try 1))
(sqrt 13)