caden_varn has asked for the wisdom of the Perl Monks concerning the following question:

I need to create a file including single precision floating point fields in the IBM mainframe format (specifically to be read by the SAS s370frb4. informat). I am on an HP-UX 11 box which evidently uses a different floating point - when I use pack's 'f' option the value changes when read in by the SAS program on the other end. Is there an option or module that can do this easily? Any help greatefully received...

Replies are listed 'Best First'.
Re: Writing IBM Mainframe floating point
by roboticus (Chancellor) on Jul 20, 2018 at 14:19 UTC

    caden varn:

    It seems that the IBM Mainframes support multiple floating point formats. The wikipedia page shows the binary formats for them, and under "Special uses" mentions that SAS 5 Transport files use an IBM format rather than the IEEE format.

    It looks like a relatively simple format* so you should be able to convert between them with a little bit of bit masks, shifts, and such.

    Note: Relatively simple in that there are few fields, and that the IEEE-754 page and the IBM floating point page describes them fully. However, you'll still have to decide what to do in the oddball cases: NaN, *Inf, exponents out of range, deciding how to handle the extra/missing mantissa bits, etc.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Writing IBM Mainframe floating point
by syphilis (Archbishop) on Jul 20, 2018 at 14:03 UTC
    when I use pack's 'f' option the value changes when read in by the SAS program on the other end

    I'm thinking that either:

    a) pack's 'f' option is behaving incorrectly
    or
    b) the "SAS program" is misreading its input.

    Is there a third possibility ?
    If not, an example showing us what pack's 'f' option produces for a specific value, and the changed value that the SAS program reads would help us to determine where the problem lies.

    The ouput of perl -V might also be helpful.

    Cheers,
    Rob
A reply falls below the community's threshold of quality. You may see it by logging in.