NextPrevUpTopContentsIndex

9.6.2 Floating point optimization

The float declaration allows generation of more efficient code using float numbers. It reduces allocation during float calculations. It is best used with safety=0 . For example:

(progn
  (setf a 
        (make-array 1000 
                    :initial-element 1D0
                    :element-type 'double-float))
  nil ; to avoid printing the large array
  )
 
(compile 
 (defun test (a)
   (declare (optimize (speed 3) (safety 0) (float 0)))
   (declare (type (simple-array double-float  (1000))
                  a))
   (let ((sum 0D0))
     (declare (type double-float sum))
     (dotimes (i 1000)
       (incf sum (the double-float (aref a i))))
     sum)))
 
(time (test a))
=>
Timing the evaluation of (TEST A)
 
user time    =      0.000
system time  =      0.000
Elapsed time =   0:00:00
Allocation   = 16 bytes standard / 0 bytes conses
0 Page faults

LispWorks User Guide - 21 Jul 2006

NextPrevUpTopContentsIndex