Expression of arithmetic functions and constants in objective-C

Source: Internet
Author: User

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)

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 A) absolute value of an integer
(example) int val = ABS (-8);
→ 8
※fabs is used for Floating Point.
double FABS (double A) absolute value of a floating point
(for example, double val = FABS (-12.345);
→ 12.345
※abs is used for integers.
double floor (double A) return the integer part of the floating point number (discard the decimal point)
(example) Double val = floor (12.345);
→ 12.000
double Ceil (double A); return the integer part of the floating point number (discard the decimal part and Add 1 to the single digit)
(example) Double val = Ceil (12.345);
→ 13.000
double POW (double A, double B) B power of a
(example) Double val = POW (2, 3);
→ 8
double SQRT (double A) square root of a
(example) Double val = SQRT (2);

→ 1.41421356

Expression of arithmetic functions and constants in objective-C

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.