(Comp.sys.handhelds)
Item: 3432 by _joehorn at hpcvbbs.UUCP
Author: [Joseph K. Horn]
Subj: HP 48 Yards.FeetInches
Date: Tue Jun 11 1991
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?
It would sure shrink and speed up a lot of programs.
Thanx.
BTW, just in case it helps or amuses, here's the inverse function:
+-----------------------------------------+
| ->HMS(x) = x - .4*FP(x) - .004*FP(x*60) |
+-----------------------------------------+
-- Joe Horn --
----------
Resp: 1 of 2 by bson at rice-chex.ai.mit.edu
Author: [Jan Brittenson]
Date: Thu Jun 13 1991
How about:
YFI->(x) = x + FP(x) * 7/3 + FP(x*10) * 22/9
Where YFI is:
y.fii
I.e. 1 yard, 2 feet, 5 inches = 1.205
So, how does it work? Pretty simple actually. The first term maps
the integer part 1:1 (no conversion necessary). But it also maps the
.f and ..ii parts 1:1, so they need some adjustment. Feet map 1:0.3, so
as far as feet are concerned we fulfill the following equation to get
the feet back in line:
1 = 0.3 + 0.3 * k ==> k = (1-0.3)/0.3 = 7/3
So we now have:
YFI->(x) = x + FP(x) * 7/3
Note that we use FP() since we have already taken care of the
integer part (which mapped 1:1). This also maps the ..ii part, so
again we need to adjust it - we would like it to map 1:0.036 (i.e. 3 *
12in = 1ft):
1 = 0.036 + 0.036 * k + 0.36 * m
==> m = (1-0.036-0.036*7/3)/0.36 = 22/9
So now we have our final term.
YFI->(x) = x + FP(x) * 7/3 + FP(x*10) * 22/9
We multiply by ten and discard the IP to get rid of what is already
mapped. Apologies if this sounds confusing.
-- Jan Brittenson
bson@ai.mit.edu
----------
Resp: 2 of 2 by woodhams at phoenix.Princeton.EDU
Author: [Michael Woodhams]
Date: Thu Jun 13 1991
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.
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.