Processing related mathematical functions in c ++

Source: Internet
Author: User
Tags acos asin mathematical functions natural logarithm

In math. h, the mathematical library function declaration mainly includes:

1. abs (x) calculates the absolute value of integer x.

2. cosine of cos (x) x (radians)

3. fabs (x) calculates the absolute value of floating point number x.

4. ceil (x) calculates the smallest integer not less than x.

5. floor (x) is the smallest integer not greater than x.

6. log (x) calculates the natural logarithm of x.

7. log10 (x) calculates the logarithm of x (base 10)

8. pow (x, y) calculates the Power y of x.

Function Description:

Pow () is used to calculate the base-x y power value, that is, the xy value, and then return the result.

Return Value:

Returns the y Power of x.

9. sin (x) returns the sine of x (radians ).

Function Description:

Sin () is used to calculate the positive and negative values of parameter x and return the result.

Return Value:

Returns the calculation result between-1 and 1.
10. sqrt (x) calculates the square root of x.

11. Search for arccosine of acos (x)

Function Description:

Acos () is used to calculate the arc cosine of parameter x and return the result. The range of parameter x is-1 to 1. If the range is exceeded, it will fail.

Return Value:

Returns the computation result between 0 and PI, in radians. The angle in the function library is expressed in radians.

12. asin (s) returns the arc sine.

Function Description:

Asin () is used to calculate the arcsin value of parameter x and return the result. The range of parameter x is-1 to 1. If the range is exceeded, it will fail.

Return Value:

Returns the computation result between PI/2 and PI/2.

13. atan (x)

Function Description:

Atan () is used to calculate the arc tangent value of parameter x and return the result.

Return Value:

Returns the calculation result between-PI/2 and PI/2.

14. atan2 (x)

Function Description:

Atan2 () is used to calculate the arc tangent value of the y/x parameter and return the result.

Return Value:

Returns the calculation result between-PI/2 and PI/2.

15. exp (computing index)

Function Description:

Exp () is used to calculate the x power value based on e, that is, the ex value, and then return the result.

Return Value:

Returns the x power of e.

16. frexp (float data is divided into base data and index data)

Function Description:

Frexp () is used to cut the Floating Point Number of parameter x into a base number and an index. The base part is directly returned, and the exponent part is returned by the exp pointer of the parameter. The return value is multiplied by the exp power of 2, that is, the x value.

Return Value:

Returns the base part of x, and the exponent part is stored in the address indicated by the exp pointer.

# Include <stdio. h> # include <math. h>

Copy codeThe Code is as follows: main ()
{
Int exp;
Double fraction, I;
Fraction = frexp (1024, & exp );
I = ldexp (fraction, exp );
Printf ("exp = % d \ n", exp );
Printf ("fraction = % f \ n", fraction );
Printf ("I = % f", I );
}

17. ldexp (calculate the power of 2)

Function Description:

Ldexp () is used to multiply x by the exp power of 2, that is, x * 2exp.

Return Value:

Returns the calculation result.

/* Calculate 3*(2 ^ 2) = 12 */

# Include <stdio. h>

# Include <math. h>

Copy codeThe Code is as follows: main ()
{
Int exp;
Double x, answer;
Answer = ldexp (3, 2 );
Printf ("3*2 ^ (2) = % f \ n", answer );
}

18. log (calculate the logarithm value based on e)

Function Description:

Log () is used to calculate the number of x pairs based on e and return the result.

Return Value:

Returns the natural logarithm of parameter x.

# Include <stdio. h> # include <math. h>

Copy codeThe Code is as follows: main ()
{
Double answer;
Answer = log (100 );
Printf ("log (100) = % f \ n", answer );
}

19. log10 (base-10 logarithm values)

20. sinh (take the hyperbolic positive Xuan function value)

Function Description:

Sinh () is used to calculate the hyperbolic positive Xuan value of parameter x and return the result. The mathematical definition is: (exp (x)-exp (-x)/2.

Return Value:

Returns the hyperbolic Xuan value of parameter x.

# Include <stdio. h> # include <math. h>

Copy codeThe Code is as follows: main ()
{
Double answer = sinh (0.5 );
Printf ("sinh (0.5) = % f \ n", answer );
}

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.