Post Reply 
(49G) Integer Square Detection
10-11-2015, 06:48 AM (This post was last modified: 06-15-2017 01:45 PM by Gene.)
Post: #1
(49G) Integer Square Detection
The programme ISSQ? economically detects whether an integer is a perfect square, returning 1. for yes, 0. for no.

A problem arises in compiling the programme: the ZINTs in bold type have been processed through the command

FPTR2 ^Z>ZH

& are in fact hexadecimal ZINTs - the on-calculator compiler attempts to return the four numbers as decimal ZINTs, thus debilitating the programme.

Similarly, the decompiler produces the programme as here printed, not indicating the hexadecimal nature of the ZINTs.

Anyone have a solution to this compilation problem?


ISSQ?

::
CK1&Dispatch
# FF
::
::
1LAMBIND
TRUE
ZINT 23;
ZINT 11
ZINT 1218:019866014613
ZINT 65
ZINT 402483012450293
ZINT 63
ZINT 202021202030213
ZINT 64
BINT5
ONE_DO
::
1GETLAMSWAP_
FPTR2 ^ZMod
FPTR2 ^Z>#
FPTR2 ^ZBit?
SWAPDROP
?SEMI
ISTOP-INDEX
#2*
#1-
NDROP
FALSE
ExitAtLOOP
;
LOOP
1GETABND
SWAP
NOTcsdrpfls
::
DUP
Z2_
Z<
DUP
?SEMI
DROPDUP
FPTR2 ^Z>ZH
FPTR2 ^ZBits
BINT2
#/
#+
Z2_
SWAP
FPTR2 ^PPow#
BEGIN
SWAPDROPDUP
3PICKOVER
FPTR2 ^ZQUOText
FPTR2 ^QAdd
Z2_
FPTR2 ^ZQUOText
2DUP
Z>
NOT_UNTIL
DROPDUP
FPTR2 ^ZSQ_
ROT
EQUAL
;
SWAPDROP
;
COERCEFLAG
;
;
Find all posts by this user
Quote this message in a reply
10-12-2015, 09:41 AM
Post: #2
RE: HP 49G: Integer Square Detection
(10-11-2015 06:48 AM)Gerald H Wrote:  A problem arises in compiling the programme: the ZINTs in bold type have been processed through the command

FPTR2 ^Z>ZH

& are in fact hexadecimal ZINTs - the on-calculator compiler attempts to return the four numbers as decimal ZINTs, thus debilitating the programme.

Similarly, the decompiler produces the programme as here printed, not indicating the hexadecimal nature of the ZINTs.

Anyone have a solution to this compilation problem?

Perhaps you can replace those lines with NIBHEX statements. Not human-readable, but at least they would compile correctly.

Example: Running ZINT 123 through Z>ZH returns the hex zint 7B which is displayed as "7;" by the HP 50g. This can be encoded in a program listing as:

NIBHEX 4162080000B70

<0|ΙΈ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-12-2015, 11:53 AM
Post: #3
RE: HP 49G: Integer Square Detection
Thank you Joe, yes that works,

::
FPTR2 ^Z>ZH
x->H
"NIBHEX "
SWAP&$
;

will then compile correctly.

The decompilation problem remains - should any programme maintenance be needed the problem recurs.

The problem could be obviated by putting the decimal ZINT in the programme followed by FPTR2 ^Z>ZH - it's just I find that an inelegant solution.
Find all posts by this user
Quote this message in a reply
10-12-2015, 12:08 PM
Post: #4
RE: HP 49G: Integer Square Detection
So here a compilable version of ISSQ?

Code:

::
  CK1&Dispatch
  # FF
  ::
    ::
      1LAMBIND
      TRUE
      NIBHEX 4162090000B320
      ZINT 11
      NIBHEX 4162071000316410668910A81210
      ZINT 65
      NIBHEX 41620510003920542103842040
      ZINT 63
      NIBHEX 41620510003120302021202020
      ZINT 64
      BINT5
      ONE_DO
      ::
        1GETLAMSWAP_
        FPTR2 ^ZMod
        FPTR2 ^Z>#
        FPTR2 ^ZBit?
        SWAPDROP
        ?SEMI
        ISTOP-INDEX
        #2*
        #1-
        NDROP
        FALSE
        ExitAtLOOP
      ;
      LOOP
      1GETABND
      SWAP
      NOTcsdrpfls
      ::
        DUP
        Z2_
        Z<
        DUP
        ?SEMI
        DROPDUP
        FPTR2 ^Z>ZH
        FPTR2 ^ZBits
        BINT2
        #/
        #+
        Z2_
        SWAP
        FPTR2 ^PPow#
        BEGIN
        SWAPDROPDUP
        3PICKOVER
        FPTR2 ^ZQUOText
        FPTR2 ^QAdd
        Z2_
        FPTR2 ^ZQUOText
        2DUP
        Z>
        NOT_UNTIL
        DROPDUP
        FPTR2 ^ZSQ_
        ROT
        EQUAL
      ;
      SWAPDROP
    ;
    COERCEFLAG
  ;
;
@
Find all posts by this user
Quote this message in a reply
10-13-2015, 07:04 AM
Post: #5
RE: HP 49G: Integer Square Detection
And here a slightly optimized version of ISSQ?

Code:

::
   CK1&Dispatch
   # FF
   ::
     ::
       DUP1LAMBIND
       TRUE
       NIBHEX 4162090000B320
       ZINT 11
       NIBHEX 4162071000316410668910A81210
       ZINT 65
       NIBHEX 41620510003920542103842040
       ZINT 63
       NIBHEX 41620510003120302021202020
       ZINT 64
       BINT5
       ONE_DO
       ::
         1GETLAMSWAP_
         FPTR2 ^ZMod
         FPTR2 ^Z>#
         FPTR2 ^ZBit?
         SWAPDROP
         ?SEMI
         ISTOP-INDEX
         #2*
         #1-
         NDROP
         FALSE
         ExitAtLOOP
       ;
       LOOP
       ABND
       NOTcsdrpfls
       DUP
       Z2_
       Z<
       casedrptru
       DUP
       FPTR2 ^Z>ZH
       FPTR2 ^ZBits
       BINT2
       #/
       #+
       Z2_
       SWAP
       FPTR2 ^PPow#
       BEGIN
       SWAPDROPDUP
       3PICKOVER
       FPTR2 ^ZQUOText
       FPTR2 ^QAdd
       Z2_
       FPTR2 ^ZQUOText
       2DUP
       Z>
       NOT_UNTIL
       DROP
       FPTR2 ^ZSQ_
       EQUAL
     ;
     COERCEFLAG
   ;
 ;
@
Find all posts by this user
Quote this message in a reply
Post Reply 




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