Determine if a string is numeric: Difference between revisions

no edit summary
(Added Z80 Assembly version)
No edit summary
Line 2,047:
<pre>
["123", "-12.3", "-12e5", "+123"]
</pre>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun isNumeric = logic by text value
try
^|So funny:
|a) we check if it's castable to a real
|b) we obtain the real 0.0
|c) conversion from real to int to get 0
|d) int can be converted to logical to get ⊥
|e) we can negate the result
|^
return not when(value.contains("."), logic!int!(real!value * 0), logic!(int!value * 0))
remedy
return false
end
end
fun main = int by List args
if args.length == 1
writeLine(isNumeric(args[0]))
else
writeLine("value".padEnd(8, " ") + " " + "numeric")
for each text value in text["0o755", "thursday", "3.14", "0b1010", "-100", "0xff"]
writeLine(value.padEnd(8, " ") + " " + isNumeric(value))
end
end
return 0
end
exit main(Runtime.args)
</syntaxhighlight>
{{out}}
<pre>
value numeric
0o755 ⊤
thursday ⊥
3.14 ⊤
0b1010 ⊤
-100 ⊤
0xff ⊤
</pre>
 
214

edits