Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
: number? >n >kind ns:n n:= ;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
String numericString = '123456';
|
||||
String partlyNumericString = '123DMS';
|
||||
String decimalString = '123.456';
|
||||
|
||||
System.debug(numericString.isNumeric()); // this will be true
|
||||
System.debug(partlyNumericString.isNumeric()); // this will be false
|
||||
System.debug(decimalString.isNumeric()); // this will be false
|
||||
System.debug(decimalString.remove('.').isNumeric()); // this will be true
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(string->number "albert")
|
||||
→ #f
|
||||
(string->number -666)
|
||||
→ -666
|
||||
(if (string->number 666) 'YES 'NO)
|
||||
→ YES
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim Shared symbols(0 To 15) As UByte
|
||||
For i As Integer = 48 to 57
|
||||
symbols(i - 48) = i
|
||||
Next
|
||||
For i As Integer = 97 to 102
|
||||
symbols(i - 87) = i
|
||||
Next
|
||||
|
||||
Const plus As UByte = 43
|
||||
Const minus As Ubyte = 45
|
||||
Const dot As UByte = 46
|
||||
|
||||
Function isNumeric(s As Const String, base_ As Integer = 10) As Boolean
|
||||
If s = "" OrElse s = "." OrElse s = "+" OrElse s = "-" Then Return False
|
||||
Err = 0
|
||||
|
||||
If base_ < 2 OrElse base_ > 16 Then
|
||||
Err = 1000
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim t As String = LCase(s)
|
||||
|
||||
If (t[0] = plus) OrElse (t[0] = minus) Then
|
||||
t = Mid(t, 2)
|
||||
End If
|
||||
|
||||
If Left(t, 2) = "&h" Then
|
||||
If base_ <> 16 Then Return False
|
||||
t = Mid(t, 3)
|
||||
End if
|
||||
|
||||
If Left(t, 2) = "&o" Then
|
||||
If base_ <> 8 Then Return False
|
||||
t = Mid(t, 3)
|
||||
End if
|
||||
|
||||
If Left(t, 2) = "&b" Then
|
||||
If base_ <> 2 Then Return False
|
||||
t = Mid(t, 3)
|
||||
End if
|
||||
|
||||
If Len(t) = 0 Then Return False
|
||||
Dim As Boolean isValid, hasDot = false
|
||||
|
||||
For i As Integer = 0 To Len(t) - 1
|
||||
isValid = False
|
||||
|
||||
For j As Integer = 0 To base_ - 1
|
||||
If t[i] = symbols(j) Then
|
||||
isValid = True
|
||||
Exit For
|
||||
End If
|
||||
If t[i] = dot Then
|
||||
If CInt(Not hasDot) AndAlso (base_ = 10) Then
|
||||
hasDot = True
|
||||
IsValid = True
|
||||
Exit For
|
||||
End If
|
||||
Return False ' either more than one dot or not base 10
|
||||
End If
|
||||
Next j
|
||||
|
||||
If Not isValid Then Return False
|
||||
Next i
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Dim s As String
|
||||
s = "1234.056789"
|
||||
Print s, " (base 10) => "; isNumeric(s)
|
||||
s = "1234.56"
|
||||
Print s, " (base 7) => "; isNumeric(s, 7)
|
||||
s = "021101"
|
||||
Print s, " (base 2) => "; isNumeric(s, 2)
|
||||
s = "Dog"
|
||||
Print s, " (base 16) => "; isNumeric(s, 16)
|
||||
s = "Bad125"
|
||||
Print s, " (base 16) => "; isNumeric(s, 16)
|
||||
s = "-0177"
|
||||
Print s, " (base 8) => "; isNumeric(s, 8)
|
||||
s = "+123abcd.ef"
|
||||
Print s, " (base 16) => "; isNumeric(s, 8)
|
||||
s = "54321"
|
||||
Print s, " (base 6) => "; isNumeric(s, 6)
|
||||
s = "123xyz"
|
||||
Print s, " (base 10) => "; isNumeric(s)
|
||||
s = "xyz"
|
||||
Print s, " (base 10) => "; isNumeric(s)
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
function numeric(""n) {
|
||||
number(n)
|
||||
issues {
|
||||
print(n, " is not numeric!")
|
||||
return
|
||||
}
|
||||
print(n, " is numeric :)")
|
||||
}
|
||||
|
||||
software {
|
||||
numeric("1200")
|
||||
numeric("3.14")
|
||||
numeric("3/4")
|
||||
numeric("abcdefg")
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
local(str='12345')
|
||||
string_isNumeric(#str) // true
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
'12345'->isdigit // true
|
||||
'1X34Q'->isdigit // false
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import strutils
|
||||
let s = "123"
|
||||
var f: float
|
||||
try:
|
||||
f = parseFloat s
|
||||
except EInvalidValue:
|
||||
echo "not numeric"
|
||||
|
||||
if s.contains AllChars - Digits:
|
||||
echo "not a positive integer"
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
Built-In Function
|
||||
Syntax
|
||||
|
||||
IsNumber(Value)
|
||||
Description
|
||||
|
||||
Use the IsNumber function to determine if Value contains a valid numeric value. Numeric characters include sign indicators and comma and period decimal points.
|
||||
To determine if a value is a number and if it's in the user's local format, use the IsUserNumber function.
|
||||
|
||||
Parameters
|
||||
|
||||
Value
|
||||
Specify a string you want to search to determine if it is a valid number.
|
||||
|
||||
Returns
|
||||
A Boolean value: True if Value contains a valid numeric value, False otherwise.
|
||||
|
||||
Example
|
||||
|
||||
&Value = Get Field().Value;
|
||||
If IsNumber(&Value) Then
|
||||
/* do numeric processing */
|
||||
Else
|
||||
/* do non-numeric processing */
|
||||
End-if;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function isNumber(string s)
|
||||
return scanf(s,"%f")!={}
|
||||
end function
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
function testset(sequence s)
|
||||
for i=1 to length(s) do
|
||||
s[i] = isNumber(s[i])
|
||||
end for
|
||||
return s
|
||||
end function
|
||||
?testset({"#a","#A","0xA","0(16)A","#FF","255","0",".14",".05","-5.2","0xf","ten","1B"})
|
||||
?testset({" 12 ",trim(" 12 ")})
|
||||
?testset({"0o16","0o18"})
|
||||
?testset({"1_000","0b10101111_11110000_11110000_00110011","-0b10101","0x10.5",""," ","1.","50e"})
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
see isdigit("0123456789") + nl + # print 1
|
||||
isdigit("0123a") # print 0
|
||||
|
|
@ -0,0 +1 @@
|
|||
say "0.1E-5".looks_like_number; #=> true
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
func is_numeric(s) {
|
||||
(s ~~ /^[+-]?+(?=\.?[0-9])[0-9_]*+(?:\.[0-9_]++)?(?:[Ee](?:[+-]?+[0-9_]+))?\z/) ||
|
||||
(s ~~ /^0(?:b[10_]*|x[0-9A-Fa-f_]*|[0-9_]+\b)\z/)
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var strings = %w(0 0.0 -123 abc 0x10 0xABC 123a -123e3 0.1E-5 50e);
|
||||
for str in strings {
|
||||
say ("%9s => %s" % (str, is_numeric(str)))
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func isNumeric(a: String) -> Bool {
|
||||
return Double(a) != nil
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func isNumeric(a: String) -> Bool {
|
||||
return a.toInt() != nil
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
def isnum (string str)
|
||||
try
|
||||
double str
|
||||
return true
|
||||
catch valueerror
|
||||
return false
|
||||
end try
|
||||
end isnum
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(DEFUN NUMERICP (X)
|
||||
(IF (STRING->NUMBER X) T))
|
||||
|
|
@ -0,0 +1 @@
|
|||
try tonumber catch false
|
||||
|
|
@ -0,0 +1 @@
|
|||
def is_numeric: true and try tonumber catch false;
|
||||
Loading…
Add table
Add a link
Reference in a new issue