Determine if a string is numeric: Difference between revisions

Line 3,895:
" $a" isNumeric . ( succeeds, because $ is a valid override prefix )
( denoting that the following character is a hexadecimal number )</lang>
 
=={{header|TMG}}==
Unix TMG dialect. NOTE: the program also performs some basic normalization (namely, removing the plus sign and translating "E" to "e"):
<lang UnixTMG>prog: ignore(<< >>)
parse(line)\prog
parse(error)\prog;
line: number *;
number: ignore(none)
sign float (exp | ={})
= { < True: > 3 2 1 * };
sign: <+>={} | <->={<->} | ={};
float: int ( <.> decim = { 2 <.> 1 } | = { 1 } )
| <.> int = { <.> 1 };
int: smark any(digit) string(digit) scopy;
decim: smark string(digit) scopy;
exp: smark any(<<eE>>) scopy sign int = { <e> 2 1 };
 
error: smark any(nonl) ignore(none) string(nonl) scopy * = { <False: > 1 * };
 
digit: <<0123456789>>;
none: <<>>;
nonl: !<<
>>;</lang>
 
Sample input:
<pre>
123
+12345.678
.678
1.
+1.0E+99
-7.
-123e-123
00000
.
1.2.3
0x123
a1-a5
1 000 000
1,000,000
1.00e1e1
</pre>
 
Sample output:
<pre> True: 123
True: 12345.678
True: .678
True: 1.
True: 1.0e99
True: -7.
True: -123e-123
True: 00000
False: .
False: 1.2.3
False: 0x123
False: a1-a5
False: 1 000 000
False: 1,000,000
False: 1.00e1e1
</pre>
 
=={{header|UNIX Shell}}==
Anonymous user