4 ms·
His Gamma function is even worse than I said above, because not only does it have a bug, it doesn't work at all for negative numbers, which was his big bolded c
by weichi 16y ago
His Gamma function is even worse than I said above, because not only does it have a bug, it doesn't work at all for negative numbers, which was his big bolded complaint about the original implementation. I'm embarrassed that I didn't see this at first, because it should be really obvious - the approximation would be taking the square root of a negative number!
I know he would have caught these bugs had he needed to implement these for a real system. But there is nevertheless an important point here. He is 100% right that over-architecting is a bad idea, and that correctness is more important than architecture. But complaining about a factorial function not handling negative numbers, and then "fixing" the problem by implementing the Gamma function, is doing the same thing all over again. It's really easy to fix the factorial implementation to do something reasonable for negative numbers; it's much harder to implement a Gamma function that works for all input. Why bother unless you really have to?