Post Reply 
(12C) Add or Subtract Fractions
09-27-2018, 04:52 PM (This post was last modified: 09-28-2018 05:44 AM by Dieter.)
Post: #7
RE: (12C) Add or Subtract Fractions
(09-24-2018 05:24 PM)Dieter Wrote:  New calculation: 1/3 – 2/5
1 [ENTER] 3 [ENTER] 2 [ENTER] 5 [R/S]
2 [R/S]
"1" –15

Update: there are still a few steps left, so here is a slightly modified version that adds a nicer display of negative results: now the numerator has the sign of the result and the denominator is always positive. So the above example will now be displayed as "–1" 15. The same holds for mixed fractions, so –3 1/4 is returned as "–3" "–1" 4.

Here is the code:

Code:
01 STO 4
02 R↓
03 STO 3
04 R↓
05 STO 2
06 R↓
07 STO 1
08 CLX
09 R/S
10 1
11 -
12 X=0?
13 GTO 27
14 1
15 -
16 X=0?
17 GTO 29
18 1
19 -
20 X=0?
21 GTO 41
22 1
23 -
24 X=0?
25 GTO 44
26 GTO 08
27 RCL 3   add
28 GTO 31
29 RCL 3   subtract
30 CHS
31 RCL 2
32 x
33 RCL 1
34 RCL 4
35 x
36 +
37 RCL 2
38 RCL 4
39 x
40 GTO 51
41 RCL 4   multiply
42 RCL 3
43 GTO 46
44 RCL 3   divide
45 RCL 4
46 RCL 1
47 x
48 X<>Y
49 RCL 2
50 x
51 STO 2   store result
52 X<>Y    in R2 (denominator)
53 STO 1   and R1 (numerator)
54 ENTER   GCD loop starts here
55 ENTER
56 CLX
57 +
58 R↓
59 ÷
60 LstX
61 X<>Y
62 INTG
63 x
64 -
65 X=0?
66 GTO 68
67 GTO 54
68 +
69 STO÷1   reduce
70 STO÷2   fraction
71 RCL 2
72 RCL 2
73 ENTER
74 x
75 √x
76 STO 2   store abs(denominator)
77 ÷       sign(denominator)
78 STOx1   adjust sign of numerator
79 RCL 1
80 PSE     display numerator
81 RCL 1
82 RCL 2
83 R/S     display denominator
84 X=0?
85 GTO 87  if input was zero, convert to mixed fraction
86 GTO 01  else continue calculation with new data
87 RCL 1
88 RCL 2
89 ÷
90 INTG
91 PSE
92 RCL 2
93 x
94 RCL 1
95 X<>Y
96 -
97 PSE
98 GTO 81

I think it won't get much better now.
There's still room for one more step. You may use this to add a FIX 0 (f 0) somewhere. ;-)

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


Messages In This Thread
(12C) Add or Subtract Fractions - Gamo - 09-17-2018, 05:49 AM
RE: (12C) Add or Subtract Fractions - Gamo - 09-19-2018, 07:55 AM
RE: (12C) Add or Subtract Fractions - Dieter - 09-27-2018 04:52 PM
RE: (12C) Add or Subtract Fractions - Gamo - 09-25-2018, 02:36 AM



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