Home Bio Freeware Programming Disclosures   Subscribe via: ( Email / RSS )
 

Doing Math in Objective C

0 Comments
Written by Orville Chomer
 
Topics: Math, Objective C, Programming


One thing you will find you need to do in any programming language is do math. Here are some useful math functions for the Objective C language. I give a little bit of a comparison to Visual Basic for those who know that language. They are provided in no special order:

  • fabs() – Gets the absolute value of the value in parentheses. Works like ABS() function in Visual Basic. fabs(-123) = 123, fabs(34) = 34.
  • ceil() – Find the ceiling integer. Kind of like rounding up. Same as INT(x+1) in Visual Basic.  ceil(3.1) = 4.
  • floor() – Find the floor integer. Kind of like rounding down. Same as INT(x) in Visual Basic. floor(3.6) = 3.
  • exp() – Find the exponential value.
  • pow() – Raise a number to the power. pow(3,6) = 3^6 in Visual Basic.
  • rand() – Generate a pseudo random number. Function is RND(x) in Visual Basic. A good discussion on random numbers in Objective C can be found here.
  • srandom() – Generate a seed for the random number generator. This is done with the Randomize statement in Visual Basic.
  • sqrt() – Find out the square root of a number. sqrt(x) = x^(1/2) in Visual Basic.

Posted on January 21, 2011

No Responses »

No responses yet.

RSS feed for comments on this post. TrackBack URL

Leave a Comment or a Question


Comment Rules: How should a person with some class be? Cool. That's how we're gonna be -- cool. Critical is fine, but if you're rude, we'll delete your stuff. Please use your PERSONAL name or initials and not your business name and do not put your website in the comment text, as both come off like spam. Have fun and thanks for adding to the conversation!




Get Adobe Flash playerPlugin by wpburn.com wordpress themes