It uses the algoritm made by John Kennedy. You can find his article here:

https://begriffs.com/pdf/dec2frac.pdf

It is very fast, and since it only uses named variables, it will not change any registers.

it will however change change the stack.

As an example, i will convert Pi to a fraction. I just enter Pi into the X register and start the program.

The image you see here, is the result. The value in Z is the decimal value of the fraction, and the value in Y and X is the actual fraction.

you can change the accuracy by changing the value in line 37, but the more accurate the fraction gets, the bigger will the numbers, that make up the fraction become.

Code: Select all

```
00 { 154-Byte Prgm }
01▸LBL "FRAC"
02 STO "X"
03 STO "Z1"
04 0
05 STO "D0"
06 1
07 STO "D1"
08▸LBL 00
09 RCL "Z1"
10 FP
11 1/X
12 STO "Z2"
13 IP
14 RCL "D1"
15 ×
16 RCL "D0"
17 +
18 STO "D2"
19 RCL "X"
20 ×
21 0.5
22 +
23 IP
24 STO "N"
25 RCL "D1"
26 STO "D0"
27 RCL "D2"
28 STO "D1"
29 RCL "Z2"
30 STO "Z1"
31 RCL "X"
32 RCL "N"
33 RCL "D2"
34 ÷
35 -
36 ABS
37 1ᴇ-12
38 X<Y?
39 GTO 00
40 CLST
41 RCL "N"
42 RCL "D2"
43 ÷
44 RCL "N"
45 RCL "D2"
46 CLV "X"
47 CLV "Z1"
48 CLV "Z2"
49 CLV "D0"
50 CLV "D1"
51 CLV "D2"
52 CLV "N"
53 END
```