home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13392 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  2.5 KB

  1. Path: sparky!uunet!psinntp!execnet![jeff.zeitlin@execnet.com]
  2. From: "jeff zeitlin" <jeff.zeitlin@execnet.com>
  3. Newsgroups: comp.lang.c
  4. Subject: cobol comp-3 to dbl
  5. Message-ID: <1992Sep8.798.12908@execnet>
  6. Date: 8 Sep 92 22:37:12 EST
  7. Reply-To: "jeff zeitlin" <jeff.zeitlin@execnet.com>
  8. Distribution: comp
  9. Organization: Executive Networks Information
  10. Lines: 47
  11.  
  12. IN MESSAGE <1992Aug31.174651.14828@thinkage.on.ca>, Alan Bowler writes:
  13.  
  14. AB::>In article <1992Aug26.151021.4445#afs.com> jack@afs.com (Jack Brasch) write
  15.   ::>>Could someone point me in the right direction or mail me a routine to
  16.   ::>>convert COBOL COMP-3 types to a double.
  17.  
  18. AB::>The starting point would be the Cobol programmer's guide for your
  19.   ::>particular Cobol implementation.  Somewhere in there it should tell you
  20.   ::>exactly what COMP-3 is for that Cobol implementation.  The starnadrds
  21.   ::>only say that you can do arithemetic on comp-N items.  What the -N
  22.   ::>produces on your hardware varies with every Cobol compiler.  It is not
  23.   ::>unlikely that comp-N means different things to different compilers on
  24.   ::>the SAME hardware.  (I have seen this several times.)  When you know
  25.   ::>what the hardware is doing with comp-3 on this Cobol compiler, figuring
  26.   ::>out how to convert to a C double should be straight forward.  At worse
  27.   ::>you can move it to a DISPLAY item, and let the C code call strtod().
  28.  
  29.   As I understand it, the definition of COBOL says that data names
  30.   defined as USAGE IS COMPUTATIONAL-3 are stored in what IBM calls
  31.   packed decimal format.  In this form, there are two digits per
  32.   octet, except that the last octet contains one digit and a sign
  33.   indication.  The decimal point is not explicitly stored.
  34.  
  35.   Example:  The number 12,345 would be stored as
  36.   octet       1    2    3
  37.   contains   12   34   5F
  38.  
  39.   where the sign nybble contains a B or D if negative, A, C, E, or F
  40.   if positive.  In my example above, the octets are numbered from
  41.   most significant to least significant.
  42.  
  43.   NOTE: the numbers 1.2345, 123.45, 1,234.5, .12345, \et cetera\ would
  44.   be stored identically.  It is the responsibility of the program to
  45.   interpolate the decimal point.
  46.  
  47.   The only thing you should have to know about the original program is
  48.   a) are these numbers stored big-endian or little-endian, and b) how
  49.   many octets are allocated (i.e. is there any zero padding to a
  50.   specific length).
  51.  
  52.   J/
  53.   jeff.zeitlin@execnet.com
  54.  
  55.  * OLX 2.2 * WARNING ! SAFESEX.ZIP is a Trojan
  56. --
  57. Executive Network Information System  (914) 667-4567
  58. International ILink Host
  59.