Mathematical functions in C Programming Language

Source: Internet
Author: User

Mathematical functions in C Language

The C language provides the following mathematical functions. To use these functions, you must add them to the program file header:

# Include <math. h>

During compilation, the "-lm" parameter must be added to the mathematical function library, for example, "gcc-LM test. c 」.

For the independent variables of the function and the return value types, see the Declaration of the type before the independent variables or functions.

The function is already in "math. H "or other header files have been declared, so you do not need to add a type declaration during use, for example," Y = sin (x );」, you do not need to write "Y = double sin (Double X );」.

Function Description

Double sin (Double X)

Sine function value of X

Double cos (Double X)

Returns the cosine of X.

Double Tan (Double X)

Returns the tangent of X.

Double asin (Double X)

The inverse sine function value of X sin-1x, the value of X between [-], the return value between [-P/2, P/2]

Double ACOs (Double X)

Returns the inverse cosine function value of cos-1x between [-] and between [-P/2, P/2 ].

Double atan (Double X)

Returns the arc tangent function value tan-1x between [-P/2, P/2 ].

Double atan2 (Double Y, double X)

The arc tangent function value of Y/X Tan-1 (y/X). The return value is between [-p, p ].

Double sinh (Double X)

Returns the hyperbolic sine of X.

Double cosh (Double X)

Returns the hyperbolic cosine of X.

Double Tanh (Double X)

Returns the hyperbolic tangent of X.

Double exp (Double X)

X's exponential function ex

Double Log (Double X)

Natural logarithm Ln (x) of x, x> 0

Double log10 (Double X)

The base number of X is the logarithm of 10, log10x, x> 0

Double POW (Double X, Double Y)

X to the power of Y XY

Double SQRT (Double X)

The root number of X √ x

Double Ceil (Double X)

Minimum integer not less than X (but its type is double)

Double floor (Double X)

The maximum integer not greater than X (but its type is double)

Int ABS (int x)

Absolute Value of integer x |

Long labs (long X)

Absolute Value of long integer x |

Double FABS (Double X)

Absolute value of real number x |

Double ldexp (Double X, int N)

X? 2N

Double fmod (Double X, Double Y)

The remainder of the Floating Point Number of x/y. the symbol is the same as that of X.

Function Name: atof
Function: converts a string to a floating point number.
Usage: Double atof (const char * nptr );
Program example:
# Include <stdlib. h>
# Include <stdio. h>

Int main (void)
{
Float F;
Char * STR = "12345.67 ";

F = atof (STR );
Printf ("string = % s float = % F/N", STR, F );
Return 0;
}

Function Name: atoi
Function: converts a string to an integer.
Usage: int atoi (const char * nptr );
Program example:
# Include <stdlib. h>
# Include <stdio. h>

Int main (void)
{
Int N;
Char * STR = "12345.67 ";

N = atoi (STR );
Printf ("string = % s integer = % d/N", STR, N );
Return 0;
}

Function Name: atol
Function: converts a string to an integer.
Usage: Long atol (const char * nptr );
Program example:

# Include <stdlib. h>
# Include <stdio. h>

Int main (void)
{
Long L;
Char * STR = "98765432 ";

L = atol (lstr );
Printf ("string = % s integer = % LD/N", STR, L );
Return (0 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.