NO

Author Topic: Wrong type for LDBL_TRUE_MIN in <float.h>  (Read 1810 times)

kst

  • Guest
Wrong type for LDBL_TRUE_MIN in <float.h>
« on: October 23, 2012, 01:19:29 am »
Compiler version: Pelles C for Windows, Version 7.00.355 (Win64) under Windows 7 Ultimate 64 bits

The <float.h> header contains the following:

Code: [Select]
#ifdef __MSPOCC__
#define FLT_TRUE_MIN   1.40129846E-45
#define DBL_TRUE_MIN   4.9406564584124654E-324
#define LDBL_TRUE_MIN  4.9406564584124654E-324
#else /* !__MSPOCC__ */
#define FLT_TRUE_MIN   0x8p-152F
#define DBL_TRUE_MIN   0x8p-1077
#define LDBL_TRUE_MIN  0x8p-1077
#endif /* !__MSPOCC__ */

Both versions of the definition of LDBL_TRUE_MIN are of type double. They should be of type long double. This is easily fixed by appending an `L` to the constant:

Code: [Select]
#ifdef __MSPOCC__
#define FLT_TRUE_MIN   1.40129846E-45
#define DBL_TRUE_MIN   4.9406564584124654E-324
#define LDBL_TRUE_MIN  4.9406564584124654E-324L   /* Added "L" suffix here */
#else /* !__MSPOCC__ */
#define FLT_TRUE_MIN   0x8p-152F
#define DBL_TRUE_MIN   0x8p-1077
#define LDBL_TRUE_MIN  0x8p-1077L   /* Added "L" suffix here */
#endif /* !__MSPOCC__ */

This (admittedly minor) bug causes this program:

Code: [Select]
#include <float.h>
#include <stdio.h>

int main(void) {
    printf("LDBL_TRUE_MIN = %Lg\n", LDBL_TRUE_MIN);
    return 0;
}

to produce this compile-time diagnostic:

Code: [Select]
warning #2234: Argument 2 to 'printf' does not match the format string; expected 'long double' but found 'double'.