Compartilhar via


Floating-Point Support

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Floating-Point Support.

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. 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.

Many of the floating point math library functions have different implementations for different CPU architectures. For example, the 32-bit x86 CRT may have a different implementation than the 64-bit x64 CRT. In addition, some of the functions may have multiple implementations for a given CPU architecture. The most efficient implementation is selected dynamically at run-time depending on the instruction sets supported by the CPU. For example, in the 32-bit x86 CRT, some functions have both an x87 implementation and an SSE2 implementation. When running on a CPU that supports SSE2, the faster SSE2 implementation is used. When running on a CPU that does not support SSE2, the slower x87 implementation is used. 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. In most cases, the results are within +/-1 ulp of the correctly rounded result, but the actual results may vary across CPUs.

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. 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. The compiler treats long double and double as distinct types, but the long double functions are identical to their double counterparts. 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.

The CRT supports these floating point functions:

abs, _abs64

acos, acosf, acosl

acosh, acoshf, acoshl

asin, asinf, asinl

asinh, asinhf, asinhl

atan, atanf, atanl, atan2, atan2f, atan2l

atanh, atanhf, atanhl

_atodbl, _atodbl_l

atof, _atof_l

_atoflt, _atoflt_l, _atoldbl, _atoldbl_l

cbrt, cbrtf, cbrtl

ceil, ceilf, ceill

_chgsign, _chgsignf, _chgsignl

_clear87, _clearfp

compl

conj, conjf, conjl

_control87, __control87_2, _controlfp

_controlfp_s

copysign, copysignf, copysignl, _copysign, _copysignf, _copysignl

cos, cosf, cosl

cosh, coshf, coshl

div

_ecvt

ecvt

_ecvt_s

erf, erff, erfl, erfc, erfcf, erfcl

exp, expf

exp2, exp2f, exp2l

expm1, expm1f, expm1l

fabs, fabsf

_fcvt

fcvt

_fcvt_s

fdim, fdimf, fdiml

feclearexcept

fegetenv

fegetexceptflag

fegetround

feholdexcept

feraiseexcept

ferror

fesetenv

fesetexceptflag

fesetround

fetestexcept

feupdateenv

_finite, _finitef

floor, floorf, floorl

fma, fmaf, fmal

fmax, fmaxf, fmaxl

fmin, fminf, fminl

fmod, fmodf

_fpclass, _fpclassf

fpclassify

_fpieee_flt

_fpreset

frexp

gcvt

_gcvt

_gcvt_s

hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl

ilogb, ilogbf, ilogbl

imaxabs

imaxdiv

isnan, _isnan, _isnanf

_j0, _j1, _jn

labs, llabs

ldexp

ldiv, lldiv

lgamma, lgammaf, lgammal

llrint, llrintf, llrintl

llround, llroundf, llroundl

log, logf, log10, log10f

log1p, log1pf, log1pl

log2, log2f, log2l

logb, logbf, logbl, _logb, _logbf

lrint, lrintf, lrintl

_lrotl, _lrotr

lround, lroundf, lroundl

_matherr

__max

__min

modf, modff

nan, nanf, nanl

nanf

nanl

nearbyint, nearbyintf, nearbyintl

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

norm, normf, norml

pow, powf, powl

remainder, remainderf, remainderl

remquo, remquof, remquol

rint, rintf, rintl

_rotl, _rotl64, _rotr, _rotr64

round, roundf, roundl

_scalb

scalbn, scalbnf, scalbnl, scalbln, scalblnf, scalblnl

_set_controlfp

_set_SSE2_enable

sin, sinf, sinl

sinh, sinhf, sinhl

sqrt, sqrtf, sqrtl

_status87, _statusfp, _statusfp2

strtof, _strtof_l

strtold, _strtold_l

tan, tanf, tanl

tanh, tanhf, tanhl

tgamma, tgammaf, tgammal

trunc, truncf, truncl

_wtof, _wtof_l

_y0, _y1, _yn

See Also

Run-Time Routines by Category