Post Reply 
(11C) Arithmetic with Fractions
09-17-2018, 04:04 PM (This post was last modified: 09-19-2018 05:09 PM by Albert Chan.)
Post: #11
RE: (11C) Arithmetic with Fractions
(09-17-2018 01:12 AM)Albert Chan Wrote:  Hi, Thomas Klemm,

Thanks for the link to Kahan paper. I tried it, it work perfectly.

However, Kahan's example does not shown the algorithm's power.
Doing the math as fixed fraction already avoid the overflow problem ...

I made up a better example, to show Kahan's algorithm, where mixed fraction trick won't work:

M/N = 1234567/12345648 - 635720/6357263

From Kahan's paper: (using HP-12C, with my Mod/Gcd program)
G = gcd(12345648, 6357263) = 181
b = 12345648 / 181 = 68208
d = 6357263 / 181 = 35123
a = 1234567 % 181 = 147
c = 635720 % 181 = 48
ad - bc = 147*35123 - 68208*48 = 1889097 = 181 * 10437
g =gcd(G, ad - bc) = 181

M = 10437 + Det({{6820, 68208}, {3512, 35123}}) = 10437 - 7636 = 2,801
N = G/g * b * d = 68208 * 35123 = 2,395,669,584
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) Arithmetic with Fractions - Gamo - 09-15-2018, 07:02 AM
RE: (11C) Arithmetic with Fractions - Albert Chan - 09-17-2018 04:04 PM
RE: (11C) Arithmetic with Fractions - Gamo - 09-17-2018, 03:47 AM
RE: (11C) Arithmetic with Fractions - Gamo - 09-17-2018, 09:40 AM
RE: (11C) Arithmetic with Fractions - Gamo - 09-22-2018, 06:33 AM



User(s) browsing this thread: 1 Guest(s)