HP Forums
(49G) FPTR2^ZSQRT Replacement - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) FPTR2^ZSQRT Replacement (/thread-3837.html)



(49G) FPTR2^ZSQRT Replacement - Gerald H - 05-14-2015 02:50 PM

Edit: Programme changed to remove uncommon names for pointers etc.

The built in integer square root-finder function returns the integer square root of N a positive integer & TRUE/FALSE if the square of the answer is exactly N or not. Sadly the square root of larger integers is not calculated correctly.

eg For entry

8057607683965968206853219945486680251051474004852138

FPTR2^ZSQRT returns

89764178177967899999999999 (incorrect value) & FALSE.

The programme below returns

89764178177967898147413811 (correct value) & FALSE.

Programme name: ISQRT

Size: 125.

CkSum: # 6291d

Code:
::
  CK1&Dispatch
  # FF
  ::
    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
  ;
;



RE: (49G) FPTR2^ZSQRT Replacement - Gerald H - 09-08-2017 04:43 PM

Please note progamme has been edited to remove ?_