cf(-sqrt(2)) => [1,2] NO
cf(-sqrt(2)),cflength=3 => [1,2,2,2] NO
But those are the CF's for sqrt(2).
(I show the results for cflength=1 and =3 to show
cf(sqrt(2)/sqrt(5)) => [0,1,2,13] NO
cf(sqrt(2)/sqrt(5)),length=3 => [0,1,1,1,2,1,2,4,2,3,4] NO
The correct result (as you can see from cf(sqrt(.4))) is
[0,1,1,1,2] (repeat 1,1,2)
Apparently cf computes the *truncated* CF for sqrt(2)
and the *truncated* CF for sqrt(5) and then combines
That is the wrong way to do it. Gosper's algorithm
(1972) as documented in Hakmem 101B
em101b) and even more clearly in
The strange thing is that CF uses Gosper's algorithm
correctly for finite-length CFs.
Another (unrelated) bug:
[0, 10000000000000000189023153, 2]
as opposed to
cf(1.0b-25) => [0, 10000000000000000000000000]
Compare the correct behavior of
Presumably this has something to do with the weird way
CF is an MFEXPR* to avoid LISTARITH arithmetic....
Log in to post a comment.