当前位置: 代码迷 >> 综合 >> [iOS]计算函数
  详细解决方案

[iOS]计算函数

热度:3   发布时间:2024-03-09 20:27:06.0

绝对值

int abs(int i);         // 处理int类型的取绝对值
double fabs(double i);  // 处理double类型的取绝对值
float fabsf(float i);   // 处理float类型的取绝对值

两点之间的距离

// 计算两点之间的距离
- (float)calculateDistanceWithPointOne:(CGPoint)pointOne PointTwo:(CGPoint)pointTwo {CGFloat xDist = (pointOne.x - pointTwo.x);CGFloat yDist = (pointOne.y - pointTwo.y);CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist));return distance;
}

其他

// 随机数
rand()  
// 向下取整
floor() / floorf() / floorl() 
// 向上取整
ceil() / ceilf() / ceill() 
// 四舍五入
round() / roundf() / roundl() 
// 求平方根
sqrt() / sqrtf() / sqrtl() 
// 求最大值
fmax() / fmaxf() / fmaxl()  
// 求最小值
fmin() / fminf() / fminl()  
// 求直角三角形斜边的长度
hypot() / hypotf() / hypotl()  
// 求两数整除后的余数
fmod() / fmodf() / fmodl()  
// 浮点数分解为整数和小数
modf() / modff() / modfl()  
// 浮点数分解尾数和二为底的指数
frexp() / frexpf() / frexpl() 
// 求正弦值 
sin() / sinf() / sinl()  
// 求双曲正弦值
sinh() / sinhf() / sinhl() 
// 求余弦值
cos() / cosf() / cosl() 
// 求双曲余弦值
cosh() / coshf() / coshl()  
// 求正切值
tan() / tanf() / tanl()  
// 求双曲正切值
tanh() / tanhf() / tanhl() 
// 求反正弦值
asin() / asinf() / asinl()  
// 求反双曲正弦值
asinh() / asinhf() / asinhl()  
// 求反余弦值
acos() / acosf() / acosl()  
// 求反双曲余弦值
acosh() / acoshf() / acoshl()  
// 求反正切值
atan() / atanf() / atanl()  
// 求坐标值的反正切值
atan2() / atan2f() / atan2l() 
// 求反双曲正切值
atanh() / atanhf() / atanhl() 

 

  相关解决方案