Summary:
The "fixed decimal" support provided in Gen r7.5 and later releases has been changed to use a different set of mathematical libraries. These changes will require customers to modify any C External Action Blocks which contain decimal precision attributes.
The functionality provided in the new releases is similar to prior releases in that customers will still have to use their own mathematical library to perform any necessary calculations within their EABs, if they do not want to lose precision. However, with the new implementation, conversion functions are no longer necessary to convert from/to a proprietary format.
It is strongly recommended that customers read the Gen r7.5 Release Summary for further documentation on other possible changes to their C applications due to the use of the new mathematical libraries
Instructions:
In traditional C programming, mathematical calculations are performed using floating-point arithmetic. However, floating-point data types cannot always store decimal fractions exactly. This can result in rounding errors and/or imprecise results. For some types of applications, this imprecision does not negatively affect the functionality of the application. In other cases, especially in financial applications, the results of using floating-point arithmetic are unacceptable.
Several companies have written mathematical libraries to provide "fixed decimal" support to the C language. Using these libraries, allows a C application to return results similar to what a COBOL application would return.
Prior releases of Gen used Rogue Wave's math libraries for performing mathematical operations on attributes that had their Technical Design "Implement with decimal precision" property enabled. Starting with Gen r7.5, a new set of math libraries is used to support decimal precision attributes.
This new set of math libraries provides several benefits, including less CPU usage for generated C applications. Other features made possible in this implementation are the ability to detect "divide by zero" and "overflow" error conditions.
One other notable feature provided in this implementation is the fact that the code is no longer dependent on a proprietary data structure to store decimal precision attributes. However, because of this new implementation, customers will have to modify their C External Action Blocks that use decimal precision attributes.
External Action Blocks prior to Gen r7.5
In releases prior to Gen r7.5, decimal precision attributes were represented in the generated C code by the proprietary "rwfixed" data structure. The "rwfixed" structure was essentially equivalent to the Rogue Wave "RWFixedDec96" class.
If customers wanted to maintain precision within decimal precision attributes in their EAB, they had to buy their own Rogue Wave license and use the RWFixedDec96 class. They could cast "rwfixed" views to the RWFixedDec96 class and use the mathematical functions provided by the Rogue Wave libraries to perform any necessary calculations.
In addition to this option, several conversion routines were provided to allow customers to convert between the "rwfixed" data structure and native data types (double, long, and text strings). This allowed customers to convert from the "rwfixed" data structure to a text string. This text string could then be passed to some other mathematical library to perform any necessary calculations. Customers could also convert from the "rwfixed" data structure to a double or a long data type, but may lose precision by doing so.
External Action Blocks after Gen r7.5
In Gen r7.5 and later releases, decimal precision attributes are represented in the generated C code by a non-proprietary variable-size character array. This data type is called a "DPrec" and is a typedef of a char. Decimal precision attributes are now implemented as text strings (i.e., a character array or a DPrec array).
The size of the DPrec array is the length of the attribute plus three. The additional three bytes are for the sign, decimal point and null terminator. For example, a decimal precision attribute defined as a number of 18 digits will be implemented as DPrec[21]. Please see the "Decimal Precision Attributes" section in Chapter 4 of the Gen r8.5 Workstation Construction Guide for additional rules on the contents of a DPrec array.
Because decimal precision attributes are now represented in a "universal" format (text strings), customers no longer have to convert these attributes from/to a proprietary format in their EABs. They can use the text strings directly with whatever mathematical library they choose. Customers can also use standard C functions to convert from strings to other native data types (e.g., double or long), but may lose precision by doing so.