Objective-C 常用函数和常数例表

算术函数
【算术函数】

函数名 说明
[b]int rand()[/b] 随机数生成。
(例)
srand(time(nil)); //随机数初期化
int val = rand()%50; //0~49之间的随机数

[b]int abs(int a) [/b] 整数的绝对值
(例)int val = abs(-8);
 →8
※浮点数的时候用fabs。

[b]double fabs(double a)[/b] 浮点数的绝对值
(例)double val = fabs(-12.345);
 →12.345
※整数的时候用abs。

[b]double floor(double a) [/b] 返回浮点数整数部分(舍弃小数点)
(例)double val = floor(12.345);
 →12.000

d[b]ouble ceil(double a);[/b] 返回浮点数整数部分(舍弃小数点部分,往个位数进1)
(例)double val = ceil(12.345);
 →13.000

[b]double pow(double a, double b)[/b] a的b次方
(例)double val = pow(2, 3);
 →8

[b]double sqrt(double a) [/b] a的平方根
(例)double val = sqrt(2);
 →1.41421356


三角函数

【三角函数】
函数名 说明
[b]double cos(double a) [/b] 余弦函数 (a:弧度)
[b]double sin(double a)[/b] 正弦函数 (a:弧度)
[b]double tan(double a)[/b] 正切函数 (a:弧度)
[b]double asin(double a) [/b] 反正弦值 (a:弧度)
[b]double acos(double a) [/b] 反余弦函数(a:弧度)
[b]double atan(double a)[/b] 反正切函数
[b]double atan2(double a, double b) [/b] 返回给定的 a 及 b 坐标值的反正切值


指数函数
【指数函数】
函数名 说明
[b]double log(double a) [/b] 以e 为底的对数值
[b]double log10(double a) [/b] 对数函数log
常数
常数 常数名 说明
M_PI 圆周率(=π)
M_PI_2 圆周率的1/2(=π/2)
M_PI_4 圆周率的1/4(=π/4)
M_1_PI =1/π
M_2_PI =2/π
M_E =e
M_LOG2E log_2(e)
M_LOG10E log_10(e)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值