Jump to content

Determine if a string is numeric: Difference between revisions

no edit summary
No edit summary
Line 467:
'12+3' is NOT a number
'end' is NOT a number</pre>
 
=={{header|Befunge}}==
<lang befunge> ~:0\`#v_:"+"-!#v_:"-"-!#v_::"E"-\"e"-*#v_ v
v _v# < < 0<
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!#v_ v
^ $< > > $ v
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!#v_> v>
^ $< >$~:0\`#v_:"+"-#v_v
v $_v# < < :#<
>~:0\`#v_>::"0"-0\`\"9"-0`+!#v_:"."-!#v_::"E"-\"e"-*!v 0 > v
^ $< v < << ^_^#-"-"<
> "ciremuN">:#,_@ >>#$_"ciremun toN">:#,_@^ <</lang>
 
 
Although only integer inputs are strictly allowed in Befunge, the code tries to adhere to the floating point conventions in other languages when recognising valid numbers.
 
{{out}}
<pre>
'PI' Not numeric
'0123' Numeric
'-0123' Numeric
'12.30' Numeric
'-12.30' Numeric
'123!' Not numeric
'0' Numeric
'0.0' Numeric
'.123' Numeric
'-.123' Numeric
'12E3' Numeric
'12E-3' Numeric
'12+3' Not numeric
'end' Not numeric
'12..34' Not numeric
'12e3.4' Not numeric
'192.168.0.1' Not numeric
</pre>
 
=={{header|Bracmat}}==
To check whether a string is a number, a fraction or an integer, use the patterns <code>#</code>, <code>/</code> and <code>~/#</code> ("not a fraction and yet a number"). In the pattern matching examples below (which can be typed in at the Bracmat prompt) <code>F</code> denotes 'failure' and <code>S</code> denotes 'success'.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.