Math functions in Object-C
2015-03-31 本文已影响13人
Nirvana_icy
- double pow ( double, double ) - power of
NSLog(@"%.f", pow(3,2) ); //result 9 - double sqrt( double ) - square root
NSLog(@"%.f", sqrt(16) ); //result 4 - double ceil ( double ) - if the argument has any decimal part, returns the next bigger integer
NSLog(@"res: %.f", ceil(3.000000000001)); //result 4
NSLog(@"res: %.f", ceil(3.00)); //result 3 - double floor ( double ) - removes the decimal part of the argument
NSLog(@"res: %.f", floor(3.9999999)); - double round ( double ) - rounds the argument
NSLog(@"res: %.f", round(3.46)); //result 3