C++ compiler interpretation of long doubles
HCL Informix® Object Interface for C++ provides data type conversion functions in the value interface ITConversions to enable conversion of C++ type long double. The intent is to permit fetching floating point values into C++ long double variables. However, the HCL Informix® Client Software Development Kit does not allow for conversion of long double values into HCL Informix® decimal or float types. Thus, Object Interface for C++ applications should always ensure that any floating literal passed to ITConversions::ConvertFrom(long double val) is within the double range. Otherwise, ConvertFrom(long double val) will return FALSE for value objects that contain SQL MONEY, FLOAT, and SMALLFLOAT values.
Object Interface for C++ is written with the assumption that a floating literal without the ANSI C++ specified suffixes l or L (example: 12.988 instead of 12.988L) assigned to a long double variable will be treated by the C++ compiler as a long double. This assumption agrees with the ANSI C++ Draft Standard (Doc No: X3J16/94-0027, WG21/N0414, 25 January 1994), which states that the type of a floating literal is double unless explicitly specified by a suffix. The suffixes f and F specify float; the suffixes l and L specify long double. Thus, the suffix l or L must be applied to a floating literal in order for it to be interpreted by the C++ compiler as a long double value.
long double d = 12.988;
double dasd = (double) d;
if( dasd == d )
return 0;
else return 1;
The following table compares support for the ANSI C++ draft standard referenced above among several versions of Sun C++ compilers. The table shows how the different compiler versions evaluated the expression (dasd == d). If the expression evaluates to FALSE, the values are not equal.
Sun C++ compiler versions | Evaluation of (dasd == d) |
---|---|
4.0 (Dec 1993) | FALSE (values are not equal) |
4.0.1 (Jul 1994) | FALSE (values are not equal) |
4.1 (Oct 1995) | TRUE (values are equal) |
5.0 (Oct 1999) | TRUE (values are equal) |
6.01 (2001) | TRUE (values are equal) |