Packed Decimal Warnings and Error Conditions

C language only
The following figure shows all the warnings and error conditions that are issued by the ILE C compiler for packed decimal expressions.
Figure 1. Packed Decimal Warnings and Error Conditions
#include <decimal.h>
decimal (999,99) s1 = 1234.56d;   /* Generates a severe error because          */
                                  /* the decimal size is greater than 63.      */
decimal (10, 64) s2 = 1234.56d;   /* Generates a sever error because           */
                                  /* the precisionsize exceeds 63.             */
decimal (1.2, 3) s3 = 1.2d;       /* Generates a severe error because          */
                                  /* the decimal size is an invalid number.    */
decimal (2,1.2) s4 = 1.3d;        /* Generates a severe error because the      */
                                  /* precision size is an invalid number.      */
decimal (1,3) s5 = 1.345d;        /* Generates a severe error because the      */
                                  /* precision size exceeds the decimal size.  */
decimal (63,62) s6 
       = 123456789012345678901234567890123456789012345678901234567890123456789d; 
                                  /* Generates a severe error because decimal  */
                                  /* constant is out of range of a valid       */
                                  /* packed decimal constants.                 */
decimal(10,2) s7 = 1234567890123456789012345678901234567890123456789012345678.12345d 
                   + 12345.1234567891d; 
                                  /* s7 = (63,5) + (15,10)                     */
                                  /* Generates a severe error because of       */
                                  /* truncation of precision values in         */
                                  /* intermediate result.                      */
decimal (10,2) s8 = 123456789012345678901234567890.12345d  
                    * 12345678901234567890123456.12d;   
                                  /* s8 = (35,5) + (28,2)                      */
                                  /* Generates a severe error because of       */
                                  /* truncation of precision values in         */
                                  /* intermediate result.                      */
decimal (10,2) s9 = 1234567890123456789012345678901234567890d  
                    / 1234567890.123456789012345678901234567891d;
                                  /* Generates a warning for possible loss of  */
                                  /* whole-digit data in intermediate value.   */
                                  /* Generates a severe error for loss of      */
                                  /* whole-digit data loss in result.          */
Note:
  • For assignments to a target field that is to small to hold the packed decimal number, the ILE C compiler issues no warning or error for static, external or automatic initialization.
  • For expressions requiring decimal point alignment (namely addition, subtraction or comparison), the ILE C compiler issues errors for static, external, and automatic initialization if, during alignment, the maximum number of allowed digits is exceeded.
  • For multiplication, if the evaluation of the expression results in a value larger than the maximum number of allowed digits:
    • A compile time error is issued for static or external initialization; no module is created.
    • A compile time warning is issued if the expression is within a function; a runtime exception is generated.
    • Truncation occurs on the fractional part, preserving as much of the integral part as possible.
  • For division, a compile time error is generated when ((n1- p1) + p2) >63.

The ILE C/C++ Language Reference contains information on the multiplication and division operators for packed decimals.