Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,56 @@
|
|||
DATA "PI", "0123", "-0123", "12.30", "-12.30", "123!", "0"
|
||||
DATA "0.0", ".123", "-.123", "12E3", "12E-3", "12+3", "end"
|
||||
|
||||
|
||||
while n$ <> "end"
|
||||
read n$
|
||||
print n$, IsNumber(n$)
|
||||
wend
|
||||
end
|
||||
|
||||
function IsNumber(string$)
|
||||
on error goto [NotNumber]
|
||||
string$ = trim$(string$)
|
||||
'check for float overflow
|
||||
n = val(string$)
|
||||
|
||||
'assume it is number and try to prove wrong
|
||||
IsNumber = 1
|
||||
for i = 1 to len(string$)
|
||||
select case mid$(string$, i, 1)
|
||||
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
|
||||
HasNumeric = 1 'to check if there are any digits
|
||||
case "e", "E"
|
||||
'"e" must not occur more than once
|
||||
'must not occur before digits
|
||||
|
||||
if HasE > 0 or HasNumeric = 0 then
|
||||
IsNumber = 0
|
||||
exit for
|
||||
end if
|
||||
HasE = i 'store position of "e"
|
||||
HasNumeric = 0 'needs numbers after "e"
|
||||
case "-", "+"
|
||||
'must be either first character or immediately after "e"
|
||||
'(HasE = 0 if no occurrences yet)
|
||||
if HasE <> i-1 then
|
||||
IsNumber = 0
|
||||
exit for
|
||||
end if
|
||||
case "."
|
||||
'must not have previous points and must not come after "e"
|
||||
if HasE <> 0 or HasPoint <> 0 then
|
||||
IsNumber = 0
|
||||
exit for
|
||||
end if
|
||||
HasPoint = 1
|
||||
case else
|
||||
'no other characters allowed
|
||||
IsNumber = 0
|
||||
exit for
|
||||
end select
|
||||
next i
|
||||
'must have digits
|
||||
if HasNumeric = 0 then IsNumber = 0
|
||||
[NotNumber]
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue