2010. 4. 26. 14:24
Objective-C 에서 가장 많이 쓰는 수학함수 모음입니다.
ceil() – 올림값
NSLog(@"ceil(1.2) : %0.2f", ceil(1.2)); -> ceil(1.2) : 2.00
NSLog(@"ceil(1.8) : %0.2f", ceil(1.8)); -> ceil(1.8) : 2.00
NSLog(@"ceil(1.2) : %0.2f", ceil(-1.2)); -> ceil(-1.2) : -1.00
NSLog(@"ceil(1.8) : %0.2f", ceil(-1.8)); -> ceil(-1.8) : -1.00
floor() – 버림값
NSLog(@"floor(1.2) : %0.2f", floor(1.2)); -> floor(1.2) : 1.00
NSLog(@"floor(1.8) : %0.2f", floor(1.8)); -> floor(1.8) : 1.00
NSLog(@"floor(1.2) : %0.2f", floor(-1.2)); -> floor(-1.2) : -2.00
NSLog(@"floor(1.8) : %0.2f", floor(-1.8)); -> floor(-1.8) : -2.00
fabs() – 절대값
NSLog(@"fabs(1.2) : %0.2f", fabs(1.2)); -> fabs(1.2) : 1.20
NSLog(@"fabs(1.8) : %0.2f", fabs(1.8)); -> fabs(1.8) : 1.80
NSLog(@"fabs(1.2) : %0.2f", fabs(-1.2)); -> fabs(-1.2) : -1.20
NSLog(@"fabs(1.8) : %0.2f", fabs(-1.8)); -> fabs(-1.8) : -1.80
sqrt() - 루트값
NSLog(@"sqrt(4) : %0.2f", sqrt(4)); -> sqrt(4) : 2.00
pow(x, y) - 거듭제곱근 (x의 y승)
NSLog(@"pow(2, 10) : %0.2f", pow(2, 10)); -> pow(2, 10) : 1024.00
exp() – 지수값
NSLog(@"exp(1) : %0.2f", exp(1)); -> exp(1) : 2.72
유용한 Define 값
#define M_E 2.71828182845904523536028747135266250 /* e */
#define M_LOG2E 1.44269504088896340735992468100189214 /* log 2e */
#define M_LOG10E 0.434294481903251827651128918916605082 /* log 10e */
#define M_LN2 0.693147180559945309417232121458176568 /* log e2 */
#define M_LN10 2.30258509299404568401799145468436421 /* log e10 */
#define M_PI 3.14159265358979323846264338327950288 /* pi */
#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
#define M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
#define M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
#define M_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */
#define M_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */
#define M_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
더 많은 정보는 math.h 파일에서 확인 할 수 있습니다.