Objective-C Math

April 1, 2009 § 4 Comments

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


§ 4 Responses to Objective-C Math

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Objective-C Math at Web Builders.


%d bloggers like this: