Post Reply 
(50g) Integer Ratio to Exact Repeating Decimal
01-20-2018, 05:13 PM (This post was last modified: 01-20-2018 09:46 PM by Gerald H.)
Post: #2
RE: (50g) Integer Ratio to Exact Repeating Decimal
Edited to remove DUP1PUTLAM_:

A very nice piece of programming, congratulations.

I've taken the liberty of writing a Sys version, in fact two.

The first uses the function ^Factors to find number of 2's & 5's, the second uses my Sys programme from this thread

http://www.hpmuseum.org/forum/thread-9955.html

which for all fractions I've tested proves faster.

Trust the programmes are of some interest.

Size: 305.5

CkSum: # C2A3h

Code:
::
  CK1&Dispatch
  BINT10
  ::
    FPTR2 ^FXNDext
    DUP
    FPTR2 ^FACTORS
    DUPDUP
    ZINT 2
    SWAP
    FPTR2 ^ListPos
    DUP
    #0<>
    ITE
    ::
      #1+
      NTHCOMPDROP
    ;
    SWAPDROP
    SWAPDUP
    ZINT 5
    SWAP
    FPTR2 ^ListPos
    DUP
    #0<>
    ITE
    ::
      #1+
      NTHCOMPDROP
    ;
    SWAPDROP
    COERCE2
    #MAX
    ZINT 0
    '
    NULLLAM
    BINT4
    NDUPN
    DOBIND
    4GETLAM
    3GETLAM
    FPTR2 ^ZDIVext
    SWAP
    FPTR2 ^Z>S
    CHR_.
    >T$
    SWAP
    2GETLAM
    #0=?SKIP
    ::
      2GETLAM
      #1+_ONE_DO
      ZINT 10
      FPTR2 ^RMULText
      3GETLAM
      FPTR2 ^ZDIVext
      3UNROLL
      FPTR2 ^Z>S
      &$SWAP
      LOOP
    ;
    DUP
    ZINT 0
    EQUALNOT
    IT
    ::
      DUP
      1PUTLAM
      SWAP
      "_"
      &$SWAP
      BEGIN
      ZINT 10
      FPTR2 ^RMULText
      3GETLAM
      FPTR2 ^ZDIVext
      3UNROLL
      FPTR2 ^Z>S
      &$SWAP
      DUP
      1GETLAM
      EQUAL
      UNTIL
    ;
    DROP
    1GETABND
    ZINT 0
    EQUAL
    ?SEMI
    "_"
    &$
  ;
;

Size: 276.5

CkSum: # E5E6h

Code:
::
  CK1&Dispatch
  BINT10
  ::
    FPTR2 ^FXNDext
    DUP
    FPTR2 ^ZTrialDiv2
    BINT0
    ROT
    BEGIN
    DUP
    ZINT 5
    FPTR2 ^ZDIVext
    ZINT 0
    EQUAL
    WHILE
    ::
      SWAPDROP
      SWAP#1+SWAP
    ;
    REPEAT
    2DROP
    #MAX
    ZINT 0
    '
    NULLLAM
    BINT4
    NDUPN
    DOBIND
    4GETLAM
    3GETLAM
    FPTR2 ^ZDIVext
    SWAP
    FPTR2 ^Z>S
    CHR_.
    >T$
    SWAP
    2GETLAM
    #0=?SKIP
    ::
      2GETLAM
      #1+_ONE_DO
      ZINT 10
      FPTR2 ^RMULText
      3GETLAM
      FPTR2 ^ZDIVext
      3UNROLL
      FPTR2 ^Z>S
      &$SWAP
      LOOP
    ;
    DUP
    ZINT 0
    EQUALNOT
    IT
    ::
      DUP
      1PUTLAM
      SWAP
      "_"
      &$SWAP
      BEGIN
      ZINT 10
      FPTR2 ^RMULText
      3GETLAM
      FPTR2 ^ZDIVext
      3UNROLL
      FPTR2 ^Z>S
      &$SWAP
      DUP
      1GETLAM
      EQUAL
      UNTIL
    ;
    DROP
    1GETABND
    ZINT 0
    EQUAL
    ?SEMI
    "_"
    &$
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (50g) Integer Ratio to Exact Repeating Decimal - Gerald H - 01-20-2018 05:13 PM



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