Post Reply 
(50G): Exact Integer Division to Integer Base
01-27-2017, 07:34 PM (This post was last modified: 06-15-2017 01:41 PM by Gene.)
Post: #1
(50G): Exact Integer Division to Integer Base
For input

A
B
C

A,B,C integers the programme returns A / B to base C.

eg For input

5
111
7

the programme returns

:7: { "." "°" 0 2 1 3 1 0 3 3 5 }

Similarly

123
77
2

:2: { 1 "." "°" 1 0 0 1 1 0 0 0 1 1 1 0 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 1 0 }

and

17
11
107

:107: { 1 "." "°" 58 38 97 29 19 48 68 9 77 87 }

and

27
6
37

37: { 4 "." "°" 18 }

"°" indicates the beginning of the recursive part of the decimal.

Code:

::
  CK3&Dispatch
  # AAA
  ::
    FPTR2 ^CK3Z
    BINT3
    NDUP
    FPTR2 ^QMul
    FPTR2 ^QMul
    FPTR2 ^QIsZero?
    case2drop
    ::
      FPTR2 ^DupQIsZero?
      ?SEMI
      SETIVLERR
    ;
    Z0_
    FPTR2 ^2LAMBIND
    2DUP
    FPTR2 ^ZDIVext
    SWAP
    2GETLAM
    NULL{}
    3UNROLL
    ::
      BEGIN
      OVER
      FPTR2 ^QIsZero?
      case
      AGAIN
      DUPUNROT
      FPTR2 ^ZDIVext
      4ROLLSWAP
      >HCOMP
      SWAPROT
      AGAIN
    ;
    RDROP
    2DROP
    "."
    >TCOMP
    4UNROLL
    FPTR2 ^QIsZero?
    ::
      case2DROP
      NULL{}
      DUP4UNROLL
      3UNROLL
      BEGIN
      DUPUNROT
      FPTR2 ^ZDIVext
      5ROLL
      ROT
      >TCOMP
      4UNROLL
      2GETLAM
      FPTR2 ^QMul
      SWAPROT
      1GETLAM
      >TCOMP
      UNROTOVER
      1PUTLAM
      OVER
      4PICK
      FPTR2 ^ListPos
      DUP#0=
      WHILE
      DROP
      REPEAT
      4UNROLL3DROP
      1GETLAM
      FPTR2 ^QIsZero?
      ::
        caseDROP
        "°"
        SWAP
        FPTR2 ^INSERT{}N
      ;
      CDRCOMP
      &COMP
    ;
    2GETLAM
    ABND
    DO>STR
    >TAG
  ;
;
Find all posts by this user
Quote this message in a reply
01-28-2017, 06:14 AM
Post: #2
RE: HP 50g: Exact Integer Division to Integer Base
The programme also delivers correct results for negative bases, eg

1
600
-10

:-10: { "." 0 0 -1 "°" 6 -6 }

and

6000000
70
-10

:-10: { 8 -5 7 -1 4 "." "°" -2 8 -5 7 -1 4 }
Find all posts by this user
Quote this message in a reply
Post Reply 




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