math.h float_t and double_t not typedef'ed when FLT_EVAL_METHOD defined

Jordy Potman
Sat Nov 17 05:33:00 GMT 2012


I am using Newlib with a clang based compiler for our architecture.

I think I have found an issue in Newlib's math.h.

Newlib's math.h does not typedef float_t and double_t when
FLT_EVAL_METHOD is defined.

math.h lines 143-147:
143: #ifndef FLT_EVAL_METHOD
144: #define FLT_EVAL_METHOD 0
145: typedef float float_t;
146: typedef double double_t;
147: #endif /* FLT_EVAL_METHOD */

Clang's float.h defines FLT_EVAL_METHOD (I think gcc's float.h does as
well), which I think is correct according to section paragraph
8 of the C99 standard.

Newlib's math.h defines the log2f function as a macro which uses

math.h lines 354-357:
354: extern float log2f _PARAMS((float));
355: #if !defined(__cplusplus)
356: #define log2f(x) (logf (x) / (float_t) _M_LN2)
357: #endif

This causes a compilation error if a program includes float.h before
math.h and uses the log2f function:
$ cat log2f_test.c 
#include <float.h>
#include <math.h>

float f(float a) {
  return log2f(a);
$ xentium-clang -std=c99 -c log2f_test.c
log2f_test.c:5:10: error: use of undeclared identifier 'float_t'; did
you mean 'float'?
  return log2f(a);
/home/potman/opt/xentium-tools-1.0.beta9-linux64/bin/../sysroots/default/include/math.h:359:31: note: expanded from
      macro 'log2f'
#define log2f(x) (logf (x) / (float_t) _M_LN2)
1 error generated.

I have changed math.h lines 354-357 to the following in our

#endif /* FLT_EVAL_METHOD */
typedef double float_t;
typedef double double_t;
#elif FLT_EVAL_METHOD == 2
typedef long double float_t;
typedef long double double_t;
typedef float float_t;
typedef double double_t;

This is my interpretation of how float_t and double_t should be
typedef'ed depending on the value of FLT_EVAL_METHOD as is described in
section 7.12 paragraph 2 of the C99 standard. However I am not a C99
standard expert.


More information about the Newlib mailing list