I would have expected this code to work in objective C, however its possible that they're handling of data types is a little different.
As this function rely upon several other functions, I would test each of these in turn against the values that the relevant CodeCogs pages give. This should narrow down the problem to one or two functions; we'll then look more closely at what is going on.