(50g) Integer Square Root Rounded to Nearest Integer

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50g) Integer Square Root Rounded to Nearest Integer (/thread-8992.html)



(50g) Integer Square Root Rounded to Nearest Integer - Gerald H - 09-06-2017 09:20 AM

For integer input N the programme returns the square root rounded to the nearest integer.

Size: 195.5

CkSum: # 782Ah

Code:
::
  CK1&Dispatch
  # FF
  ::
    DUP
    ::
      DUP
      ZINT 2
      Z<
      DUP
      ?SEMI
      DROPDUP
      FPTR2 ^Z>ZH
      FPTR2 ^ZBits
      BINT2
      #/
      #+
      ZINT 2
      SWAP
      FPTR2 ^PPow#
      BEGIN
      SWAPDROPDUP
      3PICKOVER
      FPTR2 ^ZQUOText
      FPTR2 ^QAdd
      ZINT 2
      FPTR2 ^ZQUOText
      2DUP
      Z>
      NOT_UNTIL
      DROPDUP
      DUP
      FPTR2 ^QMul
      ROT
      EQUAL
    ;
    DROP
    DUPDUP
    FPTR2 ^RADDext
    ZINT 1
    FPTR2 ^RADDext
    DUP
    FPTR2 ^QMul
    ZINT 4
    FPTR2 ^ZQUOText
    ROT
    Z<
    NOT?SEMI
    ZINT 1
    FPTR2 ^RADDext
  ;
;

Trust it compiles & works correctly.

^ZSQ_ is FPTR 6 590 which squares its argument.