Closed duckworthd closed 12 years ago
Yikes, you're right we're off by quite a bit here. I think the broader question is if we ought to be wrapping some other library where other people have worked out the numerical stability of the function approximations or if we should be redoing that work here. This is originally dlwh's code. Any opinion, David?
For this issue I used another approximation off of wikipedia for erf() and erfi() based on the cited paper.
https://gist.github.com/1520395
More generally though, it seems that the most popular scientific library for Java is Michael Flanagan's. Personally, I don't see any reason not to fall back on a well-tested library for common functions -- the only question is who's willing to implement the necessary changes.
Flanagan's code is a no-go, since it's incompatible with GPL.
I'll patch the code for now and we'll discuss adding another dependency. Commons or Colt seem like the best options.
For example,
scala> Numerics.erf(-0.5) res39: Double = -0.5206970701578215
scala> Numerics.erf(0.0) res40: Double = 1.0
scala> Numerics.erf(0.5) res41: Double = 0.5206970701578215
Numerics.erf(0.0) should = 0.0