Post Reply 
(12C) Decimal to Fraction
08-06-2018, 08:44 PM (This post was last modified: 08-06-2018 08:54 PM by Dieter.)
Post: #2
RE: (12C) Decimal to Fraction
(08-06-2018 12:33 PM)Gamo Wrote:  Program to covert Decimal to Fraction.

This program still need improvement and still not a foolproof routine.
Anyone here got any idea is very welcome.

The program only seems to return a result if the calculated fraction exactly (!) matches the input. But I am not sure if I really understand how it works.

But why don't you simply use the well-known continued fraction method?
Here is an adaptation for the 12C and its limited command set:

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 STO 2
12 RCL 0
12 x
14 ,
15 5
16 +
17 INTG
18 STO 3
19 RCL 2
20 /
21 RND
22 RCL 0
23 RND
24 -
25 x=0?
26 GTO 35
27 R↓
28 RCL 2
29 X<>Y
30 RCL 1
31 FRAC
32 1/x
33 STO 1
34 GTO 07
35 RCL 2
36 RCL 3
37 GTO 00

The program stops if the fraction agrees with the (positive) input when rounded to display precision.

Example:
Determine a fraction that agrees with √2 in four decimals.

FIX 4
2 [√x] [R/S] => 239 [X<>Y] 169
Indeed the quotient is 1,414201183.

Or try pi to six decimals:

FIX 6
3,141592654 [R/S] => 355 [X<>Y] 113

The well known approximation 355/113 = 3,141592920.
That's 3,141593 when rounded to 6 decimals.

Finally your example: what's exactly 3,1416 ?

FIX 9
3,1416 [R/S] => 3927 [X<>Y] 1250

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)