From: Jun Chen
Subject: Re: [help] How to dump floating point numbers
Date: 
Message-ID: <480sl0$ghq@nunki.usc.edu>
>Jun Chen <····@nunki.usc.edu> wrote:
>>Does anybody know how to dump floating point 
>>numbers into a file in binary (not ascii) format? 
>>Is it possible in Lisp? 
>

Reply one:

>In Common Lisp, you can use the function INTEGER-DECODE-FLOAT to get a
>representation of a flonum in terms of integral components, which you
>can then write out to a binary file.  Note that there can be several
>flonum point formats (even infinite precision ones), so you have to
>either restrict things to one format or arrange for tagging the data.
>

Reply two:

>Two approaches:
>1) Look in the manual for your implementation to find the non-portable
>function to convert between floats and their representations as integer
>words.
>
>2) Look in Steele to find the portable function which converts between floats
>and integers representing the sign, exponent, and mantissa.

Thanks to all who replied to my posting.
In my original posting, what I meant was actually saving
floating point numbers in IEEE standard format so that programs
written in other language can read. Saving as several integers 
won't do that. I finally gave up using Lisp to do this. Instead,
I passed  float numbers to a short routine written in C and let 
the C routine write those numbers into a file.

-Jun

From: Tim Pierce
Subject: Re: [help] How to dump floating point numbers
Date: 
Message-ID: <DHuu2z.H2I@midway.uchicago.edu>
In article <··········@nunki.usc.edu>, Jun Chen <····@nunki.usc.edu> wrote:

>Thanks to all who replied to my posting.
>In my original posting, what I meant was actually saving
>floating point numbers in IEEE standard format so that programs
>written in other language can read. Saving as several integers 
>won't do that.

Huh?

You can't store anything in a (conventional, von Neumann) computer
without encoding it as a series of integers.  Not even the IEEE
can do this.

-- 
By sending unsolicited commercially-oriented e-mail to this address, the 
sender agrees to pay a $100 flat fee to the recipient for proofreading 
services.
From: Jun Chen
Subject: Re: [help] How to dump floating point numbers
Date: 
Message-ID: <482o0e$l49@nunki.usc.edu>
In article <··········@midway.uchicago.edu> Tim Pierce <········@midway.uchicago.edu> writes:
<In article <··········@nunki.usc.edu>, Jun Chen <····@nunki.usc.edu> wrote:
<
<>Thanks to all who replied to my posting.
<>In my original posting, what I meant was actually saving
<>floating point numbers in IEEE standard format so that programs
<>written in other language can read. Saving as several integers 
<>won't do that.
<
<Huh?
<
<You can't store anything in a (conventional, von Neumann) computer
<without encoding it as a series of integers.  Not even the IEEE
<can do this.


What I meant above was representing a float number using integers such
as sign(-1 or 1), base(2 or 10), exponent, and significand. This is certainly
not IEEE format, which encodes those components in bit fields rather
than separate integers.
 
-Jun
From: Ken Anderson
Subject: Re: [help] How to dump floating point numbers
Date: 
Message-ID: <KANDERSO.95Nov12120804@lager.bbn.com>
In article <··········@nunki.usc.edu> ····@nunki.usc.edu (Jun Chen) writes:

> 
> What I meant above was representing a float number using integers such
> as sign(-1 or 1), base(2 or 10), exponent, and significand. This is certainly
> not IEEE format, which encodes those components in bit fields rather
> than separate integers.

you need to take the information provided by integer-decode-float and
construct an ieee number from it.  Something like this:

(defun to-u32 (value)
  (multiple-value-bind
      (integer exponent sign)
      (integer-decode-float value)
    (if (zerop integer)
	0
      (let ((bits (integer-length integer)))
	(dpb (if (plusp sign)
		 0
	       1)
	     (byte 1 31)
	     (dpb (+ 127
		     exponent
		     (1- bits))
		  (byte 8 23) 
		  (dpb (ldb (byte 23 (- bits
					24))
			    integer)
		       (byte 23 0)
		       0)))))))

USER(21): (to-u32 (single-float pi))
1078530011