common lisp - how to implement CCL::DOUBLE-FLOAT-FROM-BITS function -


i want use cl-olefs package.but found cantains plantform dependent function double-float-from-bits.

so want write function double-float-from-bits can run on plantform independently. have no idea how implment it.

or there independent functions double-float-from-bits can replaced into
cl-olefs package.

something along these lines. not terribly efficient, should quite portable.

(defun double-float-from-bits (high low)   (let* ((negative (not (zerop (logand high #x80000000))))          (mant (+ low (* #x100000000 (logand high #xfffff))))          (exbits (logand (ash high -20) #x7ff))          (ex (coerce (expt 2 (- exbits 1075)) 'double-float))          (base (coerce (+ #x10000000000000 mant) 'double-float)))     (cond ((and (zerop exbits)                 (zerop mant))            (if negative -0.0 0.0))           ((zerop exbits)            'subnormal)           ((and (= #x7ff exbits)                 (zerop mant))            (if negative 'negative-infinity 'positive-infinity))           ((= #x7ff exbits)            'not-a-number)           (negative            (- (* base ex)))           (t            (* base ex))))) 

note common lisp spec not require internal floating point representation of ieee 754; requirements bit less strict. additionally, there no means of portably expressing infinities or not-a-numbers, , chose not support subnormals.

also, there may small rounding errors, depending on implementation.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -