#lang racket
(define (average x y) (/ (+ x y) 2))
(define (square x) (* x x))
(define (abs x) (if (< x 0) (- x) x))
(define (improve guess x) (average guess (/ x guess)))
(define (good-enough? guess x) (< (abs (- (square guess) x)) 0.000000001))
(define (try guess x)
(if (good-enough? guess x)
guess
(try (improve guess x) x)))
(define (sqrt x) (try 1 x))
(sqrt 2)
海伦平方根算法(LISP描述)
推荐阅读
- 解决:ValueError: Cannot mask with non-boolean array containing NA / NaN values
- Module build failed: TypeError: this.getOptions is not a function at Object.loader
- openpyxl 设置单元格自动换行
- React报错:You are running `create-react-app` 5.0.0, which is behind the latest release (5.0.1).
- Vue中splice的使用
- 博客园设置Markdown编辑器并生成目录
- python: ImportError: cannot import name '_unicodefun' from 'click'
- eclipse module-info.java文件
- linux下的venv使用
- QLabel标签快捷键的使用