Post Reply 
Decimals to improper fractions program?
06-07-2018, 11:30 AM
Post: #11
RE: Decimals to improper fractions program?
A slow and stupid - but short for 32SII:
This routine find an estimation of K as P/Q fraction, where P and Q are relative primes and ABS(P/Q-K)<=E, where E is a given error.

Code:
---------------------
LBL Q
  RCL P
  RCL / Q
  RCL - K
  STO D        //D=P/Q-K
  ABS
  RCL E
  X>=Y?        //E>=ABS(D)?
RTN            //Yes, end of the program
  RCL D        
  X<0?         //P/Q<K ?
  GTO P        //Yes, increase P
  1            // No, increase Q
  STO + Q
  GTO Q        
---------------------
LBL P          // Increase P
  1
  STO + P
  GTO Q
---------------------

Checksums:
==========
LBL Q: CK=9676 / 22.5 byte
LBL P: CK=C1C6 / 6.0 byte

Variables:
==========
P, Q, K, E, D

Timing:
=======
| Number (K) | Error (E) | P    | Q   | Number of steps (P-1+Q-1) | Running time | Steps/secs |
| PI         | 1E-5      |  355 | 113 |  466                      |   41.5s      | 11.2/s     |
| SQRT(2)    | 1E-5      |  577 | 408 |  983                      |   86.1s      | 11.4/s     |
| e          | 1E-5      | 1071 | 394 | 1463                      |  129.7s      | 11.3/s     |

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


Messages In This Thread
RE: Decimals to improper fractions program? - Csaba Tizedes - 06-07-2018 11:30 AM



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