83Plus:Basic:Routines:DecToFrac
From WikiTI
code ;comment ;K can be any real value 1≠round(fPart(K),9 ;check for calc thinking the fractional part=1 K(Ans)+not(Ans)(1+int(K ;if fPart=1, then Ans=int(K)+1, else, Ans=K {Ans,1→L1 ;L1={numerator,denominator If fPart(L1(1 ;if there's a fPart to the numerator... Then {K→L1 ;leave just the numerator in L1 For(C,0,1 ;initiate a loop If 1=round(fPart(L1(dim(L1))),9 ;if the fPart of the last element of L1=1... 1+int(L1(dim(L1→L1(dim(L1 ;the last element of L1=int(last element of L1)+1 augment(L1,{fPart(L1(dim(L1)))^(-1 ;append the inverse of the fPart(last element of L1) to L1 0→C ;force the For loop to repeat upon next End If L1(dim(L1))=int(round(L1(dim(L1)),9 ;if the last element of L1 is an interger... 1→C ;we do NOT want to repeat the loop End ;to loop or not to loop, that is the question For(C,0,dim(L1)-2 ;for each element of L1, except one... dim(L1)-C ;saving memory and preparing to do the work L1(Ans)L1(Ans-1)→L1(Ans-1 ;multiply the last two elements of L1 together End ;L1(1)=numerator, L1(2)=denominator