(*          Program by Paulo Ney de Souza, December 21, 1989
            desouza@math.berkeley.edu
            Department of Mathematics
            University of California
            Berkeley, CA 94720

        This is a Continued Fractions program for Rational  Numbers that 
        gives the decomposition with  +  instead of  -  and  finishes at 
        the end with no abnormal message like the one in Mathematica.       *)

BeginPackage["`PlusExactContFract`"]

PlusExactContFract::usage = 
        "PlusExactContFract[q] generates the continued fraction 
        representation for the rational number q with + signs."

Begin["`private`"]

PlusExactContFract[x_Rational?Positive] :=
        Block[ { xi, xj = 0, xp = x, r = {} },

                While[  Numerator[xj] != 1 ,
                        xi = Floor[xp] ;
                        AppendTo[r, xi] ;
                        xj = xp - xi ;
                        xp = 1/xj
                     ] ;
                AppendTo[r, xp] ;
                Return [ PlusExactContFract[r] ]
            ]

End[] 
EndPackage[];
