PL/I

PL/I

PL/I

 View Only
  • 1.  ** of FIXED BIN(p1,p2) and integer

    Posted Thu August 15, 2019 05:16 PM

    In the following example, we are using the ** (exponent) operator with a FIXED BIN source and raising to an integer power.

    In the LRM, this falls under Case B, except that case B says "provided p <= M".   If p is not <= M then the result will be a floating-pt value, if it is, the result will be a FIXED BIN value.

    Furthermore the LRM defines M as "the maximum precision for FIXED BINARY.  This is the value M2 from the compiler option LIMITS(FIXEDBIN(M1,M2))."

    The program guide indicates that the default for LIMITS(FIXEDBIN()) is (31,63).   Thus, M2 is 63.

    In this example, we can see that the result of the ** operator is not a FIXED BINARY, but instead is a floating point value, because of how the resulting conversion to a CHAR string is accomplished.  If, however, you specify a LIMITS(FIXEDBIN(63)) then the result is a FIXED BIN value (again, because it is formatted in the CHAR string differently):

     

     TEST: PROC OPTIONS(MAIN);

     

      DCL FB FIXED BIN(15,3);

      DCL STR CHAR(512) VARYING;

     

      /* Case B - first operand is FIXED BIN(p1,q1)

       *          second operand integer

       *

       * FB is FIXED BIN(15,3)  In this case, the resulting

       *     value is FIXED BIN( (15 + 1)*n-1, 3*n ) which is

       *              FIXED BIN( 32, 9 ).  32 is greater than

       *              M (which defaults to 31.)

       */

      fb = 1.5;

      str = (fb ** 3);

      DISPLAY('binary 1.5 ** 3 is "' || str || '"');

     

      END;

     

    when I run it without specifying any LIMITS option, I get this output:

     

    binary 1.5 ** 3 is " 3.3750E+00"

     

    when I run it with LIMITS(FIXEDBIN(63)) I get this output:

     

    binary 1.5 ** 3 is "              3.375"

     

    I'm guessing this is a doc error in the description of Case B for the ** operation?

     

    tdr


  • 2.  Re: ** of FIXED BIN(p1,p2) and integer

    Posted Fri August 16, 2019 02:38 PM

    "unless an expression contains an 8-byte integer, all integer arithmetic will done using 4-byte integers." - this is V4R5. What happens if you change he precision of one of the operands?

    PeteF