From: jhmeyers@miu.edu (John H Meyers)
Subject: Fractions! (a la Casio, etc.)
Date: 25 Oct 1996 00:00:00 GMT
Message-ID: <54q7e3$e5n@news.iastate.edu>
references: <326E7ADF.2B10@ctv.es>
organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
reply-to: jhmeyers@miu.edu
newsgroups: comp.sys.hp48


In article <326E7ADF.2B10@ctv.es>, Jaime Riesco <jaimer@ctv.es> writes:

> Is there any way to reduce fractions (for example '8/12' to '2/3')
> with an HP48G Calculator?

  Shortest possible answer: ->NUM Left-shift 9 NXT ->Q
  (try it after STD '1/(22/15)' to see why it's not always so great)

  Goodies Disks are chock full of "fraction" programs; mostly *big* ones.

  See DEC2FRAC.* and NEW2Q.* on Goodies Disk #3 for insights about ->Q

  QPI has been recommended elsewhere in this thread.

  The simple stuff below does a good job of replacing the numeric
  "fraction" functions you've missed from your Casio calculator days,
  including simplification and common arithmetic, plus a few extras,
  such as Continued Fraction expansion & evaluation.

  This will tide you over if you haven't a cable, or room for too many lib's.

  E.g. '8/12'  Q --> '2/3'
       '2/3' '3/4' Add --> '1+5/12'
       1.325   Q --> '53/40' then QQ --> '1+13/40'
       pi 2 N->Q --> '22/7'
       1.325  ->CF  --> { 1 3 13 } which means 1+1/(3+1/13)
       pi  ->CF  --> { 3 7 15 1 292 1 1 1 3 }  [ in STD display mode ]
       { 3 7 15 1 } CF-> Q --> '355/113'
       etc.

  This is ready to use on G/GX; see included notes for S/SX adjustments.

  If memory is at a premium, select just those functions you need most.

  Kermit will download the entire file as one directory.
  If typing into HP48 by hand:
    o Store each separate object under the name which appears before it.
    o Do not try to use upper-case names for 'Add' thru 'Inv'
      ( because ADD,SUB,INV are built-in HP48 commands --> Invalid Syntax ).
    o Do not type any "@" or the comments which follow it.
    o Do not type the %%HP line.
    o Do not type backslashes (\xx); refer to ascii translation chart
      (on pg 27-16 of G/GX User's Guide).

-----------------------------------------------------------
With best wishes from:  John H Meyers  ( jhmeyers@mum.edu )
-----------------------------------------------------------

%%HP: T(3)A(D)F(.); @ this line tells Kermit to use ascii translation mode 3
DIR @ HP48 Fraction arithmetic, 100% User-RPL, (c) 1996 by John H Meyers
  Add    \<< + QQ  \>> @ use QQ for 'a+b/c' result, Q for 'd/c' result
  Sub    \<< - QQ  \>>
  Mul    \<< * QQ  \>>
  Div    \<< / QQ  \>>
  Inv    \<< INV QQ \>>
  PREC   6 @ precision; adjust to taste
  Q      \<< PREC N\->Q \>>  @ fraction or real --> 'd/c'
  QQ     \<< PREC N\->QQ \>> @ fraction or real --> 'a+b/c'
  @ Next 2 likewise, except uses arg for precision, SWAP SWAP verifies 2 args:
  N\->Q  \<< { SWAP SWAP FIX \->NUM \->Q } EEVAL \>> @ uses EEVAL below
  N\->QQ \<< { SWAP SWAP FIX \->NUM \->Q -3 SF DUP IP SWAP FP \->Q -3 CF + }
             EEVAL \>> @ uses EEVAL below
  \->CF  @ real --> { continued fraction coefficients }
         \<< \->NUM DUP SIGN SWAP ABS \->Q
         IF DUP TYPE 9 == THEN OBJ\-> DROP2 { } \-> f
            \<< DO DUP2 / IP 'f' SWAP STO+ UNTIL SWAP OVER MOD DUP NOT END
            DROP2 f \>>
         ELSE { } + END * \>> @ change * to SWAP DROP on S/SX
  CF\->  @ { continued fraction coefficients } --> real
         \<< REVLIST 9E499 SWAP 1 \<< SWAP INV + \>> DOLIST \>>
         @ An S/SX User-RPL program for DOLIST has recently been posted.
         @ Here is an S/SX program for REVLIST (keep in HOME for general use):
         @  \<< LIST\-> \-> n \<< 0 n FOR i i ROLL NEXT n \->LIST \>> \>>
  EEVAL  @ Evaluates, traps errors, restores things
         @ (move me to HOME directory for general use)
         \<< QUOTE DEPTH RCLF PATH \-> d. f. p.
             \<< IFERR EVAL THEN 1 ELSE 0 END f. STOF p. EVAL CLOSEIO
                 { DEPTH d. - 1 + DROPN ERRN DOERR } IFT \>> \>>
END @ End of the whole directory
-----------------------------------------------------------
With best wishes from:  John H Meyers  ( jhmeyers@mum.edu )
