SUMMARY: Binary floating point number conversion

From: Stefan Jon Silverman (sjs@sunthing.sjsinc.com)
Date: Mon Apr 22 1996 - 16:49:51 CDT


Folks:

        1st the thanx list:

Sean Skilton seans@ctpm.uq.edu.au
Thomas Koetter thomas@wiwi.hu-berlin.de
Steve Swales steve@ftp.lle.rochester.edu
Scott Allendorf sca@sysadm.physics.uiowa.edu
Patrick L. Nolan pln@egret1.Stanford.EDU
Keith Bierman Keith.Bierman@Eng.Sun.COM

        and especially:

Frode Stromsvag frode@read-well.no
Mark Wiederspahn markw@utig.ig.utexas.edu

        The three basic answers were:

        1). use the XDR routines in the Sun RPC developers lib and the same
            on the mainframe (not an option, the mainframers are cobol
            programmers who fear even basic floating point, let alone a
            library they have never worked with -- all conversions must be
            done on the Sun side).

        2). If using the Sun unbundled compiler, use the convert_external()
            functions (a possibility, but I would like more flexability and
            portability to other platforms whose libs may not contain these
            functions).

        3). Use the source code sent to me by Frode and written by Mark
            (although he too reccomended convert_external()).

        I'm going with Mark's source for the moment and in the absence of
any problems during testing this week will stick with this function lib.

        Thanx to all...original question included below...

        Regards,

        b c++'ing u,

        %-) sjs

PS: I am my own employer, therefore: "all opinions are twice spoken for;"
        and they do, in fact, scare the hell out of said employer!!!

-------------------------------------------------------------------------------
Stefan Jon Silverman - President SJS Associates, N.A., Inc.
                                                            572 Chestnut Street
Distributed Systems Architecture & Implementation San Francisco, Ca. 94133
                                                            Phone: 415 989 2741
                                                            Fax: 415 989 7250
E-mail: sjs@sjsinc.com Cell: 415 519 3494
-------------------------------------------------------------------------------
                  Weebles wobble, but they don't fall down!!!
-------------------------------------------------------------------------------

----- Begin Included Message -----

>From sjs Thu Apr 18 18:24:28 1996
To: sun-managers@ra.mcs.anl.gov
Subject: Binary floating point number conversion
Bcc: SJSI%AsiCes%CTS@go50.comp.pge.com
Content-Length: 3846
X-Lines: 95
Status: RO

Folks:

        I have an application running on a SPARC20 Oracle server that must
produce a binary file for transfer over to an IBM mainframe. In order to
minimize network bandwidth, using the alpha-numeric representation for
floating point (and doubles) is not an acceptable option (integers move
just fine).

        Hence, my question: can some kind soul point me to a public-domain
library or dig into your personal source-code archives to provide me with
some 'C' code that can accomplish the conversion of IEEE format binary floats
and doubles to IBM format binary floats and long-floats (64 bit). I spent
a lot of time today in various web search-engines and while reading many
interesting articles and visiting alot of intriguing sites found no joy...

        The crux of the problem is:

IEEE (from a web-page with the standard on www.ee.umd.edu):

         - ------- ------- ------- -------
        |s| exp | | | | |
         - ------- ------- ------- -------
         0 1 7 8 31

        where:

                s is the sign bit.
                1-7 is the exponent represented as a power of 2 in
                        "excess 127" notation (to give positive and negative
                        exponential values).
                8-31 is the base-2 fraction left-shifted to where the
                        first binary "1" is on the left of an imaginary
                        binary-point (with the exponent raised appropriately
                        during the shift) giving a precision of 24 bits
                        stored in 23 bits.

        for a double (64 bits), IEEE uses 11 bits for the exponent and 52
        bits for the mantissa.

IBM (from the System-360 Theory of Operation manual):

         - ------- ------- ------- -------
        |s| exp | | | | |
         - ------- ------- ------- -------
         0 1 7 8 31

        where:

                s is the sign bit.
                1-7 is the exponent represented as a power of 16 in
                        "excess 64" notation (giving a value range of
                        16**-65 <= M <= 16**63). And yes, this is the same
                        127 range as IEEE but expressed differently...sigh!!!
                8-31 is the base-16 (hex) fraction left-shifted (normalized)
                        4 bits at a time to where the first four bits (nibble?)
                        contain a numeric value on the right of an imaginary
                        radix-point (with the exponent raised appropriately
                        during the shift).

        for a long-float (64 bits), IBM uses the same exponent as above with
        a mantissa of 56 bits.

        Anybody out there had to tackle this one before (or have someone in
their user community who may be willing to help)? I got involved in the DEC
VAX --> IEEE floating point representation conversion a couple of years ago
and it wasn't much fun (of course that's now in the public-domain). While
I can program this myself, I would much rather use some battle-hardened and
well tested code.

        If the solution comes out of private source-code, with the permission
of the author, I would be more than willing to package it up for public-
domain distribution.

        TIA...and I will summarize...

        Regards,

        b c++'ing u,

        %-) sjs

PS: I am my own employer, therefore: "all opinions are twice spoken for;"
        and they do, in fact, scare the hell out of said employer!!!

-------------------------------------------------------------------------------
Stefan Jon Silverman - President SJS Associates, N.A., Inc.
                                                            572 Chestnut Street
Distributed Systems Architecture & Implementation San Francisco, Ca. 94133
                                                            Phone: 415 989 2741
                                                            Fax: 415 989 7250
E-mail: sjs@sjsinc.com Cell: 415 519 3494
-------------------------------------------------------------------------------
                  Weebles wobble, but they don't fall down!!!
-------------------------------------------------------------------------------

----- End Included Message -----



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:58 CDT