Post Reply 
(49G) FPTR2^ZSQRT Replacement
05-14-2015, 02:50 PM (This post was last modified: 09-08-2017 04:40 PM by Gerald H.)
Post: #1
(49G) FPTR2^ZSQRT Replacement
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
  ;
;
Find all posts by this user
Quote this message in a reply
09-08-2017, 04:43 PM
Post: #2
RE: (49G) FPTR2^ZSQRT Replacement
Please note progamme has been edited to remove ?_
Find all posts by this user
Quote this message in a reply
Post Reply 




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