Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!phoenix.Princeton.EDU!woodhams From: woodhams@phoenix.Princeton.EDU (Michael Woodhams) Newsgroups: comp.sys.handhelds Subject: Re: HP 48 Yards.FeetInches Message-ID: <10737@idunno.Princeton.EDU> Date: 13 Jun 91 23:56:15 GMT References: <2855ad7d:3432comp.sys.handhelds@hpcvbbs.UUCP> Sender: news@idunno.Princeton.EDU Organization: Princeton University Observatory Lines: 43 Nntp-Posting-Host: phoenix.princeton.edu In article <2855ad7d:3432comp.sys.handhelds@hpcvbbs.UUCP> akcs.joehorn@hpcvbbs.UUCP (Joseph K. Horn) writes: >Any mathematicians out there? I need your help. > >All the code I've seen written to handle Feet.Inches pulls the number >apart into its int and frac parts, handles them, and then recombines. > >But some years ago, this algorithm for Hours.MinSec was published: > > +-----------------------------------------+ > | HMS->(x) = x + FP(x)/1.5 + FP(x*100)/90 | > +-----------------------------------------+ > >The fact that it works mystifies me. My question is: If this kind of >algorithm works for H.MS, can similar ones be created for any arbitrary >fractional systems, like Yards.FeetInches? If so, how? HMS->(H.MMSS) = H.MMSS + 0.MMSS/1.5 + 0.SS/90 = H + MM/100 + SS/10000 + MM/150 + SS/15000 + SS/9000 = H + MM(1/100+1/150) + SS(1/10000+1/15000+1/9000) = H + MM/60 + SS/3600 as required. The solution to the yards, feet, inches problem is obvious: use metrics. Let YFI->(Y.FII) convert yards.feet_inches to decimal yards, and assume it is of the form YFI->(x) = x + FP(x)/a + FP(x*10)/b and solve for a and b: YFI->(Y.FII) = Y.FII + 0.FII/a + 0.II/b = Y + F/10 + II/1000 + F/(10*a) + II/(1000*a) + II/(100*b) = Y + F*(a+1)/(10*a) + II*(a*b+b+10*a)/(1000*a*b) = Y + F/3 + II/36 so (a+1)/(10*a) = 1/3 => a=3/7 1/36 = (a*b+b+10*a)/(1000*a*b) = (3*b/7+b+30/7)/(3000*b/7) = (3*b+7*b+30)/(3000*b) = (b+3)/(300*b) => b=9/22 so YFI->(x) = x + FP(x)*7/3 + FP(x*10)*22/9 The reverse transformation is left as an exercise for the student.