I wasn't sure what to title this Question. I tried calculating different forms of a continued fraction, and I found that I get a correct result when I set d to 0 but a wrong result (in the final two terms) if I set d to 0.0
ClearAll["Global`*"];
t = Sqrt[17];
d = 0.0;
n = 11;
a = ConstantArray[0, n];
Do[a[[i]] = Floor[t + d]; t = 1/(t - Floor[t + d]), {i, 1, n}];
a
{4, 8, 8, 8, 8, 8, 8, 8, 8, 7, 4}
I only caught this because I happen to know that this series should end in infinite 8's.
When I try to calculate the form of continued fractions that allows negative terms, I get the correct series from d=1/2 but wrong terms if d=.5. So I gather that this problem has something to do with precision and using rational numbers instead of floats but why is this happening for zero? Is Mathematica adding 0.0 incorrectly?
0.0
) will result in the calculation being done with machine precision. $\endgroup$0
you can get a small speedup from using numbers instead of full symbolic expressions but without sacrificing accuracy. Tryd=0``1
. $\endgroup$d + NestList[1/(# - Floor[# + d]) &, t, 200] // Floor // RepeatedTiming
$\endgroup$