X-Git-Url: http://nsz.repo.hu/git/?p=libm;a=blobdiff_plain;f=include%2Ftgmath.h;h=6926d0f4a8503dbcbda821a0f3cf5ca69617cb04;hp=08e2028632f4e1399ba81f09d98998d225f2a3df;hb=ae446c7aae62c294a202e0d9ab3b48e4c2cdd6e4;hpb=9d90c60b78b00bc1576ab97648ce3aa0ccd16a9f diff --git a/include/tgmath.h b/include/tgmath.h index 08e2028..6926d0f 100644 --- a/include/tgmath.h +++ b/include/tgmath.h @@ -2,72 +2,79 @@ #define _TGMATH_H /* -tgmath.h is broken: return type is wrong -(always the highest conversion rank type: long double [complex]) +tgmath.h is broken: +with __GNUC__ the return type is wrong when all arguments are float [complex] +without __GNUC__ the return type is always long double [complex] (imaginary type is not supported) */ #include #include +#ifdef __GNUC__ +#define __RETCAST(x) (__typeof__((x))) +#else +#define __RETCAST(x) +#endif + #define __IS_FP(x) !!((1?1:(x))/2) -#define __IS_CX(x) (__IS_FP(x) && sizeof((x)) == sizeof((x)+I)) -#define __IS_REAL(x) (__IS_FP(x) && 2*sizeof((x)) == sizeof((x)+I)) - -#define __FLT(x) (__IS_REAL((x)) && sizeof((x)) == sizeof(float)) -#define __LDBL(x) (__IS_REAL((x)) && sizeof((x)) == sizeof(long double)) - -#define __FLTCX(x) (__IS_CX(x) && sizeof((x)) == sizeof(float complex)) -#define __DBLCX(x) (__IS_CX(x) && sizeof((x)) == sizeof(double complex)) -#define __LDBLCX(x) (__IS_CX(x) && sizeof((x)) == sizeof(long double complex)) - -#define __tg_real(__fun, x) ( \ - __FLT(x) ? __fun ## f (x) : \ - __LDBL(x) ? __fun ## l (x) : \ - __fun(x) ) - -#define __tg_real_2_1(__fun, x, y) ( \ - __FLT(x) ? __fun ## f (x, y) : \ - __LDBL(x) ? __fun ## l (x, y) : \ - __fun(x, y) ) - -#define __tg_real_2(__fun, x, y) ( \ - __FLT(x) && __FLT(y) ? __fun ## f (x, y) : \ - __LDBL(x) || __LDBL(y) ? __fun ## l (x, y) : \ - __fun(x, y) ) - -#define __tg_complex(__fun, x) ( \ - __FLTCX(x) || __FLT(x) ? __fun ## f (x) : \ - __LDBLCX(x) || __LDBL(x) ? __fun ## l (x) : \ - __fun(x) ) - -#define __tg_real_complex(__fun, x) ( \ - __LDBLCX(x) ? c ## __fun ## l (x) : \ - __DBLCX(x) ? c ## __fun (x) : \ - __FLTCX(x) ? c ## __fun ## f (x) : \ - __FLT(x) ? __fun ## f (x) : \ - __LDBL(x) ? __fun ## l (x) : \ - __fun(x) ) +#define __IS_CX(x) (__IS_FP(x) && sizeof(x) == sizeof((x)+I)) +#define __IS_REAL(x) (__IS_FP(x) && 2*sizeof(x) == sizeof((x)+I)) + +#define __FLT(x) (__IS_REAL(x) && sizeof(x) == sizeof(float)) +#define __LDBL(x) (__IS_REAL(x) && sizeof(x) == sizeof(long double)) + +#define __FLTCX(x) (__IS_CX(x) && sizeof(x) == sizeof(float complex)) +#define __DBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(double complex)) +#define __LDBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(long double complex)) + +#define __tg_real(fun, x) __RETCAST((x)+1.0)( \ + __FLT(x) ? fun ## f (x) : \ + __LDBL(x) ? fun ## l (x) : \ + fun(x) ) + +#define __tg_real_2_1(fun, x, y) __RETCAST((x)+1.0)( \ + __FLT(x) ? fun ## f (x, y) : \ + __LDBL(x) ? fun ## l (x, y) : \ + fun(x, y) ) + +#define __tg_real_2(fun, x, y) __RETCAST((x)+(y)+1.0)( \ + __FLT(x) && __FLT(y) ? fun ## f (x, y) : \ + __LDBL(x) || __LDBL(y) ? fun ## l (x, y) : \ + fun(x, y) ) + +#define __tg_complex(fun, x) __RETCAST((x)+1.0+I)( \ + __FLTCX(x) || __FLT(x) ? fun ## f (x) : \ + __LDBLCX(x) || __LDBL(x) ? fun ## l (x) : \ + fun(x) ) + +#define __tg_real_complex(fun, x) __RETCAST((x)+1.0)( \ + __LDBLCX(x) ? c ## fun ## l (x) : \ + __DBLCX(x) ? c ## fun (x) : \ + __FLTCX(x) ? c ## fun ## f (x) : \ + __FLT(x) ? fun ## f (x) : \ + __LDBL(x) ? fun ## l (x) : \ + fun(x) ) /* special cases */ -#define __tg_real_remquo(x, y, z) ( \ +#define __tg_real_remquo(x, y, z) __RETCAST((x)+(y)+1.0)( \ __FLT(x) && __FLT(y) ? remquof(x, y, z) : \ __LDBL(x) || __LDBL(y) ? remquol(x, y, z) : \ remquo(x, y, z) ) -#define __tg_real_fma(x, y, z) ( \ +#define __tg_real_fma(x, y, z) __RETCAST((x)+(y)+(z)+1.0)( \ __FLT(x) && __FLT(y) && __FLT(z) ? fmaf(x, y, z) : \ __LDBL(x) || __LDBL(y) || __LDBL(z) ? fmal(x, y, z) : \ fma(x, y, z) ) -#define __tg_real_complex_pow(x, y) ( \ +#define __tg_real_complex_pow(x, y) __RETCAST((x)+(y)+1.0)( \ __LDBLCX(x) || __LDBLCX(y) ? cpowl(x, y) : \ __DBLCX(x) || __DBLCX(y) ? cpow(x, y) : \ __FLTCX(x) || __FLTCX(y) ? cpowf(x, y) : \ __tg_real_2(pow, x, y) ) -#define __tg_real_complex_fabs(__fun, x) ( \ +#define __tg_real_complex_fabs(x) __RETCAST((x)+1.0)( \ __LDBLCX(x) ? cabsl(x) : \ __DBLCX(x) ? cabs(x) : \ __FLTCX(x) ? cabsf(x) : \ @@ -80,7 +87,7 @@ tgmath.h is broken: return type is wrong #define asin(x) __tg_real_complex(asin, (x)) #define asinh(x) __tg_real_complex(asinh, (x)) #define atan(x) __tg_real_complex(atan, (x)) -#define atan2(x) __tg_real_2(atan2, (x), (y)) +#define atan2(x,y) __tg_real_2(atan2, (x), (y)) #define atanh(x) __tg_real_complex(atanh, (x)) #define carg(x) __tg_complex(carg, (x)) #define cbrt(x) __tg_real(cbrt, (x)) @@ -98,7 +105,7 @@ tgmath.h is broken: return type is wrong #define exp2(x) __tg_real(exp2, (x)) #define expm1(x) __tg_real(expm1, (x)) #define fabs(x) __tg_real_complex_fabs(x) -#define fdim(x) __tg_real(fdim, (x)) +#define fdim(x,y) __tg_real_2(fdim, (x), (y)) #define floor(x) __tg_real(floor, (x)) #define fma(x,y,z) __tg_real_fma((x), (y), (z)) #define fmax(x,y) __tg_real_2(fmax, (x), (y))