Funciones matemáticas comunes

De cppreference.com
< cpp
Saltar a: navegación, buscar


Las siguientes funciones matemáticas son heredadas de C y provistas por el estándar C++. La mayoría de ellas se encuentra disponible por medio de la cabecera <cmath>.

Contenido

[editar] Funciones

[editar] Operaciones Básicas

Función Propósito
abs, labs, llabs Recupera el eswiki:valor absoluto de un valor integral. Función sobrecargada.
abs, fabs Recupera el valor absoluto de un valor en punto flotante. Función sobrecargada.
div, ldiv Recupera el cuociente y resto de una división. Función sobrecargada.
fmod Recupera el resto de una división en punto flotante.
remainder Recupera el resto con signo de una división. Disponible en C++11.
remquo (C++11 feature)
fma Producto-suma (C++11 feature)
fmax
fmin
Determina el mayor o menor de dos valores en punto flotante (C++11 feature)
fdim Determina la diferencia absoluta entre dos valores en punto flotante (C++11 feature)
nan
nanf
nanl
Determina "not-a-number" (NaN) (C++11 feature)

[editar] Funciones exponenciales

Función Propósito
exp Calcula e elevado a la potencia dada.
exp2 Calcula 2 elevado a la potencia dada.
expm1 Calcula e elevado a la potencia dada, menos uno. (C++11 feature)
log Calcula el logaritmo natural (base e).
log10 Calcula el logaritmo común (base 10).
log1p Calcula el logaritmo natural de 1+n. (C++11 feature)
ilogb Extrae la potencia binaria del número. (C++11 feature)
logb Extrae la potencia binaria del número. (C++11 feature)

[editar] Funciones potencias

Función Propósito
sqrt Calcula la raíz cuadrada.
cbrt Calcula la raíz cúbica.
hypot Calcula la raíz cuadrada de la suma de los cuadrados (hipotenusa de los dos catetos). (C++11 feature)
pow Calcula un número elevado a la potencia del otro.

[editar] Funciones trigonométricas

Función Propósito
sin seno
cos coseno
tan tangente
asin arcoseno
acos arcocoseno
atan arcotangente
atan2 arcotangente de dos argumentos, usando el signo para determinar el cuadrante

[editar] Funciones hiperbólicas

Función Propósito
sinh seno hiperbólico
cosh coseno hiperbólico
tanh tangente hiperbólica
asinh arcoseno hiperbólico (C++11 feature)
acosh arcocoseno hiperbólico (C++11 feature)
atanh arcotangente hiperbólica (C++11 feature)

[editar] Funciones de error y gamma

Función Propósito
erf error function (C++11 feature)
erfc complementary error function (C++11 feature)
lgamma natural logarithm of the gamma function (C++11 feature)
tgamma gamma function (C++11 feature)

[editar] Búsqueda del valor entero/real más cercano

Función Propósito
ceil nearest integer not less than the given value
floor nearest integer not greater than the given value
trunc nearest integer not greater in magnitude than the given value (C++11 feature)
round
lround
llround
nearest integer, rounding away from zero in halfway cases (C++11 feature)
nearbyint nearest integer using current rounding mode (C++11 feature)
rint
lrint
llrint
nearest integer using current rounding mode with
exception if the result differs (C++11 feature)

[editar] Manipulación del punto flotante

Función Propósito
frexp decomposes a number into scientific notation
ldexp computes a number in scientific notation
modf decomposes a number into integer and fractional parts
scalbn, scalbln (C++11 feature)
nextafter next representable floating point value (C++11 feature)
nexttoward next representable floating point value towards the given value (C++11 feature)
copysign copies the sign of a floating point value (C++11 feature)

[editar] Clasificaciones

Función Propósito
fpclassify categorizes the given floating point value (C++11 feature)
isfinite checks if the given number has finite value (C++11 feature)
isinf checks if the given number is infinite (C++11 feature)
isnan checks if the given number is NaN(C++11 feature)
isnormal checks if the given number is normal (C++11 feature)
signbit checks if the given number is negative (C++11 feature)

[editar] Macros

[editar] Constantes

HUGE_VAL indicates value too big to be representable (infinity) by double
HUGE_VALF indicates value too big to be representable (infinity) by float (C++11 feature)
HUGE_VALL indicates value too big to be representable (infinity) by long double (C++11 feature)

[editar] Clasificaciones

FP_INFINITE indicates infinite floating point value (C++11 feature)
FP_NAN indicates not-a-number (NaN) (C++11 feature)
FP_NORMAL indicates normal number (C++11 feature)
FP_SUBNORMAL indicates subnormal number (C++11 feature)
FP_ZERO indicates zero (C++11 feature)

[editar] Notes

In order to use some of the above functions, certain versions of the gcc compiler require the math library to be explicitly linked in using the -lm command-line option.

Herramientas personales
Espacios de nombres
Variantes
Acciones
Navegación
Herramientas