# Just Launched: You can now import projects and releases from Google Code onto SourceForge

We are excited to release new functionality to enable a 1-click import from Google Code onto the Allura platform on SourceForge. You can import tickets, wikis, source, releases, and more with a few simple steps.

## sbcl-devel

 [Sbcl-devel] SCALE-FLOAT shouldn't be so complex From: Paul Khuong - 2009-12-28 18:20:19 ```The CLHS tells us: scale-float returns (* float (expt (float b float) integer)), where b is the radix of the floating-point representation. float is not necessarily between 1/b and 1. The goal is clear, and I would guess that the spirit of the operation was to quickly perform some range checks and increment the exponent field of the float. That fails on denorms. We currently go through some contortions to handle denorms specially without explicitly performing any multiplication (code/float.lisp:scale-float-maybe-underflow, for instance), and still signal FP conditions. I don't see why. Does the following, which uses FP arithmetic whenever there's a chance of exception (except inexact?), seem wrong? (defun simple-scale-single-float (float scale) (declare (type single-float float) (type integer scale)) ;; Clamp the scale *very* conservatively: there's no point in scaling by more than what it takes to ;; bring least-positive-single-float to infinity or most-positive-single-float to 0. (setf scale (min scale (* 3 (- sb-vm:single-float-normal-exponent-max sb-vm:single-float-bias 1))) scale (max scale (* 3 (- sb-vm:single-float-normal-exponent-min sb-vm:single-float-bias 1)))) (flet ((make-scaling-float (scale) (declare (optimize speed)) (let ((two (sb-kernel:single-float-bits 2.0)) (exp (+ scale (+ sb-vm:single-float-bias 1)))) (sb-kernel:make-single-float (dpb exp sb-vm:single-float-exponent-byte two))))) (let* ((scale scale) (float-bits (sb-kernel:single-float-bits float)) (float-exponent (ldb sb-vm:single-float-exponent-byte float-bits)) (new-exponent (+ scale float-exponent))) (declare (type (integer #.(* 3 (- sb-vm:single-float-normal-exponent-min sb-vm:single-float-bias 1)) #.(* 3 (- sb-vm:single-float-normal-exponent-max sb-vm:single-float-bias 1))) scale) (optimize speed)) (cond ((and (<= sb-vm:single-float-normal-exponent-min ; fast path: float-exponent ; input is normal sb-vm:single-float-normal-exponent-max) (<= sb-vm:single-float-normal-exponent-min new-exponent ; and output will be sb-vm:single-float-normal-exponent-max)) (sb-kernel:make-single-float (dpb new-exponent sb-vm:single-float-exponent-byte float-bits))) ;; we're scaling way up or way down, but multiplication by powers of two ;; isn't lossy, so we can scale iteratively. ((< scale (- sb-vm:single-float-normal-exponent-min sb-vm:single-float-bias 1)) (let* ((min-exponent (- sb-vm:single-float-normal-exponent-min (+ sb-vm:single-float-bias 1))) (base-scale (make-scaling-float min-exponent))) (loop while (<= scale min-exponent) do (setf scale (- scale min-exponent) float (* float base-scale)) finally (return (* float (make-scaling-float scale)))))) ((> scale (- sb-vm:single-float-normal-exponent-max sb-vm:single-float-bias 1)) (let* ((max-exponent (- sb-vm:single-float-normal-exponent-max (+ sb-vm:single-float-bias 1))) (base-scale (make-scaling-float max-exponent))) (loop while (>= scale max-exponent) do (setf scale (- scale max-exponent) float (* float base-scale)) finally (return (* float (make-scaling-float scale)))))) ;; another simple case: the input isn't normal, but the scaling factor is. (t (* float (make-scaling-float scale))))))) Paul Khuong ```