...but does'nt this break compatibility with existing projects ?
float sin(float x) { return sinf(x); }
double sin(double x) { return sin(x); } // how to call the "extern C" sin() ??
#define __MATHFUNC__(X, FLT, DBL, LDBL) \
((sizeof (X) == sizeof (double)) \
? ((__typeof__ (X)) (DBL) ((double)(X))) \
: ((sizeof (X) == sizeof (float)) \
? ((__typeof__ (X)) (FLT) ((float)(X))) \
: ((__typeof__ (X)) (LDBL) ((long double)(X)))))
#ifdef __cplusplus
extern "C" {
#endif
extern double sin (double);
extern float sinf (float);
extern long double sinl (long double);
extern double cos (double);
extern float cosf (float);
extern long double cosl (long double);
#ifdef __cplusplus
};
#endif
#define sin(X) __MATHFUNC__ (X, sinf, sin, sinl)
#define cos(X) __MATHFUNC__ (X, cosf, cos, cosl)
float flt_sin (float x)
{
return sin (x);
}
double dbl_sin (double x)
{
return sin (x);
}
long double ldbl_sin (long double x)
{
return sin (x);
}
I prefer that the behavior remain standard and tell people that if they want better performance, put a "f" after their floating point constants and math routines.