[comp.sys.handhelds] Alternate ROUN

ahdinw01@ULKYVX.BITNET (05/31/90)

Strike 1: (Burn my previous ROUN/RN post)

    [WHAT you never got it?  Oh well all the better...]

First post:

Here is a newer and more improved version of Robert Yoder's original number
rounder program.  The number rounder can be modified easily in various ways to
yield different types of rounding.

One alternative (improvement depending on how you look at it) is to look at the
fractional part of the mantissa of the number.

Thus    Given :  3.99999999E50
        Yields:  4.E50

whereas the old version would leave such numbers unchanged.  I realize this
may not be desired by some since numbers like 19999.254 will be rounded to
20000.  If you fall into this category, then omit 'n' this post.

Other changes include:

m 1 + 'm' STO                 to          1 'm' STO+

and

ARRY-> -> sl                     to       ARRY-> DUP LIST->
<<  IF sl SIZE 1 SAME                     IF 2 == THEN * END
    THEN sl 1 GET DUP
    ELSE sl DUP LIST-> DROP *
    END


For those of us with 48's, the program is better implemented with a large
CASE statement, otherwise you will have to revert back to the original
IF THEN ELSE... structure.

Second Post:

    Well, I found one obvious problem(besides typos) with the ROUN version I
posted earlier; namely that negative number returned positive results.  This
is because I too hastily took a line of code from my original implementation
of ROUN and plopped it into Yoder's.

     I still can't decide on what implementation of ROUN is really the most
desirable.  I like Yoder's version of ROUN but I want it to correct calculator
round off ONLY.  Therefore, I don't want ROUN to round off 4.0183E-18 just
because its small since it might be the actual result of a calculation.  If
I'm thinking the wrong logic here then somebody please set me straight.

Also, when I get a chance to type in (or build myself the cable) I will post my
original version of ROUN.  My version is slightly slower but I will post it
anyways since it approaches the problem quite differently.  Who knows, there
might even be some optimizations I missed.

I am posting ROUN as I currently have it in my calculator so that the checksums
will match.  The previous post had typos and a wrong checksum.

Barring anymore more typos, here is RN. (or ROUN as posted by Yoder)
============================================================================
RN:  Bytes #EA69h, 506.5

<< DUP -> TYPE t

     << CASE t NOT THEN

           DUP SIGN SWAP DUP DUP
           IF THEN XPON SWAP MANT END    ; MANT doesn't like 0
           ROT SWAP DUP IP SWAP FP

           0 -> m
           << WHILE DUP FP m 10 < AND
              REPEAT
                IF DUP FP .00009 <=     ;this constant can be adjusted
                  THEN FLOOR
                ELSE
                IF DUP FP .9999 >=      ;this constant can be adjusted
                  THEN CEIL
                END
                END
                10 * 1 'm' STO+
              END
              m ALOG / + * 10 ROT ^ *
           >>

        END IF t 1 ==
        THEN
           C->R SWAP RN SWAP RN
           IF DUP THEN R->C ELSE DROP END
        END IF t 3 == t 4 == OR
        THEN
           OBJ-> DUP OBJ->
           IF 2 == THEN * END
           -> d s << 1 s START RN s ROLL NEXT d ->ARRY >>

        END IF t 5 ==
        THEN
           OBJ-> -> s << 1 s START RN s ROLL NEXT s ->LIST >>
        END
     END
  >>
>>
============================================================================
                          Aaron Dinwiddie
                           ==> Agima <==                    ahdinw01@ulkyvx
============================================================================