Tuesday, January 4, 2011

Objective-C Math

Objective-C is the object oriented version of C. C contains a library of standard Mathematical functions.

Objective-C does support C-based mathematical functions. All C are written for long variable types. Variables are declared long. Functions must be declared long float or double and any contacts must be written in floating point forms. eg. 1 should be written as 1.0.

int i; // long int
double x; // long float

fabs() – Find the absolute value or unsigned value in parentheses

results = fabs(x); // fabs(-1.5) = 1.5

ceil() – Find the ceiling integer; integer just above the value in parentheses; similar to rounding up

i = ceil(x); // ceil(2.5) = 3

floor() – find the integer that is below the floating point value in parentheses

i = floor(x); // floor(2.2) = 2

exp() – find the expoential value

pow() – raise a number to the power

result = pow(x,y); // raise x to the power of y
result = power(4,2); // raise 4 to the square = 16

sqrt() – find the square root of a number

i = sqrt(x); // sqrt(9) = 3

No comments:

Post a Comment

Followers