Number to String Alternative
The LinReg method is nice and well optimized, but has the downside of destroying the graph screen. Here's a version that doesn't. For small numbers, it's also faster.
Inputs: Ans - Number to convert (real)
Outputs: Ans - Converted number (string)
Destroys: A, String0, Z

Code:
:Ans→A
" →Str0
A<0→Z
abs(A→A
While A
sub("0123456789",A-10int(A/10)+1,1)+Str0→Str0
int(A/10→A
End
sub(Str0,1,length(Str0)-1
If Z
"[negative]"+Ans


I don't like that I have to destroy Z, does anyone have an alternative?
You can use a list.
I meant an alternative that doesn't destroy anything at all.
I would suggest det(1,Ans). See also:

http://dcs.cemetech.net/index.php?title=BasicLibs:NumToString
You can make costum Lists, and there are a lot of possibilitys, so it wouldn't matter to destroy a list to me. Alternative you can use mine that destroys Y0.
KermMartian, I would love to use that one for hybrid, but my routine is pure Basic, which is nice because my teacher gives me extra credit for programs, but doesn't like installing anything asm.
EDIT: Sorunome, read over my post again, including the description.
WHOOPS! srry, if you add somewhere there another FnOff, then it won't draw the graph, I forgot that row.
Nope, I tried that. I've been using the LinReg method for a long time now, it's not a new idea.
It works in my programm Calculate v1.0, thought.
I'd suggest using the DCS AnsStack feature to push and pop Z around that routine, but that doesn't help much either. Smile Here's your solution:


Code:
:Ans→A
sub(" -",1+A<0,1→Str0
abs(A→A
While A
sub("0123456789",A-10int(A/10)+1,1)+Str0→Str0
int(.1A→A
End
If " "=sub(Str0,1,1
sub(Str0,1,length(Str0)-1


Edit: .1A is one byte smaller than A/10
KermMartian wrote:
I'd suggest using the DCS AnsStack feature to push and pop Z around that routine, but that doesn't help much either.

That's a great fix, KermMartian, but as I said earlier, this routine should be pure TI-Basic.
Sorunome wrote:
Thx for youre help!
*Your help. Smile I assume that the code I gave you works well?
Not tryed out yet! Razz I was busy< uploading Mino v0.3 and checking all my e-mails! Razz
Optimized more (thanks, Xeda112358):

Code:

Ans→A
" →Str0
A<0→Z
abs(A→A
While A
int(.1A→A
sub("0123456789",A-10Ans+1,1)+Str0→Str0
End
sub(Str0,1,length(Str0)-1
If Z
"[negative]"+Ans
Umm, did you miss my solution above?
SirCmpwn wrote:
That's a great fix, KermMartian, but as I said earlier, this routine should be pure TI-Basic.

That's the third time I've said so, it's a bit frustrating.

EDIT: After testing the previous optimization, I found out that it won't actually work.
SirCmpwn wrote:
SirCmpwn wrote:
That's a great fix, KermMartian, but as I said earlier, this routine should be pure TI-Basic.

That's the third time I've said so, it's a bit frustrating.

EDIT: After testing the previous optimization, I found out that it won't actually work.
For the fourth time, look at my post that has sub(" -" near the beginning, which solves your problem in PURE basic.
Oh, my mistake, I apologize. And, just cause I can't resist, I optimized away 7 bytes:

Code:
:Ans→A
sub(" -",1+A<0,1→Str0
abs(A→A
While A
sub("0123456789",A-10int(.1A)+1,1)+Str0→Str0
int(.1A→A
End
If 1=length(Str0
sub(Str0,1,length(Str0)-1
Your change will break the routine. I was checking whether there was a space to be removed from the beginning of the string, or whether it was a negative sign. I have no idea what yours is trying to do, other than generate a string of zero length.
Oh, I see. I thought it was trying to see something else. Here's a different version, still smaller.
Also, I'm getting a domain error on line 2. EDIT: Fixed and optimized
EDIT2: Optimized even more, fixed it to always return in Ans

Code:
:Ans→A
Ans<0
sub(" -",1+Ans,1→Str0
abs(A→A
While A
sub("0123456789",A-10int(.1A)+1,1)+Str0→Str0
int(.1A→A
End
If inString(Str0,"-
"-"+Str0→Str0
sub(Str0,1,length(Str0)-1


After testing, I found out that negative numbers end up like this: "number-", instead of "-number", which is why I ended up using Z before. Anyone think of a good way to fix this?

EDIT: Fixed
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3 ... 7, 8, 9 ... 13, 14, 15  Next
» View previous topic :: View next topic  
Page 8 of 15
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement