Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I found more "bugs" in the LISP version:

+BAILOUT+ constant needs to be 16.0, not 16, as it's used in floating-point comparison:

(defconstant +BAILOUT+ 16.0)

The "i" variable was declared fixnum in the incorrect place, it should be right after the "do" block:

(do ((i 0 (incf i))) (nil) (declare (type fixnum i))

Also I've commented the printing, printing is slow, especially doing format for each character:

(declaim (optimize (speed 3))) (defconstant +BAILOUT+ 16.0)

(defconstant +MAX-ITERATIONS+ 1000)

(defun mandelbrot (x y)

(declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0)

#+lispworks (float 0)))

(declare (type single-float x y))

(let ((cr (- y 0.5))

(ci x)

(zi 0.0)

(zr 0.0))

(declare (type single-float cr ci zi zr))

(do ((i 0 (incf i)))

(nil)

(declare (type fixnum i))

(let ((temp (the single-float ( zr zi)))

(zr2 (the single-float ( zr zr)))

(zi2 (the single-float ( zi zi))))

(declare (type single-float temp zr2 zi2))

(setq zr (the single-float (+ (- zr2 zi2) cr)))

(setq zi (the single-float (+ temp temp ci)))

(when ( (the single-float (+ zi2 zr2)) +BAILOUT+)

(return-from mandelbrot i))

(when ( i +MAX-ITERATIONS+)

(return-from mandelbrot 0))))))



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: