Search code examples
zospl-i

PL/1 fixed and float, dec and bin data types. Difference between dec and bin. How many bytes?


I came from c++ and java and now I am reading book about PL/1 and have some problems with understanding data types. First is fixed bin. As I understand actually there are 4 fixed bin types. They are:

fixed bin(7,n) -- 1 byte

fixed bin(15,n) -- 2 byte

fixed bin(31,n) -- 4 byte

fixed bin(63,n) -- 8 byte

If I write in my program for example fixed bin(10,n) it will be "converted" into fixed bin(15,n) cause PC/mainfraim can hold numbers only in whole bytes. As I know there are also fixed dec(m,n) data types. But what is these "magical m numbers" for fixed dec of 1,2,4,8 bytes? Is internally representation in memory of fixed bin and fixed dec equal or different?

And about float. What are magical float bin and float dec m numbers? For how many bytes they are? And is internally representation of float bin and float dec equal/different?

I found only float dec(33) (16 bytes i think). And float bin(21) - 4 bytes, (53) - 8 bytes.


Solution

  • As you have already noted the "magic numbers" for FIXED BINARY is always one less than the number of bits in (power of two) bytes. the "one less" being there because of the sign-bit. So it is easy to understand that for FIXED BINARY UNSIGNED the boundaries are shifted by one and are 8,16,32,64 respectively.

    The internal representation for FIXED DECIMAL might seem a bit unusual if you don't come from a mainframe background, since it uses packed BCD (binary coded decimal) where each decimal digit takes up 4 bits and the sign is indicated by another 4 bits (hex D being negative, hex Cor Fpositive). So the internal representation of +1287 would be (in hex) 01 28 7C. Also the internal length does not have to be a power of two, so you might say the "magic numbers" for FIXED DECIMAL are all odd numbers, since these fill a whole number of bytes completely while even numbers leave the leftmost halfbyte unused.

    For BINARY FLOAT data the processor (I assume you run on System z hardware) knows three internal types: short, long and extended precision occupying 4, 8 or 16 bytes respectively. Short is used for precisions up to 21, long for precisions up to 53, extended for anything greater.

    With DECIMAL FLOAT things get a bit more complicated, since it depends whether the compiler can exploit the internal decimal floating point (DFP) device. If it can the upper bounds for short and long precision are 7 and 16, if it can't use it it will use a binary internal representation and the precision bounds are 6 and 16 (since precision now means decimal digits).

    Source: all of those boundaries are from the Enterprise PL/I for z/OS V4.5 Language Reference.