[comp.lang.c] Floating point format conversion?

exubho@exud1.ericsson.se (Blake Holman) (04/26/91)

Hi,

I have a data file which was written using Micrsoft binary format for
floating point numbers.  On a PC this is not a problem because the
microsoft C libraries have a function to convert the MSC binary format
to IEEE binary format.

I am looking for a function to perform this same function on a Sun
workstation running SunOS 4.1.1.  Does anyone have the source code
for this type of function or know the algorithm for such a conversion?

Please e-mail responses and I will summarize.

Thanks in advance.

Blake Holman
Ericsson Network Systems, Inc.
Richardson, Texas
(214) 997-6784

gtephx (Wild Rider) (04/30/91)

	i tried email, but (alas), it bounced; here's the text:

In article <1991Apr25.203121.11130@ericsson.se> writes:
>
>Hi,
>
>I have a data file which was written using Micrsoft binary format for
>floating point numbers.  On a PC this is not a problem because the
>microsoft C libraries have a function to convert the MSC binary format
>to IEEE binary format.
>
>I am looking for a function to perform this same function on a Sun
>workstation running SunOS 4.1.1.  Does anyone have the source code
>for this type of function or know the algorithm for such a conversion?
>

	uh, well, if it were me, being the lazy scumbag that i am :-),
	i'd simply do the conversion on the pc side using the microsoft
	conversion function, then ship the converted data to the sun.

	but, i suppose, you already have the data on the sun & have
	no way of getting it to the pc & back?

	hmm... well, then, you _do_ have a problem, don't you...
	if you have the intestinal fortitude, you can write a
	function in c to do the trick; i had to convert ibm (mainframe)
	floating point to ieee & was able to do it in c pretty
	easily, once i had the specs for the 2 formats.  all you 
	need to do is declare a bitfield struct for each format, 
	then push the bits around as necessary.  for example, i
	believe the following struct pretty much describes an ieee
	floating point value:

		typedef struct {
			ieee_sign	unsigned:1;
			ieee_exp	unsigned:8;
			ieee_mantissa	unsigned:23;
		} ieee_t;

	btw, don't forget the "hidden bit" when you're doing the conversion...
	all this makes more sense when you're looking at the specs.

	hope this helps...
	wr (wild rider)
-- 
Wallace Roberts, AG (formerly GTE) Communication Systems, Phoenix, AZ
UUCP: ...!{ncar!noao!asuvax | uunet!zardoz!hrc | att}!gtephx!robertsw
Internet: gtephx!robertsw@asuvax.eas.asu.edu    Bike: '82 GS1100L Suz
voice: (602)581-4555    fax: (602)582-7624      Cage: '89 Mustang  GT