[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dealing with the binary representation of floats.



>>>>> "Brian" == "Brian F Dennis" <xjam@CS.Berkeley.EDU> writes:

Brian> Is there any easy or standard way to take an IEEE floating
Brian> point number in Clisp and turn it into it's bit representation
Brian> for transmission through IPC? Ditto for receiving a bit pattern
Brian> and turning it into a float.

INTEGER-DECODE-FLOAT and SCALE-FLOAT might do what you want.

Another approach is to use the FFI with IPC-ready C library routines that
accept floating point numbers.   For instance, some low-level glue
to pack a various types with PVM library routines:

(def-c-call-out raw-pkdouble
  (:name "pvm_pkdouble")
  (:arguments (val (c-ptr double-float)) (nitem int) (stride int))
  (:return-type int))

[etc]

(def-c-call-out raw-upkdouble
  (:name "pvm_upkdouble")
  (:arguments (fptr (c-ptr double-float) :out :alloca)
              (nitem int)
              (stride int))
  (:return-type int))

[etc]

(defun unpack-double ()
  (multiple-value-bind (ret-code a-double) (raw-upkdouble 1 1)
    (if (zerop ret-code) a-double (check-return-code ret-code))))