In ILE C, a packed decimal is implemented as a native data type. This approach allows an error, such as a decimal format that is not valid, to be detected at compile time. In ILE C++, detection of a similar error is deferred until run time.
Figure 307. _DecimalT Class Template Run-Time Exceptions
|
Run-time exceptions may occur during the following operations:
The run-time exceptions issued by the compiler for _DecimalT class templates are shown in the following figure.
Figure 308. Run-Time Exceptions Issued by the Compiler for _DecimalT Class Templates
#include <bcd.h> static _DecimalT<5,2> s1 = __D("12345678.0"); static _DecimalT<10,2> s2 = __D("1234567891234567891234567.12345") + __D("12345.1234567891"); // s2 = (31,5) + (15,10) static _DecimalT<10,2> s3 = __D("1234567891234562345") * __D("1234567891234.12"); // s3 = (19,0) * (15,2) static _DecimalT<10,2> s4 = __D("12345678912345678912") / __D("12345.123456789123456"); // s4 = (20,0) / (20,15) int main(void) { _DecimalT<5,2> a1 = __D("12345678.0"); _DecimalT<10,2> a2, a3, a4; _DecimalT<5,2> a5 = (_DecimalT<5,2>) __D("123456.78"); a2 = __D("1234567891234567891234567.12345") + __D("12345.1234567891"); // a2 = (31,5) + (15,10) a3 = __D("123456789123456.12345") * __D("1234567891234.12"); // a3 = (20,5) * (15,2) // expression. // Note: Need (35,7) but // use (31,2), for example, // keep the integral part. a4 = __D("12345678912345678912") / __D("12345.123456789123456"); // a4 = (20,0) / (20,15) // Note: Need 35 digits to // calculate integral part // and the result becomes // (31,0). } |
Notes:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.