Objective-C common functions and constants

Source: Internet
Author: User
Arithmetic functions
Arithmetic functions]
Function Name Description
Int rand () Random Number Generation.
(Example)
Srand (Time (NiL); // initial Random Number
Int val = rand () % 50; // 0 ~ Random Number between 49
Int ABS (int) Absolute value of an integer
(Example) int val = ABS (-8 );
→ 8
※Fabs is used for Floating Point.
Double FABS (double) Absolute Value of a floating point
(Example) Double val = FABS (-12.345 );
→ 12.345
※Abs is used for integers.
Double floor (double) Returns the integer part of the floating point number (discard the decimal point)
(Example) Double val = floor (12.345 );
→ 12.000
Double Ceil (double ); Return the integer part of the floating point number (discard the decimal part and enter 1 in the single digit)
(Example) Double val = Ceil (12.345 );
→ 13.000
Double POW (double A, double B) B power of
(Example) Double val = POW (2, 3 );
→ 8
Double SQRT (double) Square root of
(Example) Double val = SQRT (2 );
→ 1.41421356
Trigonometric function
Trigonometric function]
Function Name Description
Double cos (double) Cosine Function (A: radian)
Double sin (double) Sine function (A: radian)
Double Tan (double) Tangent function (A: radian)
Double asin (double) Arcsin (A: radian)
Double ACOs (double) Arccosine function (A: radian)
Double atan (double) Arctangent Function
Double atan2 (double A, double B) Returns the arc tangent of the given coordinate values A and B.
Exponential functions
[Exponential function]
Function Name Description
Double Log (double) Base on E
Double log10 (double) Log of the logarithm function
Constant
Constant
Constant name Description
M_pi Circumference rate (= π)
M_pi_2 1/2 of the circumference rate (= π/2)
M_pi_4 1/4 of the circumference rate (= π/4)
M_1_pi = 1/π
M_2_pi = 2/π
M_e = E
M_log2e Log_2 (E)
M_log10e Log_10 (E)

 

Related Article

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.