**HP 42S & Casio fx-260 Solar: Continued Fractions**

**Introduction**

Let x be a real number. Then x can be represented by the fraction:

x = n_1 + 1/(n_2 + 1/(n_3 + 1/(n_4 + 1/(n_5 + ...))))

The above form is known as a continuous fraction, which can either have a finite set of terms or infinite set of terms. In short form, continuous fractions can be written in a vector form:

x = [ n_1, n_2, n_3, n_4, n_5, ... ]

If you are given a continuous fraction (n_1, n_2, etc.), you can calculate x with the following keystrokes, starting with the last term n_k and working left to n_1:

**RPN Calculators**

1. Start by entering n_k, then press [ 1/x ]

2. Loop: For each n_m for 1 < m < k: enter n_m, [ + ], [ 1/x ]

3. For n_1: Enter n_1, [ + ]

Remember, we are working leftwards.

Example:

Calculate 2 + 1/( 3 + 1/(5 + 1/2)). In other words x = [2, 3, 5, 2]

2 [ 1/x ]

5 [ + ] [ 1/x ]

3 [ + ] [ 1/x ]

2 [ + ]

Result: 81/35 ≈ 2.31429

The program CF for the HP 42S (and Swiss Micros DM42 and Free42 emulator) calculates the value of a continued fraction. Instructions:

1. Run CF ( [ XEQ ] (CF) )

2. Enter n_k, press (LAST)

3. For each n_m for 1 < m < k, enter n_m, press (MID)

4. For n_1, enter n_1, press (1ST). You get the result.

**HP 42S/DM42/Free 42 Program CF**

00 {56-Byte Prgm}

01 LBL "CF"

02 LBL 04

03 CLMENU

04 "LAST"

05 KEY 1 GTO 01

06 "MID"

07 KEY 2 GTO 02

08 "1ST"

09 KEY 3 GTO 03

10 MENU

11 LBL 00

12 STOP

13 GTO 00

14 LBL 01

15 1/X

16 GTO 04

17 LBL 02

18 +

19 1/X

20 GTO 04

21 LBL 03

22 +

23 CLMENU

24 EXITALL

25 RTN

26 END

**Classic Algebraic (AOS) Calculators**

We can use the same strategy for classic algebraic calculators such as the Casio fx-260 Solar II and TI-30Xa Solar:

1. Start by entering n_k, then press [ 1/x ]

2. Loop: For each n_m for 1 < m < k: press [ + ], enter n_m, press [ = ], [ 1/x ]

3. For n_1: Enter n_1, [ + ]

Remember, we are working leftwards.

Calculate 2 + 1/( 3 + 1/(5 + 1/2)). In other words x = [2, 3, 5, 2]

2 [ 1/x ]

[ + ] 5 [ = ] [ 1/x ]

[ + ] 3 [ = ] [ 1/x ]

[ + ] 2 [ = ]

Result: 81/35 ≈ 2.31429

Eddie

All original content copyright, © 2011-2020. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.