function CF(){   this.cf=new Array();   this.cfperiodLWB=-1;this.cfperiodUPB=-1;   this.cvgt=new Array();  //this.cvgtUPB=-1;  // Array cf may be longer (long period) or shorter than array cvgt   this.stopped=false; this.cfOFLO=false;   this.cvgt[-1]=new RAT(1,0,'bot0'); };      CF.prototype.append=       function(cfterm){        if(cfterm<0)HALT("CF terms must be positive");       if(this.cf.length>100){this.cfOFLO=true;return}       this.cf[this.cf.length]=cfterm;       if(this.cvgt.length==0){this.cvgt[0]=new RAT(cfterm,1)}       else if(!this.stopped)            {this.cvgt[this.cvgt.length]=new RAT(this.cvgt[this.cvgt.length-1].top*cfterm+this.cvgt[this.cvgt.length-2].top,                                                 this.cvgt[this.cvgt.length-1].bot*cfterm+this.cvgt[this.cvgt.length-2].bot  );             DBG(cfterm+":"+this.cvgt[this.cvgt.length-1].top+"/"+this.cvgt[this.cvgt.length-1].bot);             this.stopped = (    this.cvgt[this.cvgt.length-1].top/this.cvgt[this.cvgt.length-1].bot                               == this.cvgt[this.cvgt.length-2].top/this.cvgt[this.cvgt.length-2].bot);             if(this.stopped){this.cvgt.length=this.cvgt.length-1;}            };         //cfSHOW(); confirm("cf.len="+this.cf.length+" cvgt.len="+this.cvgt.length);       };CF.prototype.reset=  function(){ this.cf.length=0; this.cvgt.length=0;this.stopped=false; //this.cvgtUPB=-1;               this.cfperiodLWB=-1;  this.cfperiodUPB=-1; this.cfOFLO=false;            };CF.prototype.lastcf=  function(){return this.cf[this.cf.length-1]};CF.prototype.pop=  function(){ if(this.stopped || this.cf.length==0)return;  var x=this.lastcf(); this.cvgt.length=this.cvgt.length-1; this.cf.length=this.cf.length-1;  return x };CF.prototype.altcf= function(){    if(this.stopped || this.cf.length==0 || this.isZero() || this.isPeriodic())return;   var last=this.pop();     if(last==1&&this.cf.length>0)this.append(this.pop()+1)   else{this.append(last-1);this.append(1)} };CF.prototype.isZero=function(){return this.cf.length==1&&this.cf[0]==0};CF.prototype.isPeriodic=  function(){return this.cfperiodLWB!=-1};CF.prototype.cftoString= function(){ //alert("PERIODIC? "+this.isPeriodic()+" "+this.cfperiodLWB+".."+this.cfperiodUPB);   return (this.isPeriodic()            ? this.cf.slice(0,this.cfperiodLWB).join(", ")+(this.cfperiodLWB>0?",":"") +" ["+                 this.cf.slice(this.cfperiodLWB,this.cfperiodUPB+1).join(", ")+"]"            : this.cf.slice(0,this.cvgt.length).join(", ")+(this.stopped ? " ..." :"")          ) };CF.prototype.cvgtstoString=  function(){var s="";  if(this.isPeriodic())       {s="This CF "+(this.cfperiodLWB==0?"is ":"ends with ")+" a repeating pattern: \r"           +this.cftoString().replace(/\[/,(this.cfperiodLWB>0?" then ":" ")).replace(/\]/," repeating for ever")       };   if(s!="")s=s+"\r";   s=s+"Convergents:\r";        //Cf.cvgt.slice(0,this.cvgtUPB+1).join(", ")+(this.stopped?" ...":"");   for(i=0;i<this.cvgt.length;i++)          s=s+justify(this.cf[i],3,'R')+": "+this.cvgt[i]+" = "+this.cvgt[i].top/this.cvgt[i].bot+"\r";   if(this.stopped)s=s+"...\r";   return s};CF.prototype.toRAT=  function(){ //alert("toRAT: "+this.cftoString()+" cvgts end at "+this.cvgt.length-1);   return this.cvgt[this.cvgt.length-1] };CF.prototype.toDec=   function(){return eval(this.toRAT().toString())};CF.prototype.toString=  function(){return this.cftoString()+"\r"+this.cvgtstoString()};CF.prototype.dump=function(){return "===DUMP cf="+this.toString()+    "\r "+this.cvgt.length+"=#cvgt "+(this.cvgt.length==1?this.cvgt[0]:"")+" pLWB="+this.cfperiodLWB+  " pUPB="+this.cfperiodUPB+" stopped="+this.stopped+" OFLO="+this.cfOFLO+" 0?="+this.isZero()+"\r=====\r"};