# C++ Programming/Code/Standard C Library/Math
#### Standard C Math

This section will cover the Math elements of the C Standard Library.

## abs

| Syntax | #include <cstdlib> int abs( int num ); |
The abs function returns the absolute value of num. For example:

### Related topics

    fabs - labs

## acos

| Syntax | #include <cmath> double acos( double arg ); |
The acos function returns the arc cosine of arg, which will be in the range [0, pi]. arg should be between -1 and 1. If arg is outside this range, acos returns NAN and raises a floating-point exception.

### Related topics

    asin - atan - atan2 - cos - cosh - sin - sinh - tan - tanh

## asin

| Syntax | #include <cmath> double asin( double arg ); |
The asin function returns the arc sine of arg, which will be in the range [-pi/2, +pi/2]. arg should be between -1 and 1. If arg is outside this range, asin returns NAN and raises a floating-point exception.

### Related topics

    acos - atan - atan2 - cos - cosh - sin - sinh - tan - tanh

## atan

| Syntax | #include <cmath> double atan( double arg ); |
The function atan returns the arc tangent of arg, which will be in the range [-pi/2, +pi/2].

### Related topics

    acos - asin - atan2 - cos - cosh - sin - sinh - tan - tanh

## atan2

| Syntax | #include <cmath> double atan2( double y, double x ); |
The atan2 function computes the arc tangent of y/x, using the signs of the arguments to compute the quadrant of the return value.

### Related topics

    acos - asin - atan - cos - cosh - sin - sinh - tan - tanh

#### ceil

| Syntax | #include <cmath> double ceil( double num ); |
The ceil function returns the smallest integer no less than num. For example:
would set x to 7.0.

##### Related topics

    floor - fmod

#### cos

| Syntax | #include <cmath> float cos( float arg ); double cos( double arg ); long double cos( long double arg ); |
The cos function returns the cosine of arg, where arg is expressed in radians. The return value of cos is in the range [-1,1]. If arg is infinite, cos will return NAN and raise a floating-point exception.

##### Related topics

    acos - asin - atan - atan2 - cosh - sin - sinh - tan - tanh

#### cosh

| Syntax | #include <cmath> float cosh( float arg ); double cosh( double arg ); long double cosh( long double arg ); |
The function cosh returns the hyperbolic cosine of arg.

##### Related topics

    acos - asin - atan - atan2 - cos - sin - sinh - tan - tanh

#### div

| Syntax | #include <cstdlib> div_t div( int numerator, int denominator ); |
The function div returns the quotient and remainder of the operation numerator / denominator. The div_t structure is defined in cstdlib, and has at least:
For example, the following code displays the quotient and remainder of x/y:

##### Related topics

    ldiv

#### exp

| Syntax | #attrid <cmath> double exp( double arg ); |
The exp function returns e (2.7182818) raised to the argth power.

##### Related topics

    log - pow - sqrt

#### fabs

| Syntax | #include <cmath> double fabs( double arg ); |
The function fabs returns the absolute value of arg.

##### Related topics

    abs - fmod - labs

#### floor

| Syntax | #include <cmath> double floor( double arg ); |
The function floor returns the largest integer value not greater than arg.
would result in x being set to 6 (double 6.0).
would result in x being set to -7 (double -7.0).

##### Related topics

    ceil - fmod

#### fmod

| Syntax | #include <cmath> double fmod( double x, double y ); |
The fmod function returns the remainder of x/y.

##### Related topics

    ceil - fabs - floor

#### frexp

| Syntax | #include <cmath> double frexp( double num, int* exp ); |
The function frexp is used to decompose num into two parts: a mantissa between 0.5 and 1 (returned by the function) and an exponent returned as exp. Scientific notation works like this:

##### Related topics

    ldexp - modf

#### labs

| Syntax | #include <cstdlib> long labs( long num ); |
The function labs returns the absolute value of num.

##### Related topics

    abs - fabs

#### ldexp

| Syntax | #include <cmath> double ldexp( double num, int exp ); |
The ldexp function returns num * (2 ^ exp). And get this: if an overflow occurs, HUGE_VAL is returned.

##### Related topics

    frexp - modf

#### ldiv

| Syntax | #include <cstdlib> ldiv_t ldiv( long numerator, long denominator ); |
Testing: adiv_t, div_t, ldiv_t.
The ldiv function returns the quotient and remainder of the operation numerator / denominator. The ldiv_t structure is defined in cstdlib and has at least:

##### Related topics

    div

#### log

| Syntax | #include <cmath> double log( double num ); |
The function log returns the natural (base e) logarithm of num. There's a domain error if num is negative, a range error if num is zero.
In order to calculate the logarithm of x to an arbitrary base b, you can use:

##### Related topics

    exp - log10 - pow - sqrt

#### log10

| Syntax | #include <cmath> double log10( double num ); |
The log10 function returns the base 10 (or common) logarithm for num. There will be a domain error if num is negative and a range error if num is zero.

##### Related topics

    log

#### modf

| Syntax | #include <cmath> double modf( double num, double *i ); |
The function modf splits num into its integer and fraction parts. It returns the fractional part and loads the integer part into i.

##### Related topics

    frexp - ldexp

#### pow

| Syntax | #include <cmath> double pow( double base, double exp ); |
The pow function returns base raised to the expth power. There's a domain error if base is zero and exp is less than or equal to zero. There's also a domain error if base is negative and exp is not an integer. There's a range error if an overflow occurs.

##### Related topics

    exp - log - sqrt

#### sin

| Syntax | #include <cmath> double sin( double arg ); |
If you don't want cmath you can write sin function it is;
* include <iostream>
using namespace std;
double sin(double x) //sin function {return x-((x*x*x)/6.)+((x*x*x*x*x)/120.);}
int main {
return 0;}
The function sin returns the sine of arg, where arg is given in radians. The return value of sin will be in the range [-1,1]. If arg is infinite, sin will return NAN and raise a floating-point exception.

##### Related topics

    acos - asin - atan - atan2 - cos - cosh - sinh - tan - tanh

#### sinh

| Syntax | #include <cmath> double sinh( double arg ); |
The function sinh returns the hyperbolic sine of arg.

##### Related topics

    acos - asin - atan - atan2 - cos - cosh - sin - tan - tanh

#### sqrt

| Syntax | #include <cmath> double sqrt( double num ); |
The sqrt function returns the square root of num. If num is negative, a domain error occurs.

##### Related topics

    exp - log - pow

#### tan

| Syntax | #include <cmath> double tan( double arg ); |
The tan function returns the tangent of arg, where arg is given in radians. If arg is infinite, tan will return NAN and raise a floating-point exception.

##### Related topics

    acos - asin - atan - atan2 - cos - cosh - sin - sinh - tanh

#### tanh

| Syntax | #include <cmath> double tanh( double arg ); |
The function tanh returns the hyperbolic tangent of arg.

##### Related topics

    acos - asin - atan - atan2 - cos - cosh - sin - sinh - tan