11-25-2022, 06:02 AM

The following program for the WP-34S is inspired by the this snippet of the HP-45 ROM source code:

The registers are mapped to the stack as follows:

Z: p

Y: c

X: a

While the program could easily be translated to HP calculators, the INC and SDL commands make it shorter:

Example

41 A

6.4031242374

It is recommended to use a number in the range [1, 100), although it works outside of it as well.

However, it is more efficient to apply a decimal shift first.

So use 47.11 instead of 4711 or 0.4711.

Make sure to shift an even number of digits.

The program can be helpful to understand the algorithm if you go through an example step by step.

References

By now you may have noticed that I didn't pay attention to the exponent.

But that's not so interesting in my opinion.

Code:

` 501 L01250: .1111...1. sqt15: c + 1 -> c[p]`

502 L01251: 11.1..111. sqt16: a - c -> a[w]

503 L01252: 1.1.1...11 -> L01250 if no carry go to sqt15

504 L01253: 1111..111. a + c -> a[w]

505 L01254: .1....111. shift left a[w]

506 L01255: .....111.. p - 1 -> p

507 L01256: 1..1.1..1. sqt17: shift right c[wp]

508 L01257: ....1.11.. if p # 0

509 L01260: 1.1.1..111 -> L01251 then go to sqt16

510 L01261: ..11.1.111 -> L01065 go to tnm12

The registers are mapped to the stack as follows:

Z: p

Y: c

X: a

While the program could easily be translated to HP calculators, the INC and SDL commands make it shorter:

Code:

`001 INC Y`

002 RCL- Y

003 x≥0?

004 BACK 003

005 RCL+ Y

006 SDL 002

007 x⇆ Y

008 IP

009 SDL 001

010 # ½

011 +

012 x⇆ Y

013 DSZ Z

014 BACK 012

015 x⇆ Y

016 RTN

017 LBL A

018 # ½

019 # 012

020 x⇆ Z

021 RCL× Y

022 BACK 020

023 END

Example

41 A

6.4031242374

^{12}It is recommended to use a number in the range [1, 100), although it works outside of it as well.

However, it is more efficient to apply a decimal shift first.

So use 47.11 instead of 4711 or 0.4711.

Make sure to shift an even number of digits.

The program can be helpful to understand the algorithm if you go through an example step by step.

References

- HP-45 ROM source code from United States Patent 4,001,569
- HP35 square root algorithm
- Personal Calculator Algorithms I: Square Roots
- Patent US3576983
- Calculator Patents - Hewlett-Packard

By now you may have noticed that I didn't pay attention to the exponent.

But that's not so interesting in my opinion.