Post Reply 
(15C) Arithmetic with Fractions
09-23-2018, 05:12 PM (This post was last modified: 09-23-2018 05:14 PM by Dieter.)
Post: #2
RE: (15C) Arithmetic with Fractions
(09-23-2018 09:24 AM)Gamo Wrote:  Program to add, subtract, multiply, divide, simplify to lowest term and
convert to mixed fraction.
...
This program is the updated version from 11C that improve the computation speed by using better GCD algorithm.

So you now got a decent GCD algorithm. That's great, but why does the add/subtract function still use the slow iterative method for calculating the LCM of the two denominators? That's not required as the resulting fraction is reduced anyway in the next step.

And I think there also is an error in this LCM routine:

Code:
LBL 2
+
STO 3   <=== I think this should be STO 5
RCL 2
÷
RCL 1
x
...

But why don't you replace the whole code at LBL B with...

Code:
LBL B
RCL 1
RCL 4
x
RCL 2
RCL 3
x
+
STO 6   <== numerator of result
RCL 2
RCL 4
x
STO 5   <== denominator of result
GSB 5   <== determine GCD
GSB 3   <== reduce fraction (divide by GCD)
X<>Y
RTN

You don't have to determine (very slowly...) the LCM of the two denominators as in the next step the GCD is calculated. So simply set the common denominator to den1*den2. The whole LCM iteration can be removed completety, as shown in the example.

I also think that the lines between LBL 3 and LBL 6 can be removed. At LBL 3 the GCD is in X. The lines at LBL 3 now check whether the GCD is > 1 or not. If not, the fraction is not reduced. But this makes no sense as the GCD always is 1 or greater. So you always divide by the GCD. So I think you can delete all the lines after LBL 3 up to and including LBL 6. Please correct me if I'm wrong or if my interpretation of your program is not correct.

BTW, the division routine can be removed. All you have to do is swap the second numerator and denominator. If you want to stick to the way the program is used (enter data at LBL A), all you have to do is:

Code:
LBL D
RCL 3
RCL 4
STO 3
X<>Y
STO 4
---------------
LBL C
...

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(15C) Arithmetic with Fractions - Gamo - 09-23-2018, 09:24 AM
RE: (15C) Arithmetic with Fractions - Dieter - 09-23-2018 05:12 PM
RE: (15C) Arithmetic with Fractions - Gamo - 09-24-2018, 02:19 AM
RE: (15C) Arithmetic with Fractions - Gamo - 09-25-2018, 02:08 AM
RE: (15C) Arithmetic with Fractions - Gamo - 09-27-2018, 02:14 AM



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