[Switch] common mathematical functions and constants iOS development of

Description link

Objective-c introduce common functions, constants, variables

Arithmetic Functions

Function name Explanation
int rand() Random number generator. (Example) srand (time (nil)); // random number initialization int val = rand () P; // a random number between 0 to 49
int abs(int a) The absolute value of the integer (e) int val = abs (-8); → 8 ※ float when used fabs.
double fabs(double a) Floating-point absolute value (for example) double val = fabs (-12.345); → 12.345 ※ integer time with abs.
double floor(double a) And the floating point integer part (decimal discarded) (Example) double val = floor (12.345); → 12.000
double ceil(double a); And the floating point integer part (decimal part discarded, to enter digit 1) (Example) double val = ceil (12.345); → 13.000
double pow(double a, double b) a power of b (Example) double val = pow (2, 3); → 8
double sqrt(double a) a square root of (e) double val = sqrt (2); → 1.41421356

Trigonometric functions

Function name Explanation
double cos(double a) Cosine function (a: radian)
double sin(double a) Sine function (a: radian)
double tan(double a) Tangent function (a: radian)
double asin(double a) Arcsine (a: radian)
double acos(double a) Inverse cosine function (a: radian)
double atan(double a) Arc tangent function
double atan2(double a, double b) Returns the given coordinate values ​​of a and b arctangent

Exponential function

Function name Explanation
double log(double a) Logarithm to the base e
double log10(double a) Logarithmic function log

constant

Constant name Explanation
M_PI Pi (= π)
M_PI_2 Pi 1/2 (= π / 2)
M_PI_4 Pi 1/4 (= π / 4)
M_1_PI = 1 / p
M_2_PI = 2 / n
M_E =e
M_LOG2E log_2(e)
M_LOG10E log_10(e)

Guess you like

Origin www.cnblogs.com/wgb1234/p/12544406.html