浮点支持Floating-Point Support

Microsoft C 运行时库 (CRT) 提供了许多浮点数学库函数,包括 ISO C99 所需的所有函数。The Microsoft C Runtime library (CRT) provides many floating point math library functions, including all of those required by ISO C99. 这些函数的实现是为了平衡性能与正确性。These functions are implemented to balance performance with correctness. 因为产生正确舍入的结果可能成本过高,这些函数旨在有效地生成接近正确舍入结果的近似结果。Because producing the correctly rounded result may be prohibitively expensive, these functions are designed to efficiently produce a close approximation to the correctly rounded result. 在大多数情况下,虽然可能存在误差较大的情况,但生成的结果在正确舍入结果的 + /-1 ulp 范围内。In most cases, the result produced is within +/-1 ulp of the correctly rounded result, though there may be cases where there is greater inaccuracy.

许多浮点数学库函数具有不同 CPU 体系结构的不同实现。Many of the floating point math library functions have different implementations for different CPU architectures. 例如,相比 64 位 x64 CRT,32 位 x86 CRT 可能具有不同的实现。For example, the 32-bit x86 CRT may have a different implementation than the 64-bit x64 CRT. 此外,某些函数可能有适用于给定 CPU 体系结构的多个实现。In addition, some of the functions may have multiple implementations for a given CPU architecture. 在运行时动态地选择最有效的实现,具体取决于受 CPU 支持的指令集。The most efficient implementation is selected dynamically at run-time depending on the instruction sets supported by the CPU. 例如,在 32 位 x86 CRT 中,一些函数同时具有 x87 实现和 SSE2 实现。For example, in the 32-bit x86 CRT, some functions have both an x87 implementation and an SSE2 implementation. 在支持 SSE2 的 CPU 上运行时,使用速度更快的 SSE2 实现。When running on a CPU that supports SSE2, the faster SSE2 implementation is used. 在不支持 SSE2 的 CPU 上运行时,使用速度较慢的 x87 实现。When running on a CPU that does not support SSE2, the slower x87 implementation is used. 数学库函数的不同实现可能会使用不同的 CPU 指令和不同的算法来生成其结果,因此,这些函数可能会在各 CPU 中产生不同的结果。Because different implementations of the math library functions may use different CPU instructions and different algorithms to produce their results, the functions may produce different results across CPUs. 在大多数情况下,结果在正确舍入结果的 +/-1 ulp 范围内,但实际结果在各 CPU 中可能会有所不同。In most cases, the results are within +/-1 ulp of the correctly rounded result, but the actual results may vary across CPUs.

以前的 16 位版本 Microsoft C/C ++ 和 Microsoft Visual C++ 支持 long double 类型作为 80 位精度浮点数据类型。Previous 16-bit versions of Microsoft C/C++ and Microsoft Visual C++ supported the long double type as an 80-bit precision floating-point data type. 在更高版本的 Visual C++ 中,long double 数据类型是与 double 类型相同的 64 位精度浮点数据类型。In later versions of Visual C++, the long double data type is a 64-bit precision floating-point data type identical to the double type. 编译器将 long doubledouble 归为不同类型,但 long double 函数等于其 double 对应项。The compiler treats long double and double as distinct types, but the long double functions are identical to their double counterparts. CRT 为 ISO C99 源代码兼容性提供了数学函数的 long double 版本,但请注意,二进制表示形式可能不同于其他编译器。The CRT provides long double versions of the math functions for ISO C99 source code compatibility, but note that the binary representation may differ from other compilers.

CRT 支持以下浮点函数:The CRT supports these floating point functions:

abs、labs、llabs、_abs64abs, labs, llabs, _abs64

acos、acosf、acoslacos, acosf, acosl

acosh、acoshf、acoshlacosh, acoshf, acoshl

asin、asinf、asinlasin, asinf, asinl

asinh、asinhf、asinhlasinh, asinhf, asinhl

atan、atanf、atanl、atan2、atan2f、atan2latan, atanf, atanl, atan2, atan2f, atan2l

atanh、atanhf、atanhlatanh, atanhf, atanhl

_atodbl、_atodbl_l_atodbl, _atodbl_l

atof、_atof_latof, _atof_l

_atoflt、_atoflt_l、_atoldbl、_atoldbl_l_atoflt, _atoflt_l, _atoldbl, _atoldbl_l

cbrt、cbrtf、cbrtlcbrt, cbrtf, cbrtl

ceil、ceilf、ceillceil, ceilf, ceill

_chgsign、_chgsignf、_chgsignl_chgsign, _chgsignf, _chgsignl

_clear87、_clearfp_clear87, _clearfp

complcompl

conj、conjf、conjlconj, conjf, conjl

_control87、__control87_2、_controlfp_control87, __control87_2, _controlfp

_controlfp_s_controlfp_s

copysign、copysignf、copysignl、_copysign、_copysignf、_copysignlcopysign, copysignf, copysignl, _copysign, _copysignf, _copysignl

cos、cosf、coslcos, cosf, cosl

cosh、coshf、coshlcosh, coshf, coshl

divdiv

_ecvt_ecvt

ecvtecvt

_ecvt_s_ecvt_s

erf、erff、erfl、erfc、erfcf、erfclerf, erff, erfl, erfc, erfcf, erfcl

exp、expf、explexp, expf, expl

exp2、exp2f、exp2lexp2, exp2f, exp2l

expm1、expm1f、expm1lexpm1, expm1f, expm1l

fabs、fabsffabs, fabsf

_fcvt_fcvt

fcvtfcvt

_fcvt_s_fcvt_s

fdim、fdimf、fdimlfdim, fdimf, fdiml

feclearexceptfeclearexcept

fegetenvfegetenv

fegetexceptflagfegetexceptflag

fegetroundfegetround

feholdexceptfeholdexcept

feraiseexceptferaiseexcept

ferrorferror

fesetenvfesetenv

fesetexceptflagfesetexceptflag

fesetroundfesetround

fetestexceptfetestexcept

feupdateenvfeupdateenv

_finite、_finitef_finite, _finitef

floor、floorf、floorlfloor, floorf, floorl

fma、fmaf、fmalfma, fmaf, fmal

fmax、fmaxf、fmaxlfmax, fmaxf, fmaxl

fmin、fminf、fminlfmin, fminf, fminl

fmod、fmodffmod, fmodf

_fpclass、_fpclassf_fpclass, _fpclassf

fpclassifyfpclassify

_fpieee_flt_fpieee_flt

_fpreset_fpreset

frexpfrexp

gcvtgcvt

_gcvt_gcvt

_gcvt_s_gcvt_s

_get_FMA3_enable、_set_FMA3_enable_get_FMA3_enable, _set_FMA3_enable

hypot、hypotf、hypotl、_hypot、_hypotf、_hypotlhypot, hypotf, hypotl, _hypot, _hypotf, _hypotl

ilogb、ilogbf、ilogblilogb, ilogbf, ilogbl

imaxabsimaxabs

imaxdivimaxdiv

isnan、_isnan、_isnanfisnan, _isnan, _isnanf

_j0、_j1、_jn_j0, _j1, _jn

ldexpldexp

ldiv、lldivldiv, lldiv

lgamma、lgammaf、lgammallgamma, lgammaf, lgammal

llrint、llrintf、llrintlllrint, llrintf, llrintl

llround、llroundf、llroundlllround, llroundf, llroundl

log、logf、log10、log10flog, logf, log10, log10f

log1p、log1pf、log1pllog1p, log1pf, log1pl

log2、log2f、log2llog2, log2f, log2l

logb、logbf、logbl、_logb、_logbflogb, logbf, logbl, _logb, _logbf

lrint、lrintf、lrintllrint, lrintf, lrintl

_lrotl、_lrotr_lrotl, _lrotr

lround、lroundf、lroundllround, lroundf, lroundl

_matherr_matherr

__max__max

__min__min

modf、modffmodf, modff

nan、nanf、nanlnan, nanf, nanl

nanfnanf

nanlnanl

nearbyint、nearbyintf、nearbyintlnearbyint, nearbyintf, nearbyintl

nextafter、nextafterf、nextafterl、_nextafter、_nextafterf、nexttoward、nexttowardf、nexttowardlnextafter, nextafterf, nextafterl, _nextafter, _nextafterf, nexttoward, nexttowardf, nexttowardl

norm、normf、normlnorm, normf, norml

pow、powf、powlpow, powf, powl

remainder、remainderf、remainderlremainder, remainderf, remainderl

remquo、remquof、remquolremquo, remquof, remquol

rint、rintf、rintlrint, rintf, rintl

_rotl、_rotl64、_rotr、_rotr64_rotl, _rotl64, _rotr, _rotr64

round、roundf、roundlround, roundf, roundl

_scalb_scalb

scalbn、scalbnf、scalbnl、scalbln、scalblnf、scalblnlscalbn, scalbnf, scalbnl, scalbln, scalblnf, scalblnl

_set_controlfp_set_controlfp

_set_SSE2_enable_set_SSE2_enable

sin、sinf、sinlsin, sinf, sinl

sinh、sinhf、sinhlsinh, sinhf, sinhl

sqrt、sqrtf、sqrtlsqrt, sqrtf, sqrtl

_status87、_statusfp、_statusfp2_status87, _statusfp, _statusfp2

strtof、_strtof_lstrtof, _strtof_l

strtold、_strtold_lstrtold, _strtold_l

tan、tanf、tanltan, tanf, tanl

tanh、tanhf、tanhltanh, tanhf, tanhl

tgamma、tgammaf、tgammaltgamma, tgammaf, tgammal

trunc、truncf、truncltrunc, truncf, truncl

_wtof、_wtof_l_wtof, _wtof_l

_y0、_y1、_yn_y0, _y1, _yn

请参阅See Also

按类别分的运行时例程Run-Time Routines by Category