Re: TIB: Real Number to String


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

Re: TIB: Real Number to String





Well, usually when I am programming on my machine in C, I just use a 
while loop... On the TI-8x, one COULD use this to 'calculate' the 
decimal places on it, or rather just keep going until the number 
becomes zero:

--- Begin Random Code Block ---

Prompt X,N
int(N)->A
frac(N)->B
" "->Str1
Repeat A==0
A/10->A
Str1+sub("0123456789",Mod(frac(A)*10,10),1)->Str1
int(A)->A
End
Str1+"."->Str1
Repeat B==0
B*10->B
Str1+sub("0123456789",Mod(B,10),1)->Str1
End
sub(Str1,1,lngth Str1-1)->Str1
If sub(Str1,lngth Str1-1,1)=="."
sub(Str1,0,lngth Str1-1)->Str1

--- End Random Code Block ---

As you can see, this isn't too much longer than the other version listed
here, although this will probably be slower. The good news is that this
can handle numbers of ANY size, although numbers in scientific notation
(anything over 9 digits or so) will probably cause it to burp out a
rather silly string... not sure... but if someone with an 83+ (which is
what this was written for, but it CAN be used right out in an 86/85 as well)
can test the speed on this, give me some feedback :)

>Wow, I'm impressed.  After testing this program, I discovered that its
>really fast, much faster than I would have expected.  The only thing I
>can think of to impove it further would be to make it automatically set
>the number of decimal places to go to.  However, I don't know of any
>really easy way to do this that wouldn't slow down the program
>immensely.  Anybody out there know of a quick way to find the number of
>decimal places?
-- 
----
"Science describes how our universe reacts in a mathematical 
representation of it, but can be described in regular terms. These 
terms seem to infringe on Religion's role of describing the creation, 
and once Science finds a clue to the creation, Religion declares 
Science a heretic. Religion scolds Science, telling it to stick to 
doing what it does best. To this, Science laughs and complies, going 
after the creation once again. Wouldn't it be fair to listen to the 
fact that these humans could have been a product of the Creator just 
as we are, Borak?" - Cyander, Day for the Xenith: Xenith Dawn 

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




References: