3 ms·
Continued fractions are quite awesome. Gospers monograph, which is also mentioned in the article, is quite readable: https://perl.plover.com/classes/cftalk/INFO
by rustybolt 5y ago
Continued fractions are quite awesome. Gospers monograph, which is also mentioned in the article, is quite readable: https://perl.plover.com/classes/cftalk/INFO/gosper.txt https://perl.plover.com/classes/cftalk/INFO/gosper.txt
One thing to watch out for is that when you compute floor(sqrt(2) * sqrt(2)), the computation will never finish. The reason is that continued fractions only compute approximations, so the approximation will only tell you that the result is very close to 2, but it might still be slightly above or below 2. That is, unless you implement some logic to deal with repeating coefficients, but then you will have the same problem with 1/pi times pi, for example.
- deleted 5y ago[deleted]
- enriquto 5y agoif you are amazed by continued fractions, your head will explode with continued logarithms
- lupire 5y agoTrue, but why would you need a floor? It's a rather arbitrary function.
- cdsmith 5y agoIt's actually worse than that. Even knowing the very first term of the continued fraction result would already tell you that the number is at least 2. So the computation will hang without ever producing even a single term. This is a fundamental problem shared by any form of exact real arithmetic with unique representations; you can always then be forced to make a choice, before emitting any information, that depends on infinite amounts of information about the operands. To solve this problem, you would need to choose a representation with redundancy. (With redundancy, equality comparison becomes harder, and it can still diverge, but you can still get approximations of the answer.)