형식-제네릭 수학

ISO C Standard 11(C11) 이상의 <tgmath.h> 경우 헤더는 포함 및 <complex.h>포함 <math.h> 외에도 매개 변수 형식에 따라 해당 수학 함수를 호출하는 매크로를 제공합니다.

C 런타임 라이브러리 수학 함수는 실제 및 복잡한 변형으로 제공됩니다. 각 변형은 인수의 형식에 따라 세 가지 floatdoublelong double버전으로 제공됩니다. C는 C++와 같은 오버로드를 지원하지 않으므로 각 변형의 이름은 다릅니다. 예를 들어 실제 부동 소수점 값의 절대값을 얻으려면 각각 전달 중인지 또는 값을 전달하는 doublelong doublefloat지에 따라 호출 fabsfabsffabsl 합니다. 복잡한 절대값을 얻으려면 하나 또는 각각 , 및 복합 값을 전달하는doublefloat지 여부에 따라 호출 cabslcabsfcabs합니다.long double 인수가 위의 멘션 형식과 일치하지 않으면 인수가 double인 것처럼 함수가 선택됩니다.

<tgmath.h> 에는 호출할 올바른 수학 함수의 선택을 간소화하는 매크로가 포함되어 있습니다. 매크로는 전달된 형식을 검사한 다음 올바른 함수를 호출합니다. 예를 들어 매크로는 sqrt 바인딩 sqrt(9.9f)sqrtf()되지만 에 바인딩됩니다.sqrt(9.9)sqrt() 제네릭 매개 변수에 대한 매크로 인수가 하나 이상 복잡한 경우 매크로는 복합 함수에 바인딩됩니다. 그렇지 않으면 실제 함수를 호출합니다.

형식 제네릭 매크로를 <tgmath.h> 사용하면 인수 유형에 따라 다른 함수 이름을 캐스팅하거나 선택할 필요가 없으므로 이식 가능한 코드를 더 많이 작성할 수 있습니다.

이러한 매크로는 자체 헤더에 있으므로 헤더를 사용하여 <math.h> 작성된 프로그램이 중단되지 않습니다. math.hdouble x = sin(42);>를 포함<할 때 항상 그처럼 동작합니다. 그럼에도 불구하고 대부분의 기존 C 프로그램은 헤더가 대신 <math.h> 포함<complex.h>되거나 포함되는 경우 <tgmath.h> 영향을 받지 않을 것으로 예상됩니다.

다음 표에서는 사용할 수 <tgmath.h> 있는 매크로와 확장되는 매크로를 나열합니다. modf 은 형식 확인을 복잡하게 만들지 않고 안전하게 만드는 방법을 명확하지 않기 때문에 해당 형식 제네릭 매크로가 없기 때문에 이 표에 포함되지 않습니다.

Macro 진짜
float
진짜
double
진짜
long double
복잡
float
복잡
double
복잡
long double
acos acosf acos acosl cacosf cacos cacosl
acosh acoshf acosh acoshl cacoshf cacosh cacoshl
asin asinf asin asinl casinf casin casinl
asinh asinhf asinh asinhl casinhf casinh casinhl
atan atanf atan atanl catanf catan catanl
atanh atanhf atanh atanhl catanhf catanh catanhl
cos cosf cos cosl ccosf ccos ccosl
cosh coshf cosh coshl ccoshf ccosh ccoshl
exp expf exp expl cexpf cexp cexpl
fabs fabsf fabs fabsl cabsf cabs cabsl
log logf log logl clogf clog clogl
pow powf pow powl cpowf cpow cpowl
sin sinf sin sinl csinf csin csinl
sinh sinhf sinh sinhl csinhf csinh csinhl
sqrt sqrtf sqrt sqrtl csqrtf csqrt csqrtl
tan tanf tan tanl ctanf ctan ctanl
tanh tanhf tanh tanhl ctanhf ctanh ctanhl
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 - - -
carg - - - cargf carg cargl
conj - - - conjf conj conjl
creal - - - crealf creal creall
cimag - - - cimagf cimag cimagl
cproj - - - cprojf cproj cprojl

요구 사항

/std:c11를 사용하여 컴파일합니다.

Windows SDK 10.0.20348.0(버전 2104) 이상. 최신 SDK를 다운로드하려면 Windows SDK를 참조하세요. C11 및 C17 개발을 위한 SDK를 설치하고 사용하기 위한 지침은 Visual Studio에 C11 및 C17 지원 설치를 참조하세요.

참고 항목

C 런타임 라이브러리 참조