Re: TI85 Concatenating numbers/Numbers -> Strng


[Prev][Next][Index][Thread]

Re: TI85 Concatenating numbers/Numbers -> Strng



In <gmYBmcG00YUz0OJ0c0@andrew.cmu.edu>, Jonathan Todd Samuel
<jsamuel+@andrew.cmu.edu> writes:


>OK, here's how to make a number into a string....


>That should do it. You can just tinker with the algorithm to make
>strings out of negative numbers or numbers with a decimal point. I
>suppose I can post actual code (with speed optimizations) if necessary.
>But you learn more by doing it yourself...




Pretty neat, Jonathan.  Although -- yikes -- is there no more direct way?
Unbelievable.  The routine takes about ten seconds to run.  "Ti85 string
functions aren't too good" is the understatement of the month. Unbelievably
lousy.  Is it any better on a 92, given its QWERTY keyboard and the
"textpectations" that raises?  What a cruddy Basic.  They don't even have
commented lines.  Absurd case sensitivity.  And, my TI-83 doesn't have a
MOD function, at least not one that's documented (or that I can get
working), although MOD is easy to simulate.  Also the 83 doesn't accept
ordinary string variables (like ST); you gotta use canned variables Str0,
Str1, Str2, etc.  But the following routine works for me.  I'd enjoy to see
your "speed optimizations" -- anything to cut this down to size or speed it
up:


============CUT===============
"NON-EXECUTING COMMENTS IN STR1"=Str1


-167.12=A:"SOURCE VALUE"=Str1


A=B
abs(A)=A:"REMOVE MINUS SIGN IF NEGATIVE NUMBER"=Str1
" "=Str0:"CRASHES IF ZERO LENGTH"=Str1


If int(A)<>A:Then:"IF FRACTION EXISTS..."=Str1
    fPart(A)=C
    iPart(A)=A


    Repeat int(C)=C:"REMOVE DECIMAL POINT FROM FRACTION"=Str1
        C*10=C
        End


    Repeat C<1:"PARSE FRACTION"=Str1
        C-int(C/10)*10=D:"SIMULATE MOD FUNCTION"=Str1
        sub("0123456789",D+1,1)+Str0=Str0
        (C-D)/10=C
        End


    "."+Str0=Str0:"RESTORE DECIMAL POINT"=Str1
    End


Repeat A<1:"PARSE INTEGER"=Str1
    A-int(A/10)*10=D
    sub("0123456789",D+1,1)+Str0=Str0
    (A-D)/10=A
    End


sub(Str0,1,length(Str0)-1)=Str0:"REMOVE TRAILING SPACE"=Str1


If abs(B)<>B:Then:"-"+Str0=Str0:End:"RESTORE MINUS SIGN"=Str1


Disp B,Str0
Stop
============CUT===============


Thanks loads for your help.


References: