在iOS开发中不可避免的需要使用数学函数进行计算,我们可以使用C标准库头文件中定义的数学常量宏及数学函数来进行基本的数学计算操作,这些C函数都可以在微软的MSDNAPI库中找到。(https://msdn.microsoft.com/zh-cn/library )
strlen(字符串) 计算长度
文/huluo666(简书作者)
原文链接:http://www.jianshu.com/p/8e448e933170
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
一、 iOS常用示例如:
//计算最大值、最小值、绝对值
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#define MIN(A,B) ((A) < (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
//计算scrollView索引
int index = ABS(scrollView.contentOffset.x) / scrollView.frame.size.width;
相关函数申明请查看头文件math.h
二、具体函数释义如下:
/************************************************************
* *
* Math Functions(数学函数) *
* *
***********************************************************/
#pragma mark --- 三角函数 a前缀表示取反 asin反三角函数
//TODO: 求反余弦值
extern float acosf(float);
extern double acos(double);
extern long double acosl(long double);
//TODO: 求反正弦值
extern float asinf(float);
extern double asin(double);
extern long double asinl(long double);
//TODO: 求反正切值
extern float atanf(float);
extern double atan(double);
extern long double atanl(long double);
//TODO: 求坐标值的反正切值
extern float atan2f(float, float);
extern double atan2(double, double);
extern long double atan2l(long double, long double);
//TODO: 求余弦值
extern float cosf(float);
extern double cos(double);
extern long double cosl(long double);
//TODO: 求正弦值
extern float sinf(float);
extern double sin(double);
extern long double sinl(long double);
//TODO: 求正切值
extern float tanf(float);
extern double tan(double);
extern long double tanl(long double);
//TODO: 求反双曲余弦值
extern float acoshf(float);
extern double acosh(double);
extern long double acoshl(long double);
//TODO: 求反双曲正弦值
extern float asinhf(float);
extern