#!/usr/local/bin/bc -l funcs.bc cf.bc ### CF_MISC.BC - Miscellaneous functions separated from CF.BC ## CF Alteration ## # Take the absolute value of all terms in pbv array cf__[] # . WARNING: This irrevocably changes the array! define cf_abs_terms(*cf__[]) { auto i,t,changed; .=check_cf_max_(); changed=0; for(i=0;i CF conversion ## # Minkowski Question Mark function - Inverse of Conway Box # . Treat the fractional part of x as a CF and transform it into a # . representation of alternating groups of bits in a binary number define cf_question_mark(cf__[]) { auto os,n,i,b,x,t,tmax,sign,c; .=check_cf_max_(); tmax=A^scale sign=1;if(cf__[0]<0)sign=-1 b=0;t=1 for(i=1;i1){.=c++;t/=A} scale=c } x=(cf__[0]+sign*x)/1; scale=os return upscale_rational(x); } # As above but only generates a CF as intermediary define question_mark(x) { # returns ?(x) auto cf[]; .=cf_new(cf[],x) return cf_question_mark(cf[]) } # Conway Box function - Inverse of Minkowski Question Mark # . Transform the fractional part of x by making a CF from a run-length # . encoding of the binary digits, and using that as the new fractional part define cf_conway_box(*cf__[],x) { # cf__[] = [[_x_]] auto os,f[],max,p,i,b,bb,n,j,ix,sign,which0; os=scale;scale+=scale x=upscale_rational(x) max=A^os;p=1 sign=1;if(x<0){sign=-1;x=-x} x-=(b=int(x));cf__[0]=sign*b b=0 n=1;j=1 for(i=0;i<=cf_max&&i