Hello:

I suppose all of you in this list are also in the cfe-dev list, so you probably 
know about this. Given that I defined auxiliary macros an then used them all 
throughout the file, a diffs listing would be pointless, virtually everything 
has changed. Therefore, I also send the corresponding preprocessed files for 
both the old and the new one, just in case someone wants to compare them.

The file I send here is the same I sent a few days ago to the cfe-dev list but 
for the correction of a silly-obvious mistake and the splitting of some long 
lines, following the llvm programming style guide.

For those of you who will be reviewing my changes, here is an explanation:

1st. Guard against libraries not supporting complex types:

#if defined(__STDC_NO_COMPLEX__) || !__has_include_next(<complex.h>)
#define _TG_NO_COMPLEX
#endif

And if you search for _TG_NO_COMPLEX you wil find where it is needed. The uses 
are self-explanatory.


2nd. Helper macros for defining the functions. These are the definitions from

// Macros for defining the functions

till

// End of macros for defining the functions

And then come the function definitions. Where the old file had, for instance,

static float
    _TG_ATTRS
    __tg_fabs(float __x) {return fabsf(__x);}

static double
    _TG_ATTRS
    __tg_fabs(double __x) {return fabs(__x);}

static long double
    _TG_ATTRS
    __tg_fabs(long double __x) {return fabsl(__x);}

I have

__define_function_real(fabs)

And the whole file is like that, so you see how useless a diffs report would be.

Regards
/*===---- tgmath.h - Standard header for type generic math ----------------===*\
 *
 * Copyright (c) 2009 Howard Hinnant
 * Modified in 2015 by the Clang development comunity
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
\*===----------------------------------------------------------------------===*/

#ifndef __TGMATH_H
#define __TGMATH_H

/* C99 7.22 Type-generic math <tgmath.h>. */
#include <math.h>
/* C++ handles type genericity with overloading in math.h. */
#ifndef __cplusplus

#if defined(__STDC_NO_COMPLEX__) || !__has_include_next(<complex.h>)
#define _TG_NO_COMPLEX
#endif

#ifndef _TG_NO_COMPLEX
        #include <complex.h>
#endif

#define _TG_ATTRS __attribute__((__overloadable__, __always_inline__))

// Promotion facilities
#define _TG_ATTRSp __attribute__((__overloadable__))

typedef void _Argument_type_is_not_arithmetic;
static _Argument_type_is_not_arithmetic __tg_promote(...)
  __attribute__((__unavailable__,__overloadable__));
static double               _TG_ATTRSp __tg_promote(int);
static double               _TG_ATTRSp __tg_promote(unsigned int);
static double               _TG_ATTRSp __tg_promote(long);
static double               _TG_ATTRSp __tg_promote(unsigned long);
static double               _TG_ATTRSp __tg_promote(long long);
static double               _TG_ATTRSp __tg_promote(unsigned long long);
static float                _TG_ATTRSp __tg_promote(float);
static double               _TG_ATTRSp __tg_promote(double);
static long double          _TG_ATTRSp __tg_promote(long double);
#ifndef _TG_NO_COMPLEX
static float _Complex       _TG_ATTRSp __tg_promote(float _Complex);
static double _Complex      _TG_ATTRSp __tg_promote(double _Complex);
static long double _Complex _TG_ATTRSp __tg_promote(long double _Complex);
#endif

#define __tg_promote1(__x)           (__typeof__(__tg_promote(__x)))
#define __tg_promote2(__x, __y)      (__typeof__(__tg_promote(__x) + \
                                                 __tg_promote(__y)))
#define __tg_promote3(__x, __y, __z) (__typeof__(__tg_promote(__x) + \
                                                 __tg_promote(__y) + \
                                                 __tg_promote(__z)))

#undef  _TG_ATTRSp
// End of promotion facilities


// Macros for defining the functions

#define _TG_func(rettype, func) static rettype _TG_ATTRS __tg_##func

//There are enough real functions that return int or long
//that make this is worth defining
#define __define_function_rettype_real(rettype,func) \
        _TG_func(rettype, func)(float __x) { return func##f(__x); } \
        _TG_func(rettype, func)(double __x) { return func(__x); } \
        _TG_func(rettype, func)(long double __x) { return func##l(__x); }

#define __define_function_real(func) \
        _TG_func(float, func)(float __x) { return func##f(__x); } \
        _TG_func(double, func)(double __x) { return func(__x); } \
        _TG_func(long double, func)(long double __x) { return func##l(__x); }

#define __define_function2_real(func) \
        _TG_func(float, func)(float __x, float __y) { return func##f(__x,__y); 
} \
        _TG_func(double, func)(double __x, double __y) { return func(__x,__y); 
} \
        _TG_func(long double, func)(long double __x, long double __y) \
                { return func##l(__x,__y); }

/* used only once */
#define __define_function3_real(func) \
        _TG_func(float, func)(float __x, float __y, float __z) \
                        { return func##f(__x,__y,__z); } \
        _TG_func(double, func)(double __x, double __y, double __z) 
                        { return func(__x,__y,__z); } \
        _TG_func(long double, func)(long double __x, long double __y, long 
double __z)\
                        { return func##l(__x,__y,__z); }

#ifndef _TG_NO_COMPLEX
#define __define_function_complex(func) \
        _TG_func(float _Complex, func)(float _Complex __x) { return 
c##func##f(__x); }\
        _TG_func(double _Complex, func)(double _Complex __x) { return 
c##func(__x); } \
        _TG_func(long double _Complex, func)(long double _Complex __x) \
                        { return c##func##l(__x); }

/* A function taking a complex argument and returning a real one */
#define __define_function_real_complex(func) \
        _TG_func(float, func)(float _Complex __x) { return c##func##f(__x); } \
        _TG_func(double, func)(double _Complex __x) { return c##func(__x); } \
        _TG_func(long double, func)(long double _Complex __x) \
                        { return c##func##l(__x); }

/* used only once */
#define __define_function2_complex(func) \
          _TG_func(float _Complex, func)(float _Complex __x, float _Complex 
__y) \
                        { return c##func##f(__x,__y); } \
          _TG_func(double _Complex, func)(double _Complex __x, double _Complex 
__y) \
                        { return c##func(__x,__y); } \
          _TG_func(long double _Complex, func)(long double _Complex __x, \
                        long double _Complex __y) \
                        { return c##func##l(__x,__y); }
  
#else
#define __define_function_complex(func)
#define __define_function2_complex(func)
#define __define_function_real_complex(func)
#endif


#define __define_function(func) \
                __define_function_real(func) \
                __define_function_complex(func)

/* It would be ideal to include the

#undef func
#define func(__x) __tg_##func(__tg_promote1((__x))(__x))

in the above macros, but the C preprocessor does not allow
macros that define other macros */

// End of macros for defining the functions



// Functions that take one argument, real or complex:

__define_function(acos)
__define_function(asin)
__define_function(atan)
__define_function(acosh)
__define_function(asinh)
__define_function(atanh)
__define_function(cos)
__define_function(sin)
__define_function(tan)
__define_function(cosh)
__define_function(sinh)
__define_function(tanh)
__define_function(exp)
__define_function(log)
__define_function(sqrt)
__define_function_real(fabs)
__define_function_real_complex(abs)

#undef acos
#define acos(__x) __tg_acos(__tg_promote1((__x))(__x))
#undef asin
#define asin(__x) __tg_asin(__tg_promote1((__x))(__x))
#undef atan
#define atan(__x) __tg_atan(__tg_promote1((__x))(__x))
#undef acosh
#define acosh(__x) __tg_acosh(__tg_promote1((__x))(__x))
#undef asinh
#define asinh(__x) __tg_asinh(__tg_promote1((__x))(__x))
#undef atanh
#define atanh(__x) __tg_atanh(__tg_promote1((__x))(__x))
#undef cos
#define cos(__x) __tg_cos(__tg_promote1((__x))(__x))
#undef sin
#define sin(__x) __tg_sin(__tg_promote1((__x))(__x))
#undef tan
#define tan(__x) __tg_tan(__tg_promote1((__x))(__x))
#undef cosh
#define cosh(__x) __tg_cosh(__tg_promote1((__x))(__x))
#undef sinh
#define sinh(__x) __tg_sinh(__tg_promote1((__x))(__x))
#undef tanh
#define tanh(__x) __tg_tanh(__tg_promote1((__x))(__x))
#undef exp
#define exp(__x) __tg_exp(__tg_promote1((__x))(__x))
#undef log
#define log(__x) __tg_log(__tg_promote1((__x))(__x))
#undef sqrt
#define sqrt(__x) __tg_sqrt(__tg_promote1((__x))(__x))
#undef fabs
#define fabs(__x) __tg_fabs(__tg_promote1((__x))(__x))

// The only more-than-one-argument function that may take real or complex
// agruments. This is also the only complex function that takes more than
// one argument

// pow
__define_function2_real(pow)
__define_function2_complex(pow)
#undef pow
#define pow(__x, __y) __tg_pow(__tg_promote2((__x), (__y))(__x), \
                               __tg_promote2((__x), (__y))(__y))


// Real only functions:

__define_function2_real(atan2)
__define_function_real(cbrt)
__define_function_real(ceil)
__define_function2_real(copysign)
__define_function_real(erf)
__define_function_real(erfc)
__define_function_real(exp2)
__define_function_real(expm1)
__define_function2_real(fdim)
__define_function_real(floor)
__define_function3_real(fma)
__define_function2_real(fmax)
__define_function2_real(fmin)
__define_function2_real(fmod)
__define_function2_real(hypot)
__define_function_rettype_real(int, ilogb)
__define_function_real(lgamma)
__define_function_rettype_real(long long, llrint)
__define_function_rettype_real(long long, llround)
__define_function_real(log10)
__define_function_real(log1p)
__define_function_real(log2)
__define_function_real(logb)
__define_function_rettype_real(long, lrint)
__define_function_rettype_real(long, lround)
__define_function_real(nearbyint)
__define_function2_real(nextafter)
__define_function2_real(reminder)
__define_function_real(rint)
__define_function_real(round)
__define_function_real(tgamma)
__define_function_real(trunc)

// Functions that do not follow the above regular pattern

// frexp
_TG_func(float,frexp)(float __x, int* __y) {return frexpf(__x, __y);}
_TG_func(double,frexp)(double __x, int* __y) {return frexp(__x, __y);}
_TG_func(long double,frexp)(long double __x, int* __y) {return frexpl(__x, 
__y);}

// ldexp
_TG_func(float,ldexp)(float __x, int __y) {return ldexpf(__x, __y);}
_TG_func(double,ldexp)(double __x, int __y) {return ldexp(__x, __y);}
_TG_func(long double,ldexp)(long double __x, int __y) {return ldexpl(__x, __y);}

// nexttoward
_TG_func(float,nexttoward)(float __x, long double __y) \
        {return nexttowardf(__x, __y);}
_TG_func(double,nexttoward)(double __x, long double __y) \
        {return nexttoward(__x, __y);}
_TG_func(long double,nexttoward)(long double __x, long double __y) \
        {return nexttowardl(__x, __y);}

// remquo
_TG_func(float,remqo)(float __x, float __y, int* __z) \
        {return remquof(__x, __y, __z);}
_TG_func(double,remqo)(double __x, double __y, int* __z) \
        {return remquo(__x, __y, __z);}
_TG_func(long double,remqo)(long double __x,long double __y, int* __z) \
        {return remquol(__x, __y, __z);}

// scalbn
_TG_func(float,scalbn)(float __x, int __y) {return scalbnf(__x, __y);}
_TG_func(double,scalbn)(double __x, int __y) {return scalbn(__x, __y);}
_TG_func(long double,scalbn)(long double __x, int __y) \
        {return scalbnl(__x, __y);}

// scalbln
_TG_func(float,scalbln)(float __x, long __y) {return scalblnf(__x, __y);}
_TG_func(double,scalbln)(double __x, long __y) {return scalbln(__x, __y);}
_TG_func(long double,scalbln)(long double __x, long __y) \
        {return scalblnl(__x, __y);}


#undef atan2
#define atan2(__x, __y) __tg_atan2(__tg_promote2((__x), (__y))(__x), \
                                   __tg_promote2((__x), (__y))(__y))
#undef cbrt
#define cbrt(__x) __tg_cbrt(__tg_promote1((__x))(__x))
#undef ceil
#define ceil(__x) __tg_ceil(__tg_promote1((__x))(__x))
#undef copysign
#define copysign(__x, __y) __tg_copysign(__tg_promote2((__x), (__y))(__x), \
                                         __tg_promote2((__x), (__y))(__y))
#undef erf
#define erf(__x) __tg_erf(__tg_promote1((__x))(__x))
#undef erfc
#define erfc(__x) __tg_erfc(__tg_promote1((__x))(__x))
#undef exp2
#define exp2(__x) __tg_exp2(__tg_promote1((__x))(__x))
#undef expm1
#define expm1(__x) __tg_expm1(__tg_promote1((__x))(__x))
#undef fdim
#define fdim(__x, __y) __tg_fdim(__tg_promote2((__x), (__y))(__x), \
                                 __tg_promote2((__x), (__y))(__y))
#undef floor
#define floor(__x) __tg_floor(__tg_promote1((__x))(__x))
#undef fma
#define fma(__x, __y, __z)                                \
        __tg_fma(__tg_promote3((__x), (__y), (__z))(__x), \
                 __tg_promote3((__x), (__y), (__z))(__y), \
                 __tg_promote3((__x), (__y), (__z))(__z))
#undef fmax
#define fmax(__x, __y) __tg_fmax(__tg_promote2((__x), (__y))(__x), \
                                 __tg_promote2((__x), (__y))(__y))
#undef fmin
#define fmin(__x, __y) __tg_fmin(__tg_promote2((__x), (__y))(__x), \
                                 __tg_promote2((__x), (__y))(__y))
#undef fmod
#define fmod(__x, __y) __tg_fmod(__tg_promote2((__x), (__y))(__x), \
                                 __tg_promote2((__x), (__y))(__y))
#undef frexp
#define frexp(__x, __y) __tg_frexp(__tg_promote1((__x))(__x), __y)
#undef hypot
#define hypot(__x, __y) __tg_hypot(__tg_promote2((__x), (__y))(__x), \
                                   __tg_promote2((__x), (__y))(__y))
#undef ilogb
#define ilogb(__x) __tg_ilogb(__tg_promote1((__x))(__x))
#undef ldexp
#define ldexp(__x, __y) __tg_ldexp(__tg_promote1((__x))(__x), __y)
#undef lgamma
#define lgamma(__x) __tg_lgamma(__tg_promote1((__x))(__x))
#undef llrint
#define llrint(__x) __tg_llrint(__tg_promote1((__x))(__x))
#undef llround
#define llround(__x) __tg_llround(__tg_promote1((__x))(__x))
#undef log10
#define log10(__x) __tg_log10(__tg_promote1((__x))(__x))
#undef log1p
#define log1p(__x) __tg_log1p(__tg_promote1((__x))(__x))
#undef log2
#define log2(__x) __tg_log2(__tg_promote1((__x))(__x))
#undef logb
#define logb(__x) __tg_logb(__tg_promote1((__x))(__x))
#undef lrint
#define lrint(__x) __tg_lrint(__tg_promote1((__x))(__x))
#undef lround
#define lround(__x) __tg_lround(__tg_promote1((__x))(__x))
#undef nearbyint
#define nearbyint(__x) __tg_nearbyint(__tg_promote1((__x))(__x))
#undef nextafter
#define nextafter(__x, __y) __tg_nextafter(__tg_promote2((__x), (__y))(__x), \
                                           __tg_promote2((__x), (__y))(__y))
#undef nexttoward
#define nexttoward(__x, __y) __tg_nexttoward(__tg_promote1((__x))(__x), (__y))
#undef remainder
#define remainder(__x, __y) __tg_remainder(__tg_promote2((__x), (__y))(__x), \
                                           __tg_promote2((__x), (__y))(__y))
#undef rint
#define rint(__x) __tg_rint(__tg_promote1((__x))(__x))
#undef round
#define round(__x) __tg_round(__tg_promote1((__x))(__x))
#undef remquo
#define remquo(__x, __y, __z)                         \
        __tg_remquo(__tg_promote2((__x), (__y))(__x), \
                    __tg_promote2((__x), (__y))(__y), \
                    (__z))
#undef scalbn
#define scalbn(__x, __y) __tg_scalbn(__tg_promote1((__x))(__x), __y)
#undef scalbln
#define scalbln(__x, __y) __tg_scalbln(__tg_promote1((__x))(__x), __y)
#undef tgamma
#define tgamma(__x) __tg_tgamma(__tg_promote1((__x))(__x))
#undef trunc
#define trunc(__x) __tg_trunc(__tg_promote1((__x))(__x))

/* Functions for complex argument. These can also take a real argument,
        in which case the imaginary part is presumed to be zero. The solution
        for these cases is usually trivial and depends on the particual 
function;
        hence, it cannot be systemized in a macro. */

#ifndef _TG_NO_COMPLEX
// carg
_TG_func(float,carg)(float __x) {return atan2f(0.F, __x);}
_TG_func(double,carg)(double __x) {return atan2(0., __x);}
_TG_func(long double,carg)(long double __x) {return atan2l(0.L, __x);}
__define_function_real_complex(arg)

// cimag
_TG_func(float,cimag)(float __x) {return 0;}
_TG_func(double,cimag)(double __x) {return 0;}
_TG_func(long double,cimag)(long double __x) {return 0;}
__define_function_real_complex(imag)

// conj
_TG_func(float _Complex, conj)(float __x) {return __x;}
_TG_func(double _Complex, conj)(double __x) {return __x;}
_TG_func(long double _Complex, conj)(long double __x) {return __x;}
__define_function_complex(onj)

// cproj
_TG_func(float _Complex, cproj)(float __x) {return cprojf(__x);}
_TG_func(double _Complex, cproj)(double __x) {return cproj(__x);}
_TG_func(long double _Complex, cproj)(long double __x) {return cprojl(__x);}
__define_function_complex(proj)

// creal
_TG_func(float,creal)(float __x) {return __x;}
_TG_func(double,creal)(double __x) {return __x;}
_TG_func(long double,creal)(long double __x) {return __x;}
__define_function_real_complex(real)

#undef carg
#define carg(__x) __tg_carg(__tg_promote1((__x))(__x))
#undef cimag
#define cimag(__x) __tg_cimag(__tg_promote1((__x))(__x))
#undef conj
#define conj(__x) __tg_conj(__tg_promote1((__x))(__x))
#undef cproj
#define cproj(__x) __tg_cproj(__tg_promote1((__x))(__x))
#undef creal
#define creal(__x) __tg_creal(__tg_promote1((__x))(__x))
#endif

#undef define_function_rettype_real
#undef define_function_real
#undef define_function_complex
#undef define_function_real_complex
#undef define_function2_real
#undef define_function2_complex
#undef define_function3_real
#undef define_function

#undef _TG_func
#undef _TG_ATTRS

#endif /* __cplusplus */
#endif /* __TGMATH_H */
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to