Talk:Determine if a string is numeric: Difference between revisions
Talk:Determine if a string is numeric (view source)
Revision as of 17:47, 20 August 2021
, 2 years agono edit summary
m (→Exact definition of IsNumeric?: fixed typo.) |
Puppydrum64 (talk | contribs) No edit summary |
||
Line 144:
2
</pre>
== Assembly implementation is harder than I thought==
The way I see it, the code will need to do the following:
Read the first character.
* If it's a null terminator, the program ends and the string is not numeric.
* If it's a minus sign, that's valid and so we can continue
* If it's a decimal point, that's valid and we can continue. However, the presence of a decimal point must be recorded. If the string contains a second decimal point it stops being numeric.
* If it's not a number, at this point the string is not numeric. Otherwise continue.
Read the second character.
* If it's the terminator, the string is numeric if the first character was a numeral. If the first character was a minus sign or decimal point, the string is not numeric.
* If the second character is a numeral, continue.
* If the second character is a decimal point, continue if we haven't seen one already. If there is more than one decimal point the string is not numeric.
* If the second character is anything else, the string is not numeric.
Loop through the rest of the string.
* If we encounter the terminator, the string is numeric.
* If we encounter a numeral, continue.
* If we encounter a second decimal point, the string is not numeric.
* If we encounter anything besides a numeral, the null terminator, or the first occurrence of a decimal point, the string is not numeric.
I've attempted this in both 8086 and z80 but it ends up looking like spaghetti no matter what I do.
|