X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=math.lisp;h=327de3f6f5b87cea8c2422d735d62dceb8492188;hp=c03b27f5d54238e5cfc1a48df0e43d7e3d3d5f8c;hb=03712fbb06acbb103602bae10f41aeae7fa05127;hpb=739b14ee8844dc777b174105646df3abcb865282 diff --git a/math.lisp b/math.lisp index c03b27f..327de3f 100644 --- a/math.lisp +++ b/math.lisp @@ -22,7 +22,7 @@ (defun deriv (f dx) #'(lambda (x) (/ (- (funcall f (+ x dx)) (funcall f x)) - dx))) + dx))) (defun sin^ (x) (funcall (deriv #'sin 1d-8) x)) @@ -42,34 +42,34 @@ (when (zerop (length v)) (return-from histogram (values nil nil nil)) ) (let ((n (length v)) - (bins (make-array n-bins :element-type 'integer :initial-element 0)) - found-min found-max) + (bins (make-array n-bins :element-type 'integer :initial-element 0)) + found-min found-max) (declare (fixnum n)) (unless (and min max) (setq found-min (aref v 0) - found-max (aref v 0)) + found-max (aref v 0)) (loop for i fixnum from 1 to (1- n) - do - (let ((x (aref v i))) - (cond - ((> x found-max) - (setq found-max x)) - ((< x found-min) - (setq found-min x))))) + do + (let ((x (aref v i))) + (cond + ((> x found-max) + (setq found-max x)) + ((< x found-min) + (setq found-min x))))) (unless min - (setq min found-min)) + (setq min found-min)) (unless max - (setq max found-max))) + (setq max found-max))) (let ((width (/ (- max min) n-bins))) (setq width (+ width (* double-float-epsilon width))) (dotimes (i n) - (let ((bin (nth-value 0 (truncate (- (aref v i) min) width)))) - (declare (fixnum bin)) - (when (and (not (minusp bin)) - (< bin n-bins)) - (incf (aref bins bin)))))) + (let ((bin (nth-value 0 (truncate (- (aref v i) min) width)))) + (declare (fixnum bin)) + (when (and (not (minusp bin)) + (< bin n-bins)) + (incf (aref bins bin)))))) (values bins min max))) - + (defun fixnum-width () (nth-value 0 (truncate (+ (/ (log (1+ most-positive-fixnum)) (log 2)) .5)))) @@ -81,21 +81,21 @@ (multiple-value-bind (significand exponent) (decode-float float) (multiple-value-bind (1.0-significand 1.0-exponent) - (decode-float (float 1.0 float)) + (decode-float (float 1.0 float)) (if (and (eq operation '-) - (= significand 1.0-significand)) - (scale-float (typecase float - (short-float short-float-negative-epsilon) - (single-float single-float-negative-epsilon) - (double-float double-float-negative-epsilon) - (long-float long-float-negative-epsilon)) - (- exponent 1.0-exponent)) - (scale-float (typecase float - (short-float short-float-epsilon) - (single-float single-float-epsilon) - (double-float double-float-epsilon) - (long-float long-float-epsilon)) - (- exponent 1.0-exponent)))))) + (= significand 1.0-significand)) + (scale-float (typecase float + (short-float short-float-negative-epsilon) + (single-float single-float-negative-epsilon) + (double-float double-float-negative-epsilon) + (long-float long-float-negative-epsilon)) + (- exponent 1.0-exponent)) + (scale-float (typecase float + (short-float short-float-epsilon) + (single-float single-float-epsilon) + (double-float double-float-epsilon) + (long-float long-float-epsilon)) + (- exponent 1.0-exponent)))))) (defun sinc (x) (if (zerop x)