math.h

Overview

Related Modules:

MATH

Description:

Provides common math functions.

You can use the functions provided in this file to perform mathematical operations during development. The functions include trigonometric, inverse trigonometric, hyperbolic, inverse hyperbolic, rounding, exponential, logarithmic, and Bessel functions. When using these functions, pay attention to the value range of their input parameters.

Since:

1.0

Version:

1.0

Summary

Macros

Macro Name and Value Description
NAN   (0.0f/0.0f) Indicates an undefined or unrepresentable value.
INFINITY   1e5000f Indicates an infinity.
HUGE_VALF   INFINITY Indicates a float infinity.
HUGE_VAL   ((double)INFINITY) Indicates a double infinity.
HUGE_VALL   ((long double)INFINITY) Indicates a long double infinity.
MATH_ERRNO   1 Indicates an error that occurs in floating-point operations.
MATH_ERREXCEPT   2 Indicates a floating-point exception.
math_errhandling   2 Indicates the error handling mechanism employed by math functions.
FP_ILOGBNAN   (-1-0x7fffffff) Indicates the calculation result of ilogb(NAN).
FP_ILOGB0   FP_ILOGBNAN Indicates the calculation result of ilogb(0).
FP_NAN   0 Indicates a Not-a-Number (NaN) value.
FP_INFINITE   1 Indicates an infinity.
FP_ZERO   2 Indicates value 0.
FP_SUBNORMAL   3 Indicates a subnormal.
FP_NORMAL   4 Indicates a normal value.
isinf(x) Checks whether the floating-point value x is an infinity.
isnan(x) Checks whether the floating-point value x is a NaN value.
isnormal(x) Checks whether the floating-point value x is a normal value.
isfinite(x) Checks whether the floating-point value x is finite.
signbit(x) Checks whether the sign of the floating-point value x is negative.
isunordered(x, y)   (isnan((x)) ? ((void)(y),1) : isnan((y))) Checks whether floating-point value x or y is unordered.
isless(x, y)   tg_pred_2(x, y, isless) Checks whether floating-point value x is less than y.
islessequal(x, y)   tg_pred_2(x, y, islessequal) Checks whether floating-point value x is less than or equal to y.
islessgreater(x, y)   tg_pred_2(x, y, islessgreater) Checks whether floating-point value x is either less than or greater than y.
isgreater(x, y)   tg_pred_2(x, y, isgreater) Checks whether floating-point value x is greater than y.
isgreaterequal(x, y)   tg_pred_2(x, y, isgreaterequal) Checks whether floating-point value x is greater than or equal to y.
MAXFLOAT   3.40282346638528859812e+38F Maximum value of type float.
M_E   2.7182818284590452354 / e / Base e of natural logarithms.
M_LOG2E   1.4426950408889634074 / log_2 e / Logarithm to base 2 of M_E
M_LOG10E   0.43429448190325182765 / log_10 e / Logarithm to base 10 of M_E
M_LN2   0.69314718055994530942 / log_e 2 / Natural logarithm of 2
M_LN10   2.30258509299404568402 / log_e 10 / Natural logarithm of 10
M_PI   3.14159265358979323846 / pi / Ratio of a circle’s circumference to its diameter.
M_PI_2   1.57079632679489661923 / pi/2 / Pi divided by 2
M_PI_4   0.78539816339744830962 / pi/4 / Pi divided by 4
M_1_PI   0.31830988618379067154 / 1/pi / Reciprocal of pi.
M_2_PI   0.63661977236758134308 / 2/pi / Two times the reciprocal of pi.
M_2_SQRTPI   1.12837916709551257390 / 2/sqrt(pi) / Two times the reciprocal of the square root of pi.
M_SQRT2   1.41421356237309504880 / sqrt(2) / Square root of 2
M_SQRT1_2   0.70710678118654752440 / 1/sqrt(2) / Reciprocal of the square root of 2

Functions

Function Name Description
acos (double x) double Calculates the arc cosine of the double value x.
acosf (float x) float Calculates the arc cosine of the float value x.
acosl (long double x) long double Calculates the arc cosine of the long double value x.
acosh (double x) double Calculates the inverse hyperbolic cosine of the double value x.
acoshf (float x) float Calculates the inverse hyperbolic cosine of float value x.
acoshl (long double x) long double Calculates the inverse hyperbolic cosine of the long double value x.
asin (double x) double Calculates the arc sine of the double value x.
asinf (float x) float Calculates the arc sine of the float value x.
asinl (long double x) long double Calculates the arc sine of the long double value x.
asinh (double x) double Calculates the inverse hyperbolic sine of the double value x.
asinhf (float x) float Calculates the inverse hyperbolic sine of the float value x.
asinhl (long double x) long double Calculates the inverse hyperbolic sine of the long double value x.
atan (double x) double Calculates the arc tangent of the double value x.
atanf (float x) float Calculates the arc tangent of the float value x.
atanl (long double x) long double Calculates the arc tangent of the long double value x.
atan2 (double y, double x) double Calculates the arc tangent of two double values x and y.
atan2f (float y, float x) float Calculates the arc tangent of two float values x and y.
atan2l (long double y, long double x) long double Calculates the arc tangent of two long double values x and y.
atanh (double x) double Calculates the inverse hyperbolic tangent of the double value x.
atanhf (float x) float Calculates the inverse hyperbolic tangent of the float value x.
atanhl (long double x) long double Calculates the inverse hyperbolic tangent of the long double value x.
cbrt (double x) double Calculates the cube root of the double value x.
cbrtf (float x) float Calculates the cube root of the float value x.
cbrtl (long double x) long double Calculates the cube root of the long double value x.
ceil (double x) double Calculates the minimum integer greater than or equal to the double value x.
ceilf (float x) float Calculates the minimum integer greater than or equal to the float value x.
ceill (long double x) long double Calculates the minimum integer greater than or equal to the long double value x.
copysign (double x, double y) double Generates a value by combining the magnitude of the double value x and the sign of the double value y.
copysignf (float x, float y) float Generates a value by combining the magnitude of the float value x and the sign of the float value y.
copysignl (long double x, long double y) long double Generates a value by combining the magnitude of the long double value x and the sign of the long double value y.
cos (double x) double Calculates the cosine of the double value x.
cosf (float x) float Calculates the cosine of the float value x.
cosl (long double x) long double Calculates the cosine of the long double value x.
cosh (double x) double Calculates the hyperbolic cosine of the double value x.
coshf (float x) float Calculates the hyperbolic cosine of the float value x.
coshl (long double x) long double Calculates the hyperbolic cosine of the long double value x.
erf (double x) double Calculates the error function of the double value x.
erff (float x) float Calculates the error function of the float value x.
erfl (long double x) long double Calculates the error function of the long double value x.
erfc (double x) double Calculates the complementary error function of the double value x.
erfcf (float x) float Calculates the complementary error function of the float value x.
erfcl (long double x) long double Calculates the complementary error function of the long double value x.
exp (double x) double Calculates the base-e exponential function of the double value x.
expf (float x) float Calculates the base-e exponential function of the float value x.
expl (long double x) long double Calculates the base-e exponential function of the long double value x.
exp2 (double x) double Calculates the base-2 exponential function of the double value x.
exp2f (float x) float Calculates the base-2 exponential function of the float value x.
exp2l (long double x) long double Calculates the base-2 exponential function of the long double value x.
expm1 (double x) double Calculates e raised to the power of the double value x minus one, that is, (e^x)-1.
expm1f (float x) float Calculates e raised to the power of the float value x minus one.
expm1l (long double x) long double Calculates e raised to the power of the long double value x minus one.
fabs (double x) double Calculates the absolute value of the double value x.
fabsf (float x) float Calculates the absolute value of the float value x.
fabsl (long double x) long double Calculates the absolute value of the long double value x.
fdim (double x, double y) double Calculates the positive difference between the double value x and y.
fdimf (float x, float y) float Calculates the positive difference between the float value x and y.
fdiml (long double x, long double y) long double Calculates the positive difference between the long double value x and y.
floor (double x) double Obtains the largest integer less than or equal to the double value x.
floorf (float x) float Obtains the largest integer less than or equal to the float value x.
floorl (long double x) long double Obtains the largest integer less than or equal to the long double value x.
fma (double x, double y, double z) double Calculates the value of xy+z and rounds the result up.
fmaf (float x, float y, float z) float Calculates the value of xy+z and rounds the result up.
fmal (long double x, long double y, long double z) long double Calculates the value of xy+z and rounds the result up.
fmax (double x, double y) double Obtains the larger value of two double values x and y.
fmaxf (float x, float y) float Obtains the larger value of two float values x and y.
fmaxl (long double x, long double y) long double Obtains the larger value of two long double values x and y.
fmin (double x, double y) double Obtains the smaller value of two double values x and y.
fminf (float x, float y) float Obtains the smaller value of two float values x and y.
fminl (long double x, long double y) long double Obtains the smaller value of two long double values x and y.
fmod (double x, double y) double Calculates the remainder of the double value x divided by the double value y.
fmodf (float x, float y) float Calculates the remainder of the float value x divided by the float value y.
fmodl (long double x, long double y) long double Calculates the remainder of the long double value x divided by the long double value y.
frexp (double x, int exp) double Decomposes the double value x into a significand and an integral exponent for 2.
frexpf (float x, int exp) float Decomposes float value x into a binary significand and an integral exponent for 2.
frexpl (long double x, int exp) long double Decomposes long double value x into a binary significand and an integral exponent for 2.
hypot (double x, double y) double Calculates the hypotenuse of a right triangle whose legs are x and y.
hypotf (float x, float y) float Calculates the hypotenuse of a right triangle whose legs are x and y.
hypotl (long double x, long double y) long double Calculates the hypotenuse of a right triangle whose legs are x and y.
ilogb (double x) int Obtains the integral part of the logarithm of double value x.
ilogbf (float x) int Obtains the integral part of the logarithm of float value x.
ilogbl (long double x) int Obtains the integral part of the logarithm of the long double value x.
ldexp (double x, int exp) double Multiplies the double value x by 2 raised to the power of exp.
ldexpf (float x, int exp) float Multiplies the float value x by 2 raised to the power of exp.
ldexpl (long double x, int exp) long double Multiplies the long double value x by 2 raised to the power of exp.
lgamma (double x) double Calculates the natural logarithm of the absolute value of the gamma function of the double value x.
lgammaf (float x) float Calculates the natural logarithm of the absolute value of the gamma function of the float value x.
lgammal (long double x) long double Calculates the natural logarithm of the absolute value of the gamma function of the long double value x.
llrint (double x) long long int Rounds double value x to the nearest integer.
llrintf (float x) long long int Rounds float value x to the nearest integer.
llrintl (long double x) long long int Rounds long double value x to the nearest integer.
llround (double x) long long int Rounds double value x to the nearest integer, rounding away from 0.
llroundf (float x) long long int Rounds float value x to the nearest integer, rounding away from 0.
llroundl (long double x) long long int Rounds long double value x to the nearest integer, rounding away from 0.
log (double x) double Calculates the natural logarithm of the double value x.
logf (float x) float Calculates the natural logarithm of the float value x.
logl (long double x) long double Calculates the natural logarithm of the long double value x.
log10 (double x) double Calculates the common logarithm (logarithm with base 10) of the double value x.
log10f (float x) float Calculates the common logarithm (logarithm with base 10) of the float value x.
log10l (long double x) long double Calculates the common logarithm (logarithm with base 10) of the long double value x.
log1p (double x) double Calculates the natural logarithm of one plus the double value x.
log1pf (float x) float Calculates the natural logarithm of one plus the float value x.
log1pl (long double x) long double Calculates the natural logarithm of one plus the long double value x.
log2 (double x) double Calculates the binary logarithm (logarithm with base 2) of the double value x.
log2f (float x) float Calculates the binary logarithm (logarithm with base 2) of the float value x.
log2l (long double x) long double Calculates the binary logarithm (logarithm with base 2) of the long double value x.
logb (double x) double Calculates the logarithm of the absolute value of the double value x.
logbf (float x) float Calculates the logarithm of the absolute value of the float value x.
logbl (long double x) long double Calculates the logarithm of the absolute value of the long double value x.
lrint (double x) long int Rounds the double value x to the nearest integer.
lrintf (float x) long int Rounds the float value x to the nearest integer.
lrintl (long double x) long int Rounds the long double value x to the nearest integer.
lround (double x) long int Rounds double value x to the nearest integer, rounding away from 0.
lroundf (float x) long int Rounds the float value x to the nearest integer, rounding away from 0.
lroundl (long double x) long int Rounds the long double value x to the nearest integer, rounding away from 0.
modf (double x, double iptr) double Breaks the double value x into a signed integral and a fractional part.
modff (float x, float iptr) float Breaks the float value x into a signed integral and a fractional part.
modfl (long double x, long double iptr) long double Breaks the long double value x into a signed integral and a fractional part.
nan (const char tagp) double Obtains a quiet NaN value of the double type.
nanf (const char tagp) float Obtains a quiet NaN value of the float type.
nanl (const char tagp) long double Obtains a quiet NaN value of the long double type.
nearbyint (double x) double Rounds the double value x to an integer in floating-point format.
nearbyintf (float x) float Rounds the float value x to an integer in floating-point format.
nearbyintl (long double x) long double Rounds the long double value x to an integer in floating-point format.
nextafter (double x, double y) double Obtains the next representable value following the double value x in the direction of the double value y.
nextafterf (float x, float y) float Obtains the next representable value following the float value x in the direction of the float value y.
nextafterl (long double x, long double y) long double Obtains the next representable value following the long double value x in the direction of the long double value y.
nexttoward (double x, long double y) double Obtains the next representable value following the double value x in the direction of the long double value y.
nexttowardf (float x, long double y) float Obtains the next representable value following the float value x in the direction of the long double value y.
nexttowardl (long double x, long double y) long double Obtains the next representable value following the long double value x in the direction of the long double value y.
pow (double x, double y) double Obtains the double value x raised to the power of the double value y.
powf (float x, float y) float Obtains the float value x raised to the power of the float value y.
powf10 (float x) float Calculates the xth power of 10.
powl (long double x, long double y) long double Obtains the long double value x raised to the power of the long double value y.
powl10 (long double x) long double Calculates the xth power of 10.
remainder (double x, double y) double Calculates the remainder of the double value x divided by the double value y.
remainderf (float x, float y) float Calculates the remainder of the float value x divided by the float value y.
remainderl (long double x, long double y) long double Calculates the remainder of the long double value x divided by the long double value y.
remquo (double x, double y, int quo) double Calculates the quotient and remainder of the double value x divided by the double value y.
remquof (float x, float y, int quo) float Calculates the quotient and remainder of the float value x divided by the float value y.
remquol (long double x, long double y, int quo) long double Calculates the quotient and remainder of the long double value x divided by the long double value y.
rint (double x) double Rounds the double value x to the nearest integer.
rintf (float x) float Rounds the float value x to the nearest integer.
rintl (long double x) long double Rounds the long double value x to the nearest integer.
round (double x) double Rounds the double value x to the nearest integer, rounding away from 0.
roundf (float x) float Rounds the float value x to the nearest integer, rounding away from 0.
roundl (long double x) long double Rounds the long double value x to the nearest integer, rounding away from 0.
scalbln (double x, long int exp) double Multiplies the double value x by FLT_RADIX raised to the power of the long int value exp, that is, x(FLT_RADIX)^exp.
scalblnf (float x, long int exp) float Multiplies the float value x by FLT_RADIX raised to the power of the long int value exp, that is, x(FLT_RADIX)^exp.
scalblnl (long double x, long int exp) long double Multiplies the long double value x by FLT_RADIX raised to the power of the long int value exp, that is, x(FLT_RADIX)^exp.
scalbn (double x, int exp) double Multiplies the double value x by FLT_RADIX raised to the power of the int value exp, that is, x(FLT_RADIX)^exp.
scalbnf (float x, int exp) float Multiplies the float value x by FLT_RADIX raised to the power of the int value exp, that is, x(FLT_RADIX)^exp.
scalbnl (long double x, int exp) long double Multiplies the long double value x by FLT_RADIX raised to the power of the int value exp, that is, x(FLT_RADIX)^exp.
sin (double x) double Calculates the sine of the double value x.
sinf (float x) float Calculates the sine of the float value x.
sinl (long double x) long double Calculates the sine of the long double value x.
sinh (double x) double Calculates the hyperbolic sine of the double value x.
sinhf (float x) float Calculates the hyperbolic sine of the float value x.
sinhl (long double x) long double Calculates the hyperbolic sine of the long double value x.
sqrt (double x) double Calculates the square root of double value x.
sqrtf (float x) float Calculates the square root of the float value x.
sqrtl (long double x) long double Calculates the square root of the long double value x.
tan (double x) double Calculates the tangent of the double value x.
tanf (float x) float Calculates the tangent of the float value x.
tanl (long double x) long double Calculates the tangent of the long double value x.
tanh (double x) double Calculates the hyperbolic tangent of the double value x.
tanhf (float x) float Calculates the hyperbolic tangent of the float value x.
tanhl (long double x) long double Calculates the hyperbolic tangent of the long double value x.
tgamma (double x) double Calculates the gamma function of the double value x.
tgammaf (float x) float Calculates the gamma function of the float value x.
tgammal (long double x) long double Calculates the gamma function of the long double value x.
trunc (double x) double Obtains the nearest integer whose absolute value is less than or equal to the absolute value of the double value x.
truncf (float x) float Obtains the nearest integer whose absolute value is less than or equal to the absolute value of the float value x.
truncl (long double x) long double Obtains the nearest integer whose absolute value is less than or equal to the absolute value of the long double value x.
j0 (double x) double Calculates the Bessel function of the first kind of order 0 for the double value x.
j1 (double x) double Calculates the Bessel function of the first kind of order 1 for the double value x.
jn (int n, double x) double Calculates the Bessel function of the first kind of order n for the double value x.
y0 (double x) double Calculates the Bessel function of the second kind of order 0 for the double value x.
y1 (double x) double Calculates the Bessel function of the second kind of order 1 for the double value x.
yn (int n, double x) double Calculates the Bessel function of the second kind of order n for the double value x.
finite (double x) int Checks whether the double value x is an infinity or a NaN value.
finitef (float x) int Checks whether the float value x is an infinity or a NaN value.
scalb (double x, double exp) double Multiplies the double value x by FLT_RADIX raised to the power of the double value exp, that is, xFLT_RADIX^exp.
scalbf (float x, float exp) float Multiplies the float value x by FLT_RADIX raised to the power of the float value exp, that is, xFLT_RADIX^exp.
significand (double x) double Obtains the significand of the double value x scaled to the range [1,2).
significandf (float x) float Obtains the significand of the float value x scaled to the range [1,2).
j0f (float x) float Calculates the Bessel function of the first kind of order 0 for the float value x.
j1f (float x) float Calculates the Bessel function of the first kind of order 1 for the float value x.
jnf (int n, float x) float Calculates the Bessel function of the first kind of order n for the float value x.
y0f (float x) float Calculates the Bessel function of the second kind of order 0 for the float value x.
y1f (float x) float Calculates the Bessel function of the second kind of order 1 for the float value x.
ynf (int n, float x) float Calculates the Bessel function of the second kind of order n for the float value x.
lgammal_r (long double x, int signp) long double Calculates the natural logarithm of the absolute value of the gamma function of the double value x.
sincos (double x, double sin, double cos) void Calculates the sine and cosine of the double value x.
sincosf (float x, float sin, float cos) void Calculates the sine and cosine of the float value x.
sincosl (long double x, long double sin, long double cos) void Calculates the sine and cosine of the long double value x.
exp10 (double x) double Calculates the base-10 exponential function of the double value x.
exp10f (float x) float Calculates the base-10 exponential function of the float value x.
exp10l (long double x) long double Calculates the base-10 exponential function of the long double value x.
pow10 (double x) double Calculates the value of 10 raised to the power x, which is a double value.
pow10f (float x) float Calculates the value of 10 raised to the power x, which is a float value.
pow10l (long double x) long double Calculates the value of 10 raised to the power x, which is a long double value.