Objective-c arithmetic functions and constants represent

Source: Internet
Author: User

not change
constant Name Description
M_pi Pi (=π)
M_pi_2 1/2 of Pi (=Π/2)
M_pi_4 1/4 of Pi (=Π/4)
M_1_pi =1/π
M_2_pi =2/π
M_e =e
m_log2e Log_2 (e)
m_log10e Log_10 (e)

arithmetic Functions
Name of function Description
int rand () Random number generation.
Cases
Srand (Time (nil)); Initial random number initialization
int val = rand ()%50; Random number between 0~49
int abs (int a) Absolute value of an integer
(example) int val = ABS (-8);
→8
* Use fabs when floating-point numbers.

Double Fabs (Double A) Absolute value of floating-point numbers
(example) Double val = fabs (-12.345);
→12.345
※the whole number is used abs.
Double floor (Double a) Returns the integer portion of a floating-point number (discarding a decimal point)
(example) Double val = floor (12.345);
→12.000
Double Ceil (double A); Returns the integer portion of a floating-point number (discards the decimal point and enters 1 digits)
(example) Double val = ceil (12.345);
→13.000
Double Pow (double A, double b) A's B-square
(example) Double val = Pow (2, 3);
→8
Double sqrt (double A) Square root of a
(example) Double val = sqrt (2);

→1.41421356

Objective-c arithmetic functions and constants represent

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.