Fibonacci sequence: Difference between revisions

Content added Content deleted
(Add CLU)
Line 6,217:
 
=={{header|jq}}==
{{works with|jq}}
jq does not (yet) have infinite-precision integer arithmetic, and
'''Works with gojq, the Go implementation of jq'''
currently the following algorithms only give exact answers up to fib(78). At a certain point, integers are converted to floats,
 
The C implementation of jq does not (yet) have infinite-precision integer arithmetic, and
currentlyso using it, the following algorithms only give exact answers up to fib(78). At a certain point, integers are converted toBy floatscontrast,
using the Go implementation of jq and the definition of nth_fib given below:
<lang jq>
nth_fib(pow(2;20)) | tostring | [length, .[:10], .[-10:]]
</lang>
yields
<pre>
[219140,"1186800606","0691163707"]
</pre>
in about 20 seconds on a 3GHz machine.
 
Using either the C or Go implementations, at a certain point, integers are converted to floats,
but floating point precision for fib(n) fails after n = 1476:
in jq, fib(1476) evaluates to 1.3069892237633987e+308