FX-602P Program for Decimal to Fractions Conversion

Description

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 using the FX-602P's alphabetic display feature if the answer is other than a number. The underlying numeric number is the answer in decimal form. GOTO 6 will redisplay the answer which may be necessary if the answer is larger than the screen.

Example

Determine 22/7 3 and then add 3/8 and then divide by 2. Negate and add 4 to show negative displays of values with and without integer part. Generate 10000001/1000 and redisplay last answer.

Data Input Operation Read-out Remark
Mode 1 0. Reset
2273 P4 9 3/7. Do calculation as normal but press P4 instead of (or after) =. Answer is interpreted as 93/7
+38 EXE 9 45/56. 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 101/112 Answer is 4100/112
+/- EXE -4 101/112 Answer is -4100/112
+ 4 EXE -101/112 Answer is -100/112
1 EXP 6 + 1EXP3-/+ EXE 1000000 1/1 Starts displaying answer 10000001/1000 with alpha enunciator flashing
0000 1/1000 Ends displaying answer after scrolling
GOTO 6 1000000 1/1 Redisplays answer
0000 1/1000 Ends displaying answer after scrolling

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, =, , Min05, INV INT, Min07, 1, , INV FRAC, INV RND 0, Min08, INV ABS, MinF, 1, =, INV FRAC,-, 1,INV X<->Y, INV ABS, =, INV RND 0, Min04, INV x>=F, GOTO 1, MR08, INV x=F, GOTO 2, MR04, +/-, Min04, Breaks number into integer and fractional components. See Note 1
LBL 1, MR08, INV x=0, GOTO 7, Min04, Trap for no fractional component
LBL 2, 9, 9, INV 10x, Min09, , , MR08, =, Min08, MR04,=, Min04, AC, Min00, Make numerator and denominator integer values & initialise max possible cancellation value
LBL 3, AC, MR04, , INV ISZ, MR00, =, +, INV FRAC, INV x=0, GOTO 4, GOTO 3 Find divisor for cancellation.
LBL 4, INV X<->Y, , MR09, INV X<->Y, =, INV RND 8, , INV FRAC, INV x=0, GOTO 5, GOTO 3 Attempt cancellation. See Note 2
LBL 5, 1, =, Min09, MR08, , MR04, , MR00, +, ., 5, =, INV INT, Min08, Cancel numerator and denominator.
LBL 6, INV "ALPHA", INV SPACE, INV "SPACE", MR07, x=0, GOTO 7, INV "ALPHA", AR07, INV SPACE, INV "ALPHA", GOTO 8, Start generating output display by clearing any old alpha string. Test integer part of number and if zero don't include it in the display otherwise start building display with integer part.
LBL 7, MR09, x>=0, GOTO 8, INV "ALPHA", -, INV "ALPHA" Test numerator for being non-negative. If negative start fraction only display with '-' sign.
LBL 8, MR09, INV ABS, INV "ALPHA", INV ;, AR08,INV /,INV #, INV "ALPHA", MR07, +, xbar, =, INV "ALPHA", INV ;, INV "ALPHA", HLT, GOTO 0 Generate fractional part of display value and add it to any part of display generated above. Generate the numeric value and then display the alpha display. Allow loop back to start of program.
Total number of steps = 127
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 120 is purely a compact way of obtaining the result of the numerator/denominator, i.e. M08/M09. (When using the statistical function of the calculator M08 contains Σx & M09 contains n)
Contents in memories
00 counter for attempted cancellation 10 not used
01 not used 11 not used
02 not used 12 not used
03 not used 13 not used
04 value used to cancel 14 not used
05 Value to be converted 15 not used
06 degrees-minutes-seconds display value 16 not used
07 Integer part 17 not used
08 Numerator 18 not used
09 Denominator 19 not used
0F Used variously 1F not used