home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1380 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: larryw@milton.u.washington.edu (Larry Weissman)
  2. Newsgroups: alt.sources
  3. Subject: [sun-spots] Gould floating point
  4. Message-ID: <1990May24.185305.7799@math.lsa.umich.edu>
  5. Date: 24 May 90 18:53:05 GMT
  6.  
  7. Archive-name: dgfloat/23-May-90
  8. Original-posting-by: larryw@milton.u.washington.edu (Larry Weissman)
  9. Original-subject: Gould floating point
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.sys.sun.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. >In response to the message from PRABAL@rcgl1.eng.ohio-state.edu (Prabal Acharyya)
  16. >in V9-162:
  17. >> Can anybody explain the binary format used by SUN OS 4.0.3 to represent
  18. >> floating point numbers.  I am trying to convert floating point numbers
  19. >> from a Gould 32/77 machine to my SUN 4/330.
  20. >
  21. >I can share the following from my experience writing just such a
  22. >translator for IBM-VM/CMS floating point to Sun format (which is standard
  23. >ieee fmt):
  24. >...
  25.  
  26. If the Gould uses IBM 360/370 floating point representation, you can use
  27. the code below for conversion. This runs on the SPARCstation, not the
  28. Gould. This code is not specific to SPARCstations, but some machines, like
  29. DEC's, require byte swapping and exponent range checking.
  30.  
  31. #include <math.h>
  32. /*
  33.  * dgfloat: convert dg mv-series (aka IBM 360/370) floating point data
  34.  */
  35. float dgfloat(r)
  36. float r;
  37. {
  38.     double e;    /* exponent */
  39.     float f;    /* result */
  40.     union u_tag {
  41.         float r;
  42.         long  l;
  43.     } u;
  44.  
  45.     u.r = r;
  46.     e = ((u.l & 0x7f000000) >> 24) - 64;    /* should check range */
  47.     f =  (u.l & 0x00ffffff) / 16777216.0;    /* /2^24 */
  48.     f *= pow(16.0,e);
  49.     return(u.l & 0x80000000 ? -f : f );
  50. }
  51.  
  52. Larry Weissman                         Center for Bioengineering, WD-12
  53. larryw@nsr.bioeng.washington.edu       Univ of Washington, Seattle WA 98195
  54. (206)685-2011
  55.