Hi all

I'm trying to code something to read and write floating point numbers
from/to a binary stream.

Right now I'm stuck into something strange.

I try to compile the following code, and I get an error about a number
beeing to big to be a double-float... I really don't get it :-(

Here's the code :

;;; From Paul Graham's "On Lisp"

(defmacro with-gensyms (syms &body body)
   `(let ,(mapcar #'(lambda (s)
                      `(,s (gensym)))
                  syms)
     ,@body))

;;; End of P.G.'s code

(defun read-unsigned-integer (nb-bytes) ;; just to pretend it exists.
   (* nb-bytes 8))

(defmacro define-IEEE-float (name
                             &key (sign-bits 1)
                             (exponant-bits 8)
                             (mantissa-bits 23)
                             (bias 127)
                             (associated-type 'float))
       (with-gensyms (significant exponant sign s-bits e-bits m-bits b
value)
        `(defun ,(intern (string-upcase (format nil "read-~s" name))) ()
          (let* ((,s-bits ,sign-bits)
                 (,e-bits ,exponant-bits)
                 (,m-bits ,mantissa-bits)
                 (,b ,bias)
                 (,value (read-unsigned-integer (/ (+ ,s-bits ,e-bits ,m-bits) 8)))
                 (,significant (+ (ash 1 ,m-bits) (logand (1- (ash 1 ,m-bits)) 
,value)))
                 (,exponant (- (logand (1- (ash 1 ,e-bits)) (ash ,value (- ,m-bits))) 
,b))
                 (,sign (ash ,value (- (+ ,e-bits ,m-bits)))))
            (* ,significant (expt 2 ,exponant) (expt (coerce -1
,associated-type) ,sign))))))

(define-IEEE-float IEEE-double-float
     :sign-bits 1
     :exponant-bits 11
     :mantissa-bits 52
     :bias 1023
     :associated-type 'double-float)


It seems there something wrong during the optimization in the 
compilation of the function generated by the macro...

Thanks for any hint you could give.
Martin

PS: Sorry about the long lines...

Reply via email to