cflength : 4;
cf([1, 1, 1, 1] - [1, 2, 3, 4]);
=> [0, 4, 3, 2] /* OK */
cf([1, 2, 3, 4] - [1, 1, 1, 1]);
=> [0, - 4, - 3, - 2] /* NOT SO GOOD */
cfdisrep(cf([1, 2, 3, 4] - [1, 1, 1, 1]));
=> 1/(-4+1/(-3+1/(-2)))
''%;
=> -7/30
cf(-7/30);
=> [- 1, 1, 3, 3, 2] /* OK */
cf([1, 2, 2, 2, 2] - [1, 1, 2, 1, 2, 1, 2, 1, 2]);
=> [0, - 3, - 6, 0, - 1, - 40, - 5] /* NOT SO GOOD */
cf(sqrt(3) - 2);
=> [0, - 3, - 1, - 2, - 1, - 2, - 1, - 2] /* NOT SO GOOD */
cf should probably canonicalize its output so that any of the numbers after the first are positive.
Running a noncanonical output through cf again seems to canonicalize it:
cf(args(cf(sqrt(3) - 2)));
=> [- 1, 1, 2, 1, 2, 1, 2, 1, 2] /* OK */
(The args(...) is there to erase the CF flag in the car of the result which would otherwise prevent cf from doing anything.)