Post Reply 
(12C) Square Root
12-23-2023, 04:26 AM
Post: #10
RE: (12C) Square Root
(12-23-2023 01:48 AM)Dave Hicks Wrote:  Interesting algorithm!

This is the good old digit by digit method.

Here's a program for the HP-42S:
Code:
00 { 50-Byte Prgm }
01▸LBL "√"
02 1
03 X<>Y
04 0
05 X<>Y
06▸LBL 00
07 RCL- ST Z
08 X<0?
09 GTO 01
10 1
11 STO+ ST Z
12 STO+ ST X
13 STO+ ST T
14 R↓
15 GTO 00
16▸LBL 01
17 RCL+ ST Z
18 10
19 STO× ST T
20 STO× ST Z
21 X↑2
22 ×
23 9
24 STO- ST T
25 R↓
26 STOP
27 GTO 00
28 END

Example

10
XEQ "√"

y: 30
x: 100

R/S

y: 310
x: 3900

R/S

y: 3160
x: 14400

R/S

y: 31620
x: 175600

R/S

y: 316220
x: 4911600

R/S

y: 3162270
x: 48447100


But we can do better using David Cochran's trick, multiplying the number by 5.
Therefore we only have to keep track of the subtrahend.
We just ignore the trailing 5 in the result.

Code:
00 { 45-Byte Prgm }
01▸LBL "√"
02 5
03 ×
04 LASTX
05 X<>Y
06▸LBL 00
07 RCL- ST Y
08 X<0?
09 GTO 01
10 10
11 STO+ ST Z
12 R↓
13 GTO 00
14▸LBL 01
15 RCL+ ST Y
16 10
17 STO× ST Z
18 X↑2
19 ×
20 45
21 STO- ST Z
22 R↓
23 STOP
24 GTO 00
25 END

Example

10
XEQ "√"

y: 305
x: 500

R/S

y: 3105
x: 19500

R/S

y: 31605
x: 72000

R/S

y: 316205
x: 878000

R/S

y: 3162205
x: 24558000

R/S

y: 31622705
x: 242235500


This method is used in most HP calculators.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Square Root - Gamo - 10-02-2019, 10:23 AM
RE: (12C) Square Root - Albert Chan - 10-02-2019, 02:36 PM
RE: (12C) Square Root - Albert Chan - 09-28-2020, 05:18 PM
RE: (12C) Square Root - Albert Chan - 09-28-2020, 07:14 PM
RE: (12C) Square Root - Gamo - 10-03-2019, 02:01 AM
RE: (12C) Square Root - SlideRule - 09-28-2020, 09:45 PM
RE: (12C) Square Root - Albert Chan - 06-08-2021, 03:36 PM
RE: (12C) Square Root - depor - 12-21-2023, 11:50 PM
RE: (12C) Square Root - Dave Hicks - 12-23-2023, 01:48 AM
RE: (12C) Square Root - Thomas Klemm - 12-23-2023 04:26 AM



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