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