All Manuals > LispWorks User Guide and Reference Manual > 9 The Compiler > 9.7 Optimizing your code


9.7.3 Floating point optimization

The declaration float allows generation of more efficient code using float numbers. It reduces allocation during float calculations. It is best used with safety 0. That is, you declare (optimize (float 0) (safety 0)) as in this example:

  (setf a 
        (make-array 1000 
                    :initial-element 1D0
                    :element-type 'double-float))
  nil ; to avoid printing the large array
 (defun test (a)
   (declare (optimize (speed 3) (safety 0) (float 0)))
   (declare (type (simple-array double-float  (1000))
   (let ((sum 0D0))
     (declare (type double-float sum))
     (dotimes (i 1000)
       (incf sum (the double-float (aref a i))))
(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

Note: In some cases, the operations cannot be fully optimized with float 0 , which can cause the compiled code to be larger because the unboxing and boxing of floats will be inline.

LispWorks User Guide and Reference Manual - 21 Dec 2011