HP aC++/HP ANSI C A.06.28 Release (769149-001, March 2014)
• In next release, default C compilation mode will change from C89 to C99
• In next release, default C++ compilation mode changes to full -AA
Decimal floating-point arithmetic (HP-UX 11.31 only) (New)
On HP-UX 11.31 systems, support is now included for decimal floating-point arithmetic for C. This
support follows the current draft revision of the IEEE 754 floating-point standard and ISO/IEC
Technical Report 24732, Extensions for the programming language C to support decimal
floating-point arithmetic. With decimal FP (unlike the usual binary FP), typical numerical strings
can be represented exactly in the types, avoiding subtle input errors and confusion from inexact
output. Therefore, decimal FP is WYSIWYG.
Decimal FP is designed particularly for financial applications, including banking, billing, tax
calculation, currency exchange, and accounting.
A decimal FP representation is best thought of as a triple (s, c, q) composed of a sign (1 or −1),
an integral coefficient, and a quantum exponent, representing s * c *10
q
. Therefore, 123. = (1,
123, 0) and 123.00 = (1, 12300, −2) are different representations, although they have the same
numerical value and compare equal. Arithmetic operations are defined to preserve the position of
the decimal point, much as hand-computation would. For example, 123.00 + 45.6 = 168.60 and
123.00 * 0.01 = 1.2300. These special quantum semantics facilitate exact fix-point calculation.
For typical floating-point calculations, the quantum semantics can be ignored.
Decimal FP support includes the following:
• Three built-in decimal FP types:
_Decimal32 _Decimal64 _Decimal128
with 7, 16, and 34 decimal digits of precision, respectively.
• The usual built-in arithmetic operators for decimal FP operands: +, −, *, /, assignments,
comparisons, and conversions with integer and binary FP types, all with correctly-rounded
IEEE arithmetic. An operation may combine a decimal FP operand with an operand of a
different decimal FP type or with an integer type. However, mixing operands of decimal and
binary FP types is not allowed.
• 60 math functions for each decimal FP type. Function suffixes are d32 for _Decimal32, d64
for _Decimal64, and d128 for _Decimal128. Included are:
◦ Decimal FP versions of the C99 math functions.
◦ New functions to manage quantum exponents (for fixed-point calculation).
◦ Routines to encode and decode data for either of the two standard encodings for decimal
FP data. Details of the encodings are in the draft revision of IEEE 754, which refers to
them as the "binary encoding", which the HP C/aC++ compiler uses, and the "decimal
encoding". Both encodings provide exactly the same data, analogous to big endian and
little endian encodings.
• Decimal FP I/O and string conversion. The decimal FP length modifiers for printf() and
scanf() floating-point conversion specifiers (a, A, e, E, f, F, g, G) are H for _Decimal32, D
for _Decimal64, and DD for _Decimal128. The decimal a, A specifiers for printf(), given
no precision or sufficient precision, produce an exact quantum-preserving representation of
the decimal FP value being converted.
• WDB debugger support for printing values of decimal FP types.
• Suffixes to designate decimal floating constants: df or DF for _Decimal32, dd or DD for
_Decimal64, and dl or DL for _Decimal128. Note that an unsuffixed floating constant still
has type double, regardless of the context. Explicit suffixing with a d or D to specify type
double is also allowed.
New features in version A.06.20 33