Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,2 +1 @@
|
|||
$ awk 'function isnum(x){return(x==x+0)}BEGIN{print isnum("hello"),isnum("-42")}'
|
||||
0 1
|
||||
$ awk 'function isnum(x){return(x==x+0)} BEGIN{print isnum("hello"),isnum("-42")}'
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
integer
|
||||
numeric(text s)
|
||||
{
|
||||
return alpha(s, 0);
|
||||
}
|
||||
|
||||
integer
|
||||
is_numeric(text s)
|
||||
{
|
||||
return !trap(numeric, s);
|
||||
return !trap_q(alpha, s, 0);
|
||||
}
|
||||
|
||||
integer
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
set /a a=%arg%+0 >nul
|
||||
if %a% == 0 (
|
||||
if not "%arg%"=="0" (
|
||||
echo Non Numeric.
|
||||
) else (
|
||||
echo Numeric.
|
||||
)
|
||||
) else (
|
||||
echo Numeric.
|
||||
)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import std.stdio, std.string, std.array;
|
||||
|
||||
void main() {
|
||||
foreach (const s; ["12", " 12\t", "hello12", "-12", "02"
|
||||
foreach (const s; ["12", " 12\t", "hello12", "-12", "02",
|
||||
"0-12", "+12", "1.5", "1,000", "1_000",
|
||||
"0x10", "0b10101111_11110000_11110000_00110011",
|
||||
"-0b10101", "0x10.5"])
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ bool isNumeric(in string s) pure {
|
|||
}
|
||||
|
||||
void main() {
|
||||
foreach (immutable s; ["12", " 12\t", "hello12", "-12", "02"
|
||||
foreach (immutable s; ["12", " 12\t", "hello12", "-12", "02",
|
||||
"0-12", "+12", "1.5", "1,000", "1_000",
|
||||
"0x10", "0b10101111_11110000_11110000_00110011",
|
||||
"-0b10101", "0x10.5"])
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
numeric_string(String) :-
|
||||
atom_string(Atom, String),
|
||||
atom_number(Atom, _).
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
test_strings(Strings) :-
|
||||
forall( member(String, Strings),
|
||||
( ( numeric_string(String)
|
||||
-> Result = a
|
||||
; Result = 'not a' ),
|
||||
format('~w is ~w number.~n', [String, Result])
|
||||
)
|
||||
).
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
?- test_strings(["123", "0.123", "-123.1", "NotNum", "1."]).
|
||||
123 is a number.
|
||||
0.123 is a number.
|
||||
-123.1 is a number.
|
||||
NotNum is not a number.
|
||||
1. is not a number.
|
||||
true.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
s = '123'
|
||||
try:
|
||||
i = float(s)
|
||||
except ValueError, TypeError:
|
||||
except (ValueError, TypeError):
|
||||
print 'not numeric'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
s = '123'
|
||||
if s.isdigit():
|
||||
# numeric
|
||||
print int(s)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ if \datatype(yyy,'n') then say 'oops, not numeric:' yyy
|
|||
if \datatype(yyy,'N') then say 'oops, not numeric:' yyy
|
||||
if ¬datatype(yyy,'N') then say 'oops, not numeric:' yyy
|
||||
if ¬datatype(yyy,'numeric') then say 'oops, not numeric:' yyy
|
||||
if ¬datatype(yyy,'nimrod.') then say 'oops, not numeric:' yyy
|
||||
if ¬datatype(yyy,'nim.') then say 'oops, not numeric:' yyy
|
||||
if datatype(yyy)\=='NUM' then say 'oops, not numeric:' yyy
|
||||
if datatype(yyy)/=='NUM' then say 'oops, not numeric:' yyy
|
||||
if datatype(yyy)¬=='NUM' then say 'oops, not numeric:' yyy
|
||||
|
|
|
|||
|
|
@ -1 +1,49 @@
|
|||
isnumeric
|
||||
$Typecheck on
|
||||
|
||||
Defint FALSE, TRUE
|
||||
|
||||
FALSE = 0
|
||||
TRUE = NOT FALSE
|
||||
|
||||
Function isNumeric(s as string, optchar as string) as integer
|
||||
If len(s) = 0 then
|
||||
Result = FALSE
|
||||
Exit Function
|
||||
End If
|
||||
if instr(s,"+") > 1 then
|
||||
Result = FALSE
|
||||
exit function
|
||||
end if
|
||||
if instr(s,"-") > 1 then
|
||||
Result = FALSE
|
||||
exit function
|
||||
end if
|
||||
Defint i, ndex = 0
|
||||
For i = 1 to len(s)
|
||||
select case asc(mid$(s,i,1))
|
||||
case 43 '+
|
||||
case 45 '-
|
||||
case 46 '.
|
||||
if ndex = 1 then
|
||||
Result = FALSE
|
||||
Exit function
|
||||
end if
|
||||
ndex = 1
|
||||
case 48 to 57 '0 to 9
|
||||
case else
|
||||
if instr(optchar,(mid$(s,i,1))) = 0 then
|
||||
Result = FALSE
|
||||
exit function
|
||||
end if
|
||||
end select
|
||||
next
|
||||
Result = TRUE
|
||||
End Function
|
||||
|
||||
'============================================================
|
||||
'Begin
|
||||
'============================================================
|
||||
|
||||
showmessage (str$(isNumeric("-152.34","")))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ isNumeric = 1
|
|||
f$ = trim$(f$)
|
||||
if left$(f$,1) = "-" or left$(f$,1) = "+" then f$ = mid$(f$,2)
|
||||
for i = 1 to len(f$)
|
||||
if mid$(f$,i,1) = "." then
|
||||
if dot$ = "." then isNumeric = 0
|
||||
d$ = mid$(f$,i,1)
|
||||
if d$ = "," then goto [nxtDigit]
|
||||
if d$ = "." then
|
||||
if dot$ = "." then isNumeric = 0
|
||||
dot$ = "."
|
||||
goto [nxtDigit]
|
||||
end if
|
||||
if mid$(f$,i,1) = "," then goto [nxtDigit]
|
||||
if mid$(f$,i,1) < "0" then isNumeric = 0
|
||||
if mid$(f$,i,1) > "9" then isNumeric = 0
|
||||
if (d$ < "0") or (d$ > "9") then isNumeric = 0
|
||||
[nxtDigit]
|
||||
next i
|
||||
END FUNCTION
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
$ include "seed7_05.s7i";
|
||||
include "scanstri.s7i";
|
||||
|
||||
const func boolean: isNumeric (in var string: stri) is func
|
||||
result
|
||||
var boolean: isNumeric is FALSE;
|
||||
local
|
||||
var string: numberStri is "";
|
||||
begin
|
||||
numberStri := getNumber(stri);
|
||||
isNumeric := stri = "";
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue