The Square Root's Partial Quotients Program is adapted from an HP 48 program written by Joe Horn, and uses a DO loop to compute a list of partial quotients of the continued fraction equal to the square root of an integer. The result list consists of an integer followed by the repeating quotient sequence. For example, an input of 25 returns the list {1} because the square root is exactly 5. An input of 18 returns the list {4,4,8} which means that SQRT(18)=4+1/(4+1/(8+1/(4+1/(8+... with 4 8 repeating.
| D | Denominator |
| L1 | Result list |
| N | Numerator |
| T | Current term |
| X | Input integer |
Some characters on the HP 38G, like the store-arrow (\|>), are represented in the listing below by special three-character sequences. For a full list of these sequences, you can refer to the HP 38G Character Translation Codes page.
INPUT X;"\v/ Partial Quotient";"Integer:";"Enter a positive integer";X: Get value for X
SYSEVAL 532268: Clear list L1
IF FRAC(\v/X)\=/0 THEN If the fractional part of SQRT(X) <> 0 then
compute quotient sequence
1\|>D:0\|>N: Initialize numerator, denominator
DO
INT((\v/X+N)/D)\|>T: Next term
CONCAT(L1,{T})\|>L1: Add term to list
D*T-N\|>N: Update numerator
(X-N^2)/D\|>D: Update denominator
UNTIL
D==1 Repeat until denominator=1
END
CONCAT(L1,{N*2})\|>L1: Add last term to list
ELSE
{1}\|>L1: If fractional part of SQRT(X)=0
END:
ERASE: Clear display
MSGBOX L1 Display result
Back to James Donnelly's web site.
Back to the HP 38G page.
Back to the main calculator page.