## Math functions in C++

Math functions are some established library functions related to mathematical calculations. All the C++ math functions are defined under math.h header file. C++ provides a strong library function and math functions are some of them.

We need to include math.h header file to work with math functions. Now let’s move towards the math function and why they are use inside our program.

## Trigonometric math functions

sin(x) — sin(x) determine the sine of angle x.

cos(x) — cos(x) can calculate the cosine of x.

tan(x) — tan(x) is used to determine tangent of x.

asin(x) — asin(x) determine the inverse sine of x.

acos(x) — acos(x) can calculate the inverse cosine of x.

atan(x) — atan(x) can calculate the inverse tangent of x.

## Power related math functions

sqrt(x) — sqrt(x) is used to calculate square root of x.

pow(x, y) — pow(x, y) is used to calculate xy.

cbrt(x) — cbrt(x) is used to calculate the cubic root of x.

hypot(x, y) — hypot(x, y) determines the hypotenuse of a right angled triangle

## Max, min and difference related math functions

fmax(x, y) — fmax(x, y) finds the smallest number between x and y.

fmin(x, y) — fmin(x, y) finds the minimum number between x and y.

fdim(x, y) — fdim(x, y) determine the positive difference of x and y.

## Hyperbolic math functions

sinh(x) — sinh(x) finds the hyperbolic sine of x.

cosh(x) — cosh(x) determines the hyperbolic cosine of x.

tanh(x) — tanh(x) can determine the hyperbolic tangent of x.

asinh(x) — asinh(x) can determine the arc hyperbolic sine of x.

acosh(x) — acosh(x) can find the arc hyperbolic cosine of x.

atanh(x) — atanh(x) calculates the arc hyperbolic tangent of x.

## Integer related math functions

floor(x) — floor(x) returns the largest rounds value less than or equal x.

ceil(x) — ceil(x) returns the smallest rounds value greater than or equal x.

round(x) — round(x) can round the value of x in natural way.

fmod(x, y) — fmod(x, y) determines the reminder of x / y.

reminder(x, y) — reminder(x, y) calculate the reminder of x / y.

remquo(x, y) — remquo(x, y) calculates both the reminder and quotient of x /y.

fabs(x) — fabs(x) is used to find absolute value of x.

abs(x) — abs(x) is also used to find the absolute value of x.

## Exponential math functions

exp(x) — exp(x) is used to find ex.

log(x) — log(x) can determine the logarithm of x.

log10(x) — log10(x) is also determine the logarithm of x.

logb(x) — logb(x) is also find the normal logarithm of x.

modf() — modf() function is used to break a number into an integer and a fractional part.

exp2(x) — exp2(x) can determine the exponential of x of base 2.

log2(x) — log2(x) is used to fine the logarithm of x of base 2.

expm1(x) — expm1(x) can determine ex-1.

log1p(x) — log1p(x) is used to find logarithm of (x + 1).

## Macro math functions

isinf(x) — isinf(x) is used to check whether x is infinite or not.

isfinite(x) — isfinite(x) is used to check that x is finite or not.

isnan(x) — isnan(x) is used to check x is nan or not.

isnormal(x) — isnormal(x) checks that x is normal or not.

signbit(x) — signbit(x) checks the sign of x is negative or not.

isgreater(x, y) — isgreater(x, y) is used to check whether x is greater than y or not.

isless(x, y) — isless(x, y) is used to check whether x is less than y or not.

isgreaterequal(x, y) — isgreaterequal(x, y) checks whether x is greater than or equal to y or not.

islessequal(x, y) — islessequal(x, y) checks whether x is less than or equal y or not.

tgamma(x) — tgamma(x) is used to find the gamma functions value of x.

lgamma(x) — lgamma(x) is used to calculate the logarithm of gamma function of value x.

## C++ program using math functions

``````// c++ program using math functions

#include <iostream>
#include <math.h>
using namespace std;

int main(){
int x = 90;
int y = 20;

cout << sin(x) << endl;    // sine of x
cout << cos(x) << endl;    // cosine of x
cout << tan(x) << endl;    // tangent of x
cout << pow(2, 3) << endl;    // power 3 of 2
cout << sqrt(25) << endl;    // square root of 25 = 5
cout << fmax(x, y) << endl;    // which is maximum between x and y
cout << fmin(x, y) << endl;    // which is minimum between x and y
cout << floor(3.8233) << endl;
cout << ceil(3.8233) << endl;
cout << round(3.8233) << endl;

return 0;
}``````

Output of this program Previous pageOperators in C++

Next pageBooleans in C++