home *** CD-ROM | disk | FTP | other *** search
- ;;; --------------------------------------------------------------------------;
- ;;; SQR.LSP
- ;;; (C) ¬⌐┼v 1988-1992 Autodesk ñ╜Ñq
- ;;;
- ;;; Ñ╗╡{ªíñwÑ╤ Autodesk ñ╜Ñq╡∙ÑU¬⌐┼v, ╢╚⌐≤ñU¡z▒í¬pñUÑi▒┬╗P▒zíu│\ÑiívíC
- ;;; ╗╒ñUñú▒oÑHÑ⌠ª≤º╬ªí╡oªµ⌐╬ÑX¬⌐ª╣╡{ªí¬║íu¡∞⌐l╜Xív; ª²ñ╣│\▒zªb»S⌐w¡lÑ═
- ;;; ¬║ñuº@ñW╡▓ªXª╣╡{ªí¬║íuÑ╪¬║╜Xív¿╧Ñ╬íCª│├÷│o├■¡lÑ═ñuº@¬║▒°Ñ≤ªpñU:
- ;;;
- ;;; ( i) │]¡pñW╗Pñuº@ñW¼╥»┬║Θ░w╣∩ Autodesk ñ╜Ñq¬║▓ú½~íC
- ;;; (ii) ╕ⁿª│íu¬⌐┼v (C) 1988-1992 Autodesk ñ╜Ñqív¬║¬⌐┼v│qºiíC
- ;;;
- ;;;
- ;;;
- ;;; AUTODESKñ╜Ñq┤ú¿╤ª╣╡{ªí╢╚¿╤º@íu├■ªⁿív¬║░╤ª╥, ª╙ÑBñú▒╞░úª│Ñ⌠ª≤┐∙╗~¬║
- ;;; Ñi»αíCAUTODESKñ╜Ñq»Sª╣º_╗{Ñ⌠ª≤»S⌐wÑ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºt
- ;;; ÑX¿π¬║½O├╥íCAUTODESKñ╜ÑqªP«╔ÑτñúÑX¿πª╣╡{ªí░⌡ªµ«╔ñ@⌐wñú╖|íuññ┬_ív⌐╬
- ;;; íuº╣Ñ■╡L╗~ív¬║½O├╥íC
- ;;;
- ;;;
- ;;; --------------------------------------------------------------------------;
- ;;; DESCRIPTION
- ;;;
- ;;; This is a programming example.
- ;;;
- ;;; This is an implementation of a square root function in
- ;;; LISP using the Newton-Raphson method as used in AutoCAD.
- ;;; It is intended as a test of floating point arithmetic in
- ;;; our LISP, as you can check accuracy with the statement:
- ;;; (- (sqr 2) (sqrt 2))
- ;;; which will compare the built-in function with this one.
- ;;;
- ;;; John Walker 12/17/84
- ;;;
- ;;; --------------------------------------------------------------------------;
-
- (defun sqr (x / y c cl)
- (if (or (= 'REAL(type x)) (= 'INT(type x)))
- (progn
- (cond ((minusp x) 'Negative-argument)
- ((zerop x) 0.0)
- (t (setq y (/ (+ 0.154116 (* x 1.893872)) (+ 1.0 (* x 1.047988))))
- (setq c (/ (- y (/ x y)) 2.0))
- (setq cl 0.0)
- (while (not (equal c cl))
- (setq y (- y c))
- (setq cl c)
- (setq c (/ (- y (/ x y)) 2.0))
- ) y
- )
- )
- )
- (progn
- (princ "ñ▐╝╞╡L«─íC")
- (princ)
- )
- )
- )
-
- ;;; --------------------------------------------------------------------------;
-