Post Reply 
Decimals to improper fractions program?
06-07-2018, 08:58 AM (This post was last modified: 06-07-2018 09:56 AM by Dieter.)
Post: #10
RE: Decimals to improper fractions program?
(06-06-2018 09:12 PM)Dieter Wrote:  The 15C version on that website looks more promising. Here is an adapted (and slightly tweaked) version for the 35s:

Here is an improved version for the 35s that uses two more data registers, but when the program stops to display the current fraction the stack does not have to be preserved. So this version is safer to use. And it allows an additional feature: You can always press the [÷] key to see the approximated value. The upper display line then shows the input so that you can compare both values easily.

I also added an x≠0? test to avoid a zero division error if the fraction exactly matches the input.

Code:
F001  LBL F
F002  STO X
F003  STO C
F004  CLx
F005  STO D
F006  e^x
F007  STO A
F008  RCL C
F009  IP
F010  RCLx A
F011  RCL+ D
F012  x<> A
F013  STO D
F014  RCL C
F015  FP
F016  x≠0?
F017  1/x
F018  STO C
F019  RCL A
F020  x=0?
F021  GTO F008
F022  RCL÷ X
F023  FIX 0
F024  RND
F025  STO B
F026  ALL
F027  RCL X
F028  RCL A
F029  RCL B
F030  STOP
F031  RCL A
F032  RCL÷ B
F033  RCL- X
F034  x≠0?
F035  GTO F008
F036  CLSTK
F037  RTN

When the fraction agrees with the input the next [R/S] now just exits the program with two zeros in the display. If you don't like this replace the final CLSTK with GTO F026, so that after another [R/S] the last fraction is displayed once again. You may also replace all lines from F031 to the end with GTO F008. This will return even more fractions that are even more exact than the previous ones, although the 35s' 12-digit precision cannot show this.

At any time the numerator and denominator can be recalled with RCL A and RCL B.

The original algorithm does not work for input < 1. In such a case you may enter 1/x and swap numerator and denominator.
I now have edited the program so that – I think – this issue is fixed. Try it and see if it works.

The program also works for negative input. Here the minus sign is returned once in the numerator and once in the denominator.

Example:

10 [√x] XEQ F [ENTER]

3
1

[R/S]
19
6

[R/S]
117
37

[R/S]
721
228

Check accuracy now:

[÷]
3,16227766017
3,16228070175

Continue:

[R/S]
4443
1405
...

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


Messages In This Thread
RE: Decimals to improper fractions program? - Dieter - 06-07-2018 08:58 AM



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