This program completes any pending calculation and then takes the number from the x-register (i.e.what would be on the screen) and converts the number to an integer and vulgar fraction... or tries to. Don't expect an answer in any sensible time frame if the number input is pi! Owing to the need to deal with infinite length decimals such as thirds there is a certain amount of approximation in the program, so it is possible for the wrong answer to be obtained. (Changing the approximation factor enables the program to produce approximate results to irrational numbers. See Note 2)
The number is displayed, if possible, using the degrees-minutes-seconds display. If this display is used then typing any of the 4 arithmetic buttons (×,÷,+ or -) or the equals button (=) collapses a pending calculation to return the decimal value entered. If the answer cannot be displayed using the degrees-minutes-seconds display then a sequence separated by pauses is used that shows the decimal is returned followed by the integer part, the numerator part and the denominator part and finally the calculated decimal. If the display is missed it can be recalled by entering GOTO 6. If the input is purely an integer then this is returned.
Determine 22/7 × 3 and then add 3/8 and then divide by 2. Redisplay last answer. Negate and then double.
Data Input Operation | Read-out | Remark |
---|---|---|
Mode 1 | 0. | Reset |
22÷7×3 P4 | 9o3o7. | Do calculation as normal but press P4 instead of (or after) =. Answer is interpreted as 93/7 |
+3÷8 EXE | 9o45o56. | Continue calculation. Once program has been started and HLT is displayed, EXE can be used instead of P4. Answer is interpreted as 945/56 |
÷2 EXE | 4.901785714 | Answer as a decimal followed by a pause.
Numerator & denominator of answer 4101/112 is too large to display using the degrees-minutes-second display so answer is displayed in parts separated by pauses |
4. | Integer part followed by a pause | |
101. | Numerator part followed by a pause | |
112. | Denominator part followed by a pause | |
4.901785714 | Full answer in decimal form for continued use | |
GOTO 6 | 4.901785714 | Redisplay last value using pauses |
4. | Integer part | |
101. | Numerator part | |
112. | Denominator part | |
4.901785714 | Full answer in decimal form for continued use | |
+/- EXE | −4.901785714 | Negate |
-4. | Integer part | |
101. | Numerator part | |
-112. | Denominator part is assumed to be negative rather than numerator | |
−4.901785714 | Full answer in decimal form for continued use | |
×2 EXE | -9o45o56. | -945/56. (Displayed sign applies to both integer and fractional parts) |
Instead of typing in the below, if you've got the cassette adaptor try the *.wav file
Program for Decimal to Fractions Converter | ||
---|---|---|
Program | Remark | |
MODE, 2, | Go to program mode | |
P4 | Abitrary choice of program number | |
LBL 0, | =, ×, Min5, INV INT, Min7, 1, ×, INV FRAC, INV RND 0, Min8, INV ABS, MinF, 1, =, INV FRAC,-, 1,INV X<->Y, INV ABS, =, INV RND 0, Min4, INV x>=F, GOTO 1, MR8, INV x=F, GOTO 2, MR4, +/-, Min4, | Breaks number into integer and fractional components. See Note 1 |
LBL 1, | MR8, INV x=0, GOTO 7, Min4, | Trap for no fractional component |
LBL 2, | 9, 9, INV 10x, Min9, ×, ×, MR8, =, Min8, MR4,=, Min4, AC, Min0, | Make numerator and denominator integer values & initialise max possible cancellation value |
LBL 3, | AC, MR4, ÷, INV ISZ, MR0, =, +, INV FRAC, INV x=0, GOTO 4, GOTO 3 | Find divisor for cancellation. |
LBL 4, | INV X<->Y, ÷, MR9, INV X<->Y, =, INV RND 8, ×, INV FRAC, INV x=0, GOTO 5, GOTO 3 | Attempt cancellation. See Note 2 |
LBL 5, | 1, =, Min9, MR8, ÷, MR4, ×, MR0, +, ., 5, =, INV INT, Min8, GOTO 8, | Cancel numerator and denominator |
LBL 6, | MR5, INV PAUSE, MR7, INV PAUSE, MR8, INV PAUSE, MR9, INV PAUSE, INV xbar, +, | Output answers that can't be output via degrees-minute-second method. See Note 3 |
LBL 7, | MR7, =, HLT, GOTO 0 | Display integer only answer or finish of display of value in paused display. |
LBL 8, | 6, 0, MinF, MR9, INV ABS, INV x>=F, GOTO 6, MR7, +, MR9, ÷, MRF, INV x2, +, INV x>=0, GOTO 9, 0, -, | Determine suitability of numerator for degrees-minute-second and start calculation of display value. Check for negative fraction. |
LBL 9, | MR8, ÷, MRF, =, INV RND 0, Min6, 3, 6, EXP, 6, +/-, INV 1/x, MinF, MR6, INV ABS, INV x>=F, GOTO 6, MR7, +, INV xbar, =, ×, MR6, ÷, MR6, INV degrees-minutes-seconds, HLT, GOTO 0 | Finish display value and display with pending calculation, if value is small enough to display otherwise go to other output code.See Note 2 |
Total number of steps = 155 |
Notes | ||
---|---|---|
1 | To avoid the problem of number truncation to 10 places caused by putting numbers M-registers, the Y-register has been used as a temporary store. (The FX-502P & FX-602P irritatingly throw away accuracy if you put a number in a memory. This truncation applies to both the number put into the M-register and the value in the X-register. The truncation does not happen to the values in the Y & L registers.) The technique is to use a structure like that used above: × ... 1= or × ... 1×. This makes a copy in the Y-register on pressing × and brings it back by multiplying by 1. Between the × and the 1= or 1× the copy can be used to extract the integer and fractional parts of all of the up to 12 digit accuracy of the arithmetic registers. | |
2 | The INV RND 8 at step 70 is a botch to allow cancellation to proceed when cancellation does not quite work. This can happen for recursive fractions. Changing this value for smaller numbers of places allows more approximate answers to be obtained. For instance, various approximations to pi can be achieved for different settings of rounding. | |
3 | The use of INV xbar at step 101 is purely a compact way of obtaining the result of the numerator/denominator, i.e. M8/M9. (When using the statistical function of the calculator M8 contains Σx & M9 contains n) |
Contents in memories | |||
---|---|---|---|
0 | counter for attempted cancellation | .0 | not used |
1 | not used | .1 | not used |
2 | not used | .2 | not used |
3 | not used | .3 | not used |
4 | value used to cancel | .4 | not used |
5 | Value to be converted | .5 | not used |
6 | degrees-minutes-seconds display value | .6 | not used |
7 | Integer part | .7 | not used |
8 | Numerator | .8 | not used |
9 | Denominator | .9 | not used |
F | Used variously | .F | not used |