views:

233

answers:

2

Anyone know of a good implementation of this whose license is compatible with non-free iPhone apps?

As suggested in this question, Boost looks absolutely wonderful. But as best I can tell, it is only available in C++.

http://stackoverflow.com/questions/2328258/cumulative-normal-distribution-function-in-c

+2  A: 

So you specifically want an objective-c solution, correct? Because, just in case you were not already aware, you can use C++ libraries within your project.

Jorge Israel Peña
Wow, I didn't know that, I wish I could accept both answers, as both are great.
William Jockusch
No worries. Stephen provided an original answer, I just linked to another question that might have helped you :)
Jorge Israel Peña
+6  A: 

No need for anything fancy. Any platform with a good C99 math library (like the iphone) already has everything you need -- specifically the erfc function, which is a slight variant:

#import <math.h>

double cumulativeNormal(double x) {
    return 0.5 * erfc(-x * M_SQRT1_2);
}

If you don't need double precision, change the doubles to floats, use the erfcf function, and change the literals to single-precision literals.

Remember, Objective-C is an extremely light extension to C. Every C function is an Objective-C function, with no wrapping or other shenanigans required.

Stephen Canon