Math function */ - how to reverse Multiply Middle
Davetief
Posts: 16
Hi all,
I am trying to figure out how to do this -
I have this calculation in a program: F = K */ $01CC
Example 53988 = 30046 */ $01CC
In another part of the program, I need to do the reverse of this calculation. The question is how? Using / doesn't work.
I am trying to figure out how to do this -
I have this calculation in a program: F = K */ $01CC
Example 53988 = 30046 */ $01CC
In another part of the program, I need to do the reverse of this calculation. The question is how? Using / doesn't work.
Comments
You lose the bottom 8-bits with the multiply middle operator and you can't get them back unless you preserved in some other way.
So in your example, $01CC will end up just $0100.
If this doesn't answer your question, can you give an example with the above numbers of what you want to do?
K = F */ $008F
30157 = 53988 */ $008F which is close but not exactly the original 30046 due to rounding in determining $008F
To get $008F, take $01CC, and convert to decimal: 1 + 204/256 = 1.79687.
1/1.79687 = 0.55652 and that times 256 is 142.46956. Round up to 143 and convert to hex gives $008F, your new divisor.
Maybe the inverse you want is 256/460. Calculate: factor = 256 * (256/460) = 142. Then x = y */ 142. Note that 142/256 = 256/460 approximately, the best that can be done with 256 as an implicit denominator.
53988 */ 142 = 29946
which is close to your starting value, 30046. Not exact, because there are a couple of round-offs involved.
PS: Oh, I see you got a quick shower of answers!
Edit: I fixed the link. The URL tag was missing a quote.
460/256 = 1 + 204/256 = 1 + 52224/65536, and on the Stamp that becomes,
y = x + (x ** 52224) division by 65536 being implied. The implied fraction involving ** has to be less than one.
30046 + (30046 ** 52224) = 53988
The inverse is 256/460 = 36472/65536, and
x = y ** 36472
53988 ** 36472 = 30045.
Much better inverse, less roundoff.
Here's a direct link to this material on my website, http://emesystems.com/BS2math1.htm
(Thanks Erco!)
Now what did I do again?
Thank you to the others for the other ideas also. I also had tried them before seeing this one. I could have made due, but things will be simpler now.