Type-generic math

来自cppreference.com

<tgmath.h>包括头<math.h><complex.h>,并定义了几种类型的通用宏。这些宏确定实际要调用的函数的参数的类型.
Original:
The header <tgmath.h> includes the headers <math.h> and <complex.h> and defines several type-generic macros. These macros determines the actual function to call depending on the types of the parameters.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 三角函数,双曲线,指数函数NJ

A型通用宏XXX调用
Original:
A type-generic macro XXX calls either of:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 真正的功能
    Original:
    real function:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • float变种XXXf
    Original:
    float variant XXXf
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • double变种XXX
    Original:
    double variant XXX
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • long double变种XXXl
    Original:
    long double variant XXXl
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 复杂的功能
    Original:
    complex function:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • float变种cXXXf
    Original:
    float variant cXXXf
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • double变种cXXX
    Original:
    double variant cXXX
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • long double变种cXXXl
    Original:
    long double variant cXXXl
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
上述规则的一个例外是exp(请参阅下表)
Original:
An exception to the above rule is exp (see the table below).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
调用的函数如下:
Original:
The function to call is determined as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 如果任何参数是复杂的,那么复杂的函数被调用,否则,真正的函数被调用.
    Original:
    If any of the parameters is complex, then the complex function is called, otherwise the real function is called.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 如果任何参数是long double,然后long double变种被调用。否则,如果任何参数是double,然后被称为double变种。否则,float的变体被称为.
    Original:
    If any of the parameters is long double, then the long double variant is called. Otherwise, if any of the parameters is double, then the double variant is called. Otherwise, float variant is called.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 的行为是未定义的参数与相应的函数的参数是不兼容的。
    Original:
    The behavior is undefined is any of the parameters is incompatible with the corresponding argument of the function.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
类型通用的宏如下:
Original:
The type-generic macros are as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Type-generic macro Real function
variants
Complex function
variants
 
float
double
long double
float
double
long double
asin asinf asin asinl casinf casin casinl
acos acosf acos acosl cacosf cacos cacosl
atan atanf atan atanl catanf catan catanl
asinh asinhf asinh asinhl casinhf casinh casinhl
acosh acoshf acosh acoshl cacoshf cacosh cacoshl
atanh atanhf atanh atanhl catanhf catanh catanhl
sin sinf sin sinl csinf csin csinl
cos cosf cos cosl ccosf ccos ccosl
tan tanf tan tanl ctanf ctan ctanl
sinh sinhf sinh sinhl csinhf csinh csinhl
cosh coshf cosh coshl ccoshf ccosh ccoshl
tanh tanhf tanh tanhl ctanhf ctanh ctanhl
exp expf exp expl cexpf cexp cexpl
log logf log logl clogf clog clogl
pow powf pow powl cpowf cpow cpowl
sqrt sqrtf sqrt sqrtl csqrtf csqrt csqrtl
abs fabsf fabs fabsl cabsf cabs cabsl
exp expf exp expl cexpf cexp cexpl

[编辑] 其它功能NJ

A型通用宏XXX的变种,一个真正的函数调用
Original:
A type-generic macro XXX calls either of the variants of a real function:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • float变种XXXf
    Original:
    float variant XXXf
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • double变种XXX
    Original:
    double variant XXX
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • long double变种XXXl
    Original:
    long double variant XXXl
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
请注意,有没有modf类型通用的宏.
Original:
Note, there's no modf type-generic macro.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
调用的函数如下:
Original:
The function to call is determined as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 如果任何参数是long double,然后long double变种被调用。否则,如果任何参数是double,然后被称为double变种。否则,float的变体被称为.
    Original:
    If any of the parameters is long double, then the long double variant is called. Otherwise, if any of the parameters is double, then the double variant is called. Otherwise, float variant is called.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 的行为是未定义的参数与相应的函数的参数是不兼容的。
    Original:
    The behavior is undefined is any of the parameters is incompatible with the corresponding argument of the function.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Type-generic macro Real function
variants
 
float
double
long double
atan2 atan2f atan2 atan2l
cbrt cbrtf cbrt cbrtl
ceil ceilf ceil ceill
copysign copysignf copysign copysignl
erf erff erf erfl
erfc erfcf erfc erfcl
exp2 exp2f exp2 exp2l
expm1 expm1f expm1 expm1l
fdim fdimf fdim fdiml
floor floorf floor floorl
fma fmaf fma fmal
fmax fmaxf fmax fmaxl
fmin fminf fmin fminl
fmod fmodf fmod fmodl
frexp frexpf frexp frexpl
hypot hypotf hypot hypotl
ilogb ilogbf ilogb ilogbl
ldexp ldexpf ldexp ldexpl
lgamma lgammaf lgamma lgammal
llrint llrintf llrint llrintl
llround llroundf llround llroundl
log10 log10f log10 log10l
log1p log1pf log1p log1pl
log2 log2f log2 log2l
logb logbf logb logbl
lrint lrintf lrint lrintl
lround lroundf lround lroundl
nearbyint nearbyintf nearbyint nearbyintl
nextafter nextafterf nextafter nextafterl
nexttoward nexttowardf nexttoward nexttowardl
remainder remainderf remainder remainderl
remquo remquof remquo remquol
rint rintf rint rintl
round roundf round roundl
scalbln scalblnf scalbln scalblnl
scalbn scalbnf scalbn scalbnl
tgamma tgammaf tgamma tgammal
trunc truncf trunc truncl

[编辑] 为例

int i;
float f;
double d;
long double ld;
float complex fc;
double complex dc;
long double complex ldc;
 
// macro -> function call
cos(i);   // -> cos(i)
sin(f);   // -> sinf(f)
acos(d);  // -> acos(d)
sqrt(dc); // -> csqrt(dc);