Ported to Objective-C. It is not thoroughly tested.
Fixed the typo that was causing division to fail. Now appears to work.