C++ Mathematical Functions Last Updated : 04 Aug, 2023 Comments Improve Suggest changes Like Article Like Report C++ being a superset of C, supports a large number of useful mathematical functions. These functions are available in standard C++ to support various mathematical calculations. Instead of focusing on implementation, these functions can be directly used to simplify code and programs. In order to use these functions you need to include a header file- <math.h> or <cmath>. Math Library Functions in C++ C++ provides a large set of mathematical functions which are stated below: FunctionDescriptiondouble sin(double)This function takes angle (in radian) as an argument and returns its sine value that could be verified using sine curve.double cos(double)This function takes angle (in radians) as an argument and returns its cosine value that could be verified using cosine curve.double tan(double)This function takes angle (in radians) as an argument and returns its tangent value. This could also be verified using Trigonometry as Tan(x) = Sin(x)/Cos(x).double sqrt(double)This function takes a number as an argument and returns its square root value. The number can not be a negative value.int abs(int)This function takes an integer number as an argument and returns its absolute value. It means the output will always be positive regardless of the sign of the input.double pow(double, double)This function takes one argument as base and another as exponent.double hypot(double, double)This function requires two sides of the right-angled triangle to give output as its hypotenuse.double floor(double)This functions returns the integer value lesser or equal to the argument passed in the function.double fabs(double)This function returns the absolute value of any number.double acos(double)This function returns the arc cosine of the argument. The argument to acos() must be in the range -1 to 1; otherwise, a domain error occurs.double asin(double)This function returns the arc sine of the argument. The argument to asin() must be in the range -1 to 1; otherwise, a domain error occurs.double atan(double)This function returns the arc tangent of arg.double atan2(double, double)This function returns the arc tangent of (double a)/(double b).double ceil(double)This function returns the smallest integer as double not less than the argument provided.double cosh(double)This function returns the hyperbolic cosine of the argument provided. The value of the argument provided must be in radians.double tanh(double)This function returns the hyperbolic tangent of the argument provided. The value of the argument provided must be in radians.double log(double)This function takes a number and returns the natural log of that number.double exp(double)This function returns the value of e = 2.718 raised to the given number.Example of C++ Mathematical Functions C++ program to illustrate some of the above-mentioned functions: C++ // C++ program to illustrate some of the // above mentioned functions #include <iostream> #include <math.h> using namespace std; int main() { double x = 2.3; cout << "Sine value of x=2.3 : " << sin(x) << endl; cout << "Cosine value of x=2.3 : " << cos(x) << endl; cout << "Tangent value of x=2.3 : " << tan(x) << endl; double y = 0.25; cout << "Square root value of y=0.25 : " << sqrt(y) << endl; int z = -10; cout << "Absolute value of z=-10 : " << abs(z) << endl; cout << "Power value: x^y = (2.3^0.25) : " << pow(x, y) << endl; x = 3.0; y = 4.0; cout << "Hypotenuse having other two sides as x=3.0 and" << " y=4.0 : " << hypot(x, y) << endl; x = 4.56; cout << "Floor value of x=4.56 is : " << floor(x) << endl; x = -4.57; cout << "Absolute value of x=-4.57 is : " << fabs(x) << endl; x = 1.0; cout << "Arc Cosine value of x=1.0 : " << acos(x) << endl; cout << "Arc Sine value of x=1.0 : " << asin(x) << endl; cout << "Arc Tangent value of x=1.0 : " << atan(x) << endl; y = 12.3; cout << "Ceiling value of y=12.3 : " << ceil(y) << endl; x = 57.3; // in radians cout << "Hyperbolic Cosine of x=57.3 : " << cosh(x) << endl; cout << "Hyperbolic tangent of x=57.3 : " << tanh(x) << endl; y = 100.0; // Natural base with 'e' cout << "Log value of y=100.0 is : " << log(y) << endl; return 0; } OutputSine value of x=2.3 : 0.745705 Cosine value of x=2.3 : -0.666276 Tangent value of x=2.3 : -1.11921 Square root value of y=0.25 : 0.5 Absolute value of z=-10 : 10 Power value: x^y = (2.3^0.25) : 1.23149 Hypotenuse having other two sides as x=3.0 and y=4.0 : 5 Floor value of x=4.56 is : 4 Absolute value of x=-4.57 is : 4.57 Arc Cosine value of x=1.0 : 0 Arc Sine value of x=1.0 : 1.5708 Arc Tangent value of x=1.0 : 0.785398 Ceiling value of y=12.3 : 13 Hyperbolic Cosine of x=57.3 : 3.83746e+24 Hyperbolic tangent of x=57.3 : 1 Log value of y=100.0 is : 4.60517 Comment More infoAdvertise with us Next Article C++ Mathematical Functions V Vidhayak_Chacha Follow Improve Article Tags : C++ Programs C++ CPP-Functions cpp-math Practice Tags : CPP Similar Reads C/C++ Mathematical Programs Mathematical Algorithms in programming are the specialized method to solve arithmetic problems such as finding roots, GCD, etc. Most of us are familiar with the conventional methods and concepts used to solve such problems but they may not be the best choice in programming, such as the best choice f 2 min read C++ Function Practice Problems Functions are the basic building block of the program. They are the block of code that performs a specific task. Function can be executed from anywhere in the program any number of times. They increase the modularity and reusability of the code.Practicing problems is one of the most effective ways t 2 min read Useful Inbuilt Functions in C++ In-built functions in C++ are those functions that are part of C++ standard libraries. The purpose of inbuilt functions is to provide common and essential functionality that is frequently required in the programming. In this article, we will look at some of the commonly used inbuilt functions in C++ 7 min read C++ Program to Illustrate Trigonometric functions The math.h header contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In order to use these functions you need to include header file math.h. Note: All the functions take input in radians and not degrees Be 5 min read How to Parse Mathematical Expressions in a C++ String? In C++, strings are sequences of characters stored in a char array. Strings are used to store words and text. We can also store mathematical expressions in this string. In this article, we will explore how to parse mathematical expressions in a C++ String. Example: Input:expression = (3 + 4) * 2 / ( 5 min read C++ Fundamentals Practice Problems Fundamental concepts form the foundation of learning any programming language. They include absolute basic topics such as storing and accessing data, input and output, performing mathematical, logical, operations, etc. So it is important to have clear understanding of fundamentals to move on to the 2 min read C++ Program to Make a Simple Calculator A simple calculator is a device used to perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It makes arithmetic calculations easier and faster. In this article, we will learn how to code a simple calculator using C++.ExamplesInput: Enter an operator (+, - 3 min read C++ Program to Perform Calculations in Pure Strings Given a string of operations containing three operands for each operation "type of command", "first operand", and "second operand". Calculate all the commands given in this string format. In other words, you will be given a pure string that will ask you to perform an operation and you have to perfor 5 min read C++ Exercises - C++ Practice Set with Solutions Do you want to improve your command on C++ language? Explore our vast library of C++ exercise questions, which are specifically designed for beginners as well as for advanced programmers. We provide a large selection of coding exercises that cover every important topic, including classes, objects, a 15+ min read C++ program for Complex Number Calculator Pre-Requisites: Complex Numbers, Mathematics, Object-oriented Programming This is a Complex Number Calculator which performs a lot of operations which are mentioned below, to simplify our day-to-day problems in mathematics. The implementation of this calculator is done using C++ Programming Language 15+ min read Like