iOS中的round/ceil/floorf函数略解及常用的一些宏

extern float ceilf(float);

extern double ceil(double);

extern long double ceill(long double);

 

extern float floorf(float);

extern double floor(double);

extern long double floorl(longdouble);

 

extern float roundf(float);

extern double round(double);

extern long double roundl(longdouble);

 

round:如果参数是小数,则求本身的四舍五入。

ceil:如果参数是小数,则求最小的整数但不小于本身.

floor:如果参数是小数,则求最大的整数但不大于本身. 

 

Example:如何值是1.6的话,则

1.6 -- round 2.000000

    -- ceil 2.000000

    -- floor 1.00000

 

 

 

常用的一些宏

【算术函数】
函数名说明
int rand()随机数生成。
(例)
srand(time(nil)); //随机数初期化
int val = rand()P; //0~49之间的随机数
int abs(int a)整数的绝对值
(例)int val = abs(-8);
 →8
※浮点数的时候用fabs。
double fabs(double a)浮点数的绝对值
(例)double val = fabs(-12.345);
 →12.345
※整数的时候用abs。
double floor(double a)返回浮点数整数部分(舍弃小数点)
(例)double val = floor(12.345);
 →12.000
double ceil(double a);返回浮点数整数部分(舍弃小数点部分,往个位数进1)
(例)double val = ceil(12.345);
 →13.000
double pow(double a, double b)a的b次方
(例)double val = pow(2, 3);
 →8
double sqrt(double a)a的平方根
(例)double val = sqrt(2);
 →1.41421356

三角函数

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

指数函数

【指数函数】
函数名说明
double log(double a)以e 为底的对数值
double log10(double a)对数函数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_LOG2Elog_2(e)
M_LOG10Elog_10(e)
 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值