MOCKSTACKS
EN  # C++ Mathematical Functions

C++ does support Mathematical Functions from libraries: `math.h` or `cmath`. So one of these libraries has to be included in the program in order to be able to work with C++ Mathematical Functions.

## Below Table is a list of C++ Mathematical Functions

Function Return Type Description
abs(x) int The fucntion returns the absolute value of x
acos(x) double The fucntion returns the arccosine of x
asin(x) double The fucntion returns the arcsine of x
atan(x) double The fucntion returns the arctangent of x
ceil(x) double The fucntion returns the value of x rounded up to its nearest integer
cos(x) doubleThe fucntion returns the cosine of x
cosh(x) double The fucntion returns the hyperbolic cosine of x
exp(x) double The fucntion returns the value of Ex
expm1(x) double The fucntion returns ex -1
fabs(x) double The fucntion returns the absolute value of a floating x
floor(x) double The fucntion returns the value of x rounded down to its nearest integer
hypot(x, y) double The fucntion returns sqrt(x2 +y2) without intermediate overflow or underflow
pow(x, y) double The fucntion returns the value of x to the power of y
sin(x) double The fucntion returns the sine of x (x is in radians)
sinh(x) double The fucntion returns the hyperbolic sine of a double value
tan(x) double The fucntion returns the tangent of an angle
tanh(x) double The fucntion returns the hyperbolic tangent of a double value

## Examples of C++ Mathematical Functions

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

int main()
{
double x = 8.1;
cout << "Sine value of x=8.1; : " << sin(x) << endl;
cout << "Cosine value of x=8.1; : " << cos(x) << endl;
cout << "Tangent value of x=8.1; : " << tan(x) << endl;

double y = 6.25;
cout << "Square root value of y=6.25 : " << sqrt(y) << endl;

int z = -50;
cout << "Absolute value of z=-50 : " << abs(z) << endl;
cout << "Power value: x^y = (8.1^6.25) : " << pow(x, y) << endl;

x = 2.0;
y = 1.0;
cout << "Hypotenuse having other two sides as x=2.0 and"
<< " y=1.0 : " << hypot(x, y) << endl;

x = 7.56;
cout << "Floor value of x=7.56 is : " << floor(x) << endl;

x = -5.43;
cout << "Absolute value of x=-5.43 is : " << fabs(x) << endl;

x = 6.0;
cout << "Arc Cosine value of x=6.0 : " << acos(x) << endl;
cout << "Arc Sine value of x=6.0 : " << asin(x) << endl;
cout << "Arc Tangent value of x=6.0 : " << atan(x) << endl;

y = 13.3;
cout << "Ceiling value of y=13.3 : " << ceil(y) << endl;

x = 33.3;
cout << "Hyperbolic Cosine of x=33.3 : " << cosh(x) << endl;
cout << "Hyperbolic tangent of x=33.3 : " << tanh(x) << endl;

y = 50.0;
cout << "Log value of y=50.0 is : " << log(y) << endl;

return 0;
}``````

### Output

Sine value of x=8.1; : 0.96989
Cosine value of x=8.1; : -0.243544
Tangent value of x=8.1; : -3.9824
Square root value of y=6.25 : 2.5
Absolute value of z=-50 : 50
Power value: x^y = (8.1^6.25) : 476465
Hypotenuse having other two sides as x=2.0 and y=1.0 : 2.23607
Floor value of x=7.56 is : 7
Absolute value of x=-5.43 is : 5.43
Arc Cosine value of x=6.0 : nan
Arc Sine value of x=6.0 : nan
Arc Tangent value of x=6.0 : 1.40565
Ceiling value of y=13.3 : 14
Hyperbolic Cosine of x=33.3 : 1.44869e+14
Hyperbolic tangent of x=33.3 : 1
Log value of y=50.0 is : 3.91202

## Conclusion

In this page (written and validated by ) you learned about C++ Mathematical Functions . What's Next? If you are interested in completing Cpp tutorial, your next topic will be learning about: Cpp if else if Statement.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.