home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15727 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.9 KB  |  65 lines

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