Post Reply 
(12C) Decimal to Fraction
08-07-2018, 11:38 AM (This post was last modified: 08-07-2018 11:51 AM by Dieter.)
Post: #6
RE: (12C) Decimal to Fraction
(08-07-2018 01:19 AM)Albert Chan Wrote:  Can the code changed to limit size of denominator instead ?

Here is a version that does it:

Code:
01 STO 0
02 STO 1
03 0
04 STO 2
05 1
06 RCL 0
07 INTG
08 RCL 2
09 x
10 +
11 RCL n
12 X<>Y
13 x≤y?
14 GTO 25
15 RCL 2
16 RCL 2
17 RCL 0
18 x
19 ,
20 5
21 +
22 INTG
23 STO 1
24 GTO 00
25 STO 2
26 R↓
27 R↓
28 RCL 2
29 X<>Y
30 RCL 1
31 FRAC
32 1/x
33 STO 1
34 GTO 07

Set the max. denominator using the 12C's [n] key.

Example:
Approximate pi with denominators up to 100 and 200.

100 [n]
3,141592654 [R/S] => 22 [X↔Y] 7

200 [n]
3,141592654 [R/S] => 355 [X↔Y] 113

Try √2 with at most six digits in numerator plus denominator.
This means the largest denominator is 999/√2 = 706,...

706 [n]
2 [√x] [R/S] => 577 [X↔Y] 408

[÷] => 1,414215686

BTW, on exit the numerator and denominator are stored in R1 and R2. The higher stack levels (Z and T) hold the next higher (better) denominator, i.e. the first one that exceeds the set limit. For the last example this is 985.

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


Messages In This Thread
(12C) Decimal to Fraction - Gamo - 08-06-2018, 12:33 PM
RE: (12C) Decimal to Fraction - Dieter - 08-06-2018, 08:44 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:29 AM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 01:02 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018 11:38 AM
RE: (12C) Decimal to Fraction - Gamo - 08-07-2018, 09:29 AM
RE: (12C) Decimal to Fraction - Joe Horn - 08-07-2018, 06:28 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:10 PM
RE: (12C) Decimal to Fraction - Joe Horn - 08-08-2018, 12:28 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 07:04 PM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 09:27 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 09:44 PM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 12:51 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 07:46 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 08:09 AM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 09:16 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 10:30 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 12:28 PM
RE: (12C) Decimal to Fraction - Gamo - 05-07-2019, 01:44 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 07:06 PM



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