When you spend time programming-world-of-higher-abstraction (Ruby & Python) and then move to a lower level, in this case Objective-C, mistakes are bound to happen. Let me share with you guys one of mine…

It was a sunny friday afternoon, I was trying to fix a glitch in my animation path. To my own happy surprise I discovered that it was fairly simple to plug this hole. All I needed was a special case when a parameter reached angle 0.00000, so of I went with some duck tape and glue (pronounced if-statements) looking something like:
if(curveAmplitude == 0.0f){
//dragon-code
}

To my total surprise the if-statement never turned out to be true. After using my favorite method for discovering how stuff works, trial-and-error, I remembered something about floats & doubles not being reliable. I started reading over the IEEE standard and David Goldberg’s paper “What Every Computer Scientist Should Know About Floating-Point Arithmetic”. As Mr. Goldberg states it all boils down to this:

“Squeezing infinitely many real numbers into a finite number of bits requires an approximate representation. […] the results of a floating-point calculation must often be rounded in order to fit back into its finite representation. The rounding error is the characteristic feature of floating-point computation.”

Thank you Mr. Goldberg for that! Now that the problem is identified it is time for a solution.

Solution:
Add two minimal macros to your source, these macros compares your number to epsilon which is the smallest float available to the system.

#define fEqual(a,b) (fabs((a) - (b)) < FLT_EPSILON)
#define fEqualToZero(a) (fabs(a) < FLT_EPSILON)

Note that if you are into precision this will not get you all the way. There rounding problem is still there, but in most simple cases this is a good-enough-solution.

So little time and so much to code (and even less time for writing blog posts =).

Recently I have submerged myself in the world of Core Animation. Apple has done a great job with this framework. For someone who is graphically challenged this has been a steep uphill battle. One mine I stepped on, was that all the core C math functions really prefer radians over degrees. I wrote the following two helper methods to do this conversion:

- (CGFloat)_degreesToRadians:(CGFloat)degrees{
return degrees * (M_PI / 180);
}
- (CGFloat)_radiansToDegrees:(CGFloat)radians{
return radians * (180 / M_PI);
}
Sorry about the code formatting. I will look for a wordpress plugin to help with this.
See you next time…

Let me initiate these posts by saying that any error included are most probably the result of my mistakes and not of the Evengelists from Apple. And if anyone has been offended in some way (I really hope this will not happen since I am writing about software development and not religion) I humbly apologize. Now, lets get started.

Read the rest of this entry »

I should start of by giving creds to my boss who let me travel all the way to Hamburg just to attend the annual Apple Tech Talk event. As someone working in the mobile industry this was a trip full of inspiration. I made an attempt of sharing my experience with the world on twitter. Though after struggling with how twitter subjects work, Apple spared me from my misery but messing up the wifi. 🙂

The talks began with an introductory talk and some numbers. An exclude of these were:

  • 2 billion+ apps downloded.
  • 50 million+ devices sold (iPhone and iPod Touch).
  • 100.000+ unique apps on the App Store.
  • 125.000+ registered developers.

You can say what you want about Apple, but those are some impressive numbers. The talk went on with praising some really cool apps out there:

  • Peaks – Which uses augmented reality to present information about a mountain peak.
  • Zipcar – Let’s you locate and interact with rentable cars. Check out this vid.
  • Snaptell – Which locates commercial products from a photo.
  • These also deserve some attention: postage timetuner tweetie2 1112 ocarina roambi things.

There were loads of talk available during the conference, I decided to attend these:

  • Interface Design by Eric Hope.
  • In App Purchase by Mark Malone.
  • Core Data by Michael Jurewitz.
  • Optimizing Your App by Michael Jurewitz.
  • Application Performance by Michael Jurewitz.

I will try to summarize my notes and post them on this blog within a few days. I did not expect the talks to go into as much detail as they did, this was a welcome surprise to me. Don’t get shocked if you stumble upon some code in the coming posts.

 

 

The purpose of this blog is solely a tool for myself, to record and organize my ongoing learning process called life. If while doing this, a confused soul as myself can learn from my mistakes than all the better.
I will primarily touch on subjects regarding programming or closely related to this. Though I tend to get quite philosophical from time to time.

Any who, let’s get started!