A valid String can have:
- a negation sign or subtraction at the beginning of the string
- A single decimal point
- All numerals
I've indicated the stack level in with the double stars to better see the nested loops and if-statements. I also commented the code quite extensively.
:2→G // Flag used to check if there is more than more than decimal point in the string
:1→A //
:If sub(Str1,1,1)="-" **1** // Changes the first character of the string to a negation sign if it is a subtraction sign because they are different in TI-Bacic.
:Then
:"-"+sub(Str1,2,length(Str1)-1)→Str1
:End **0**
:If Str1="-" or Str1="-." or Str1="." **1** // Checks for special cases
:Then
:0→X
:Return
:End **0**
:If sub(Str1,1,1)="- // Skips the check on the first character if it is a negative sign
:2→A
:For(X,A,length(Str1)) **1**
:0→F // Flag used to trigger return to the calling program if it is not set to 1
:0→Z // Looping variable used in conjunction with the repeat loop
:sub(Str1,X,1)→Str9 // Separates each character into another string
:If Str9=". **2** // Checks if the character is a decimal point
:Then
:G-1→G
:1→F
:If G=0 **3** // Returns to calling program if there is more than one decimal point
:Then
:0→X
:Return
:End **2**
:End **1**
:Repeat F or Z>9 **2**
:prgmNUMTOSTR // turns Z into Str0
:If Str9=Str0 // Checks if the current value of Z is a numeral
:1→F
:Z+1→Z // Increases the number to check
:End **1**
:If not(F **2** // Returns to the calling program if the string is not a number
:Then
:0→X
:Return
:End **1**
:End **0**
4920616D204261746D616E