3 ms·
This isn't a fair criticism for the C implementation. The output doesn't even remotely fit in a 32-bit int, which is what this implementation is for. "Moderate
by jordigh 13y ago
This isn't a fair criticism for the C implementation. The output doesn't even remotely fit in a 32-bit int, which is what this implementation is for.
"Moderately sized inputs" is a misleading thing to say for a function that grows exponentially. Would you protest that the ones digit in exp(80) is wrong in double-precision IEEE 754 arithmetic?
The formula isn't innacurate. It's simply using data types that can't fit everything. The point of the article is that Binet's formula is something that should at least be mentioned when presenting the classical introductory examples of recursion to programmers. It's unfair to praise simplistic recursive functions without even mentioning that the same result can be obtained in a much more mathematically elegant way.
- kazagistar 13y agoIf you are doing a fib function that is not valid up to an input of 80, you might as well just have a lookup table with 80 values in it. So much for mathematical elegance.
- jordigh 13y agoHow about a fib function that is valid for an input of 40.5? Binet's formula smoothly interpolates the Fibonnaci numbers. Quite elegant! And even without the interpolation, the original formula is accurate enough if you change the return type from int to double. Besides, writing Binet's formula is much shorter in the source code than hardwiring the lookup table. Way more elegant.