Path: republic.btigate.com!news-xfer.netaxs.com!news-peer.gip.net!news.gsl.net!gip.net!ais.net!vixen.cso.uiuc.edu!newsrelay.iastate.edu!news.iastate.edu!vax1.miu.edu!JHMEYERS
From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: Slow integer square roots (short)
Date: 8 Jan 1998 10:44:51 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 48
Message-ID: <692an3$41a$1@news.iastate.edu>
References: <68vvbl$e1u$1@zingo.tninet.se>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:5500

In article <68vvbl$e1u$1@zingo.tninet.se>,
Stefan Odelfalk <sod@elit.se> wrote...

[snipped good description of square root algorithms]

The same "odd-integer" method is used for the built-in decimal function;
HP adopted it for the HP35, but not for the HP80 and possibly some other
financial calcs, where they once used the logarithmic method instead
(perhaps they were short of ROM space to squeeze in all the functions).

I thought that the HP16C emulators for the HP48 might contain the square
root function, but I see that Hakan Thorngren's excellent contributed
HP16C library omits the function, which I recall as existing in the
HP16C for both real and binary arguments.

To pass the time while waiting for the ML function to be posted,
here is a User-RPL program to ponder:

%%HP: T(3); @ BSQR - binary square root (up to 64 bits)
\<< DUP B\->R \v/ R\->B SWAP OVER / DUP2 < ROT ROT IFTE \>>
@ Where \v/ represents the Square Root symbol.

Does this work?  Is this cheating?

If you just can't wait to take integer square roots of arguments
up to 2^64-1 (a twenty-digit decimal number), you could use this,
even though it's slow (.020 to .028 seconds).

Note that
  DUP2 < ROT ROT IFTE is a MIN function for binary integers;
  DUP2 > ROT ROT IFTE is a MAX function for binary integers.

A curiosity:

Have you noticed that it is not an error to divide by binary zero?
The HP48 delivers an answer of zero whenever you divide by binary zero!
The AUR happens to mention this fact, so it is quite deliberate.

Here is a MOD function for binary integers: \<< DUP2 / * - \>>

The fact that division by binary zero is permitted allows this
'MODB' function to return the level-2 argument when the divisor
is zero, just as does the built-in MOD function for real arguments!

"Hey, buddy -- don't be a root mean square!"

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>