home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!well!well.sf.ca.us!shf
- From: shf@well.sf.ca.us (Stuart H. Ferguson)
- Subject: Re: Help - IFF files used to store DOUBLES
- Message-ID: <shf.721564315@well.sf.ca.us>
- Sender: news@well.sf.ca.us
- Organization: Whole Earth 'Lectronic Link
- References: <1992Oct27.142015.2635@brandonu.ca> <shf.720953994@well.sf.ca.us> <BxEsyo.5I7@news.orst.edu>
- Date: Thu, 12 Nov 1992 10:31:55 GMT
- Lines: 53
-
- +--- brindley@maxwell.ECE.ORST.EDU (Mike Brindley) writes:
- |In article <shf.720953994@well.sf.ca.us> shf@well.sf.ca.us (Stuart H. Ferguson) writes:
- |>In <1992Oct27.142015.2635@brandonu.ca> brycerw@brandonu.ca writes:
- |>> [...] What is the best format to store DOUBLES in an IFF
- |>>file to maintain consistency in machine-independence. These files will
- |>>inevitably be used on PC's, and vax's, as well as other amigas.
- |>I would use IEEE, since this is a published and common standard. [...]
- |> on your Amiga, the values in memory are IEEE format,
- |>so you can just dump the bits directly and get a machine-independent
- |>file. ^^^^^^^^^^^^^^^^^^^
- |Are you sure that you will get a platform independent disk file? I know
- |of one example where the bytes of single precision IEEE f.p. numbers
- |are stored on disk in the perverse Intel order (least significant byte
- |first to most significant byte last). This format should take a little
- |bit of byte shuffling to read or produce on a Motorola processor.
-
- Yes, the byte-order is reversed on some machines. So what? This
- doesn't stop people from writing integers directly into IFF files.
- On a PC you have to swap the bytes when you read words out of an ILBM
- header, and people do it all the time. I never suggested IEEE numbers
- are machine-independent bit for bit, just that the format is a
- published standard. You may have to do some futzing around when you
- read it on another machine to get the number into a native format. It
- might look something like this:
-
- float convertIEEE(long in)
- {
- long mant, exp;
- float v;
-
- mant = (in & 0x7FFFFF) | 0x800000;
- exp = ((in & 0x7F800000) >> 23) - 65;
- v = mant * pow (2.0, exp - 23);
- if (in & 0x80000000)
- return (-v);
- else
- return (v);
- }
-
- This is from memory, so don't quote me. Notice that this contains
- knowledge only about the public IEEE format and nothing about the
- unknown local machine format. Little-endians may have more work,
- but we gave them more work when we decided integers in IFF files
- would be in our byte order also.
-
- I think the suggestion about using ASCII number strings misses the
- point. Text files are easy to read and write and transport -- much
- easier than IFF files -- but they are also sloppy and large.
- If the original poster wants to use an IFF file, we have to assume
- he's willing to do more work to get a cleaner, more compact result.
- --
- Stuart Ferguson (shf@well.sf.ca.us)
- Prepare to Surge to Sublight Speed!
-