This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,24 @@
integer
numeric(text s)
{
return alpha(s, 0);
}
integer
is_numeric(text s)
{
return !trap(numeric, s);
}
integer
main(void)
{
if (!is_numeric("8192&*")) {
o_text("Not numeric.\n");
}
if (is_numeric("8192")) {
o_text("Numeric.\n");
}
return 0;
}

View file

@ -0,0 +1,58 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Is-Numeric.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Numeric-Chars PIC X(10) VALUE "0123456789".
01 Success CONSTANT 0.
*> By convention, a non-zero value is used to signify failure
01 Failure CONSTANT 128.
LOCAL-STORAGE SECTION.
01 I PIC 99.
01 Num-Decimal-Points PIC 99.
01 Num-Valid-Chars PIC 99.
LINKAGE SECTION.
01 Str PIC X(30).
PROCEDURE DIVISION USING BY VALUE Str.
IF Str = SPACES
MOVE Failure TO Return-Code
GOBACK
END-IF
MOVE FUNCTION TRIM(Str) TO Str
INSPECT Str TALLYING Num-Decimal-Points FOR ALL "."
IF Num-Decimal-Points > 1
MOVE Failure TO Return-Code
GOBACK
ELSE
ADD Num-Decimal-Points TO Num-Valid-Chars
END-IF
IF Str (1:1) = "-" OR "+"
ADD 1 TO Num-Valid-Chars
END-IF
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
INSPECT Str TALLYING Num-Valid-Chars
FOR ALL Numeric-Chars (I:1) BEFORE SPACE
END-PERFORM
INSPECT Str TALLYING Num-Valid-Chars FOR TRAILING SPACES
IF Num-Valid-Chars = FUNCTION LENGTH(Str)
MOVE Success TO Return-Code
ELSE
MOVE Failure TO Return-Code
END-IF
GOBACK
.

View file

@ -1,6 +1,9 @@
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var value = "123.45e7"; // Assign string literal to value
if (isFinite(value)) {
if (isNumeric(value)) {
// value is a number
}
//Or, in web browser in address field:
// javascript:value="123.45e4"; if(isFinite(value)) {alert('numeric')} else {alert('non-numeric')}
// javascript:function isNumeric(n) {return !isNaN(parseFloat(n)) && isFinite(n);}; value="123.45e4"; if(isNumeric(value)) {alert('numeric')} else {alert('non-numeric')}

View file

@ -0,0 +1 @@
(define (string-numeric? s) (number? (string->number s)))

View file

@ -0,0 +1 @@
(define string-numeric? string->number)

View file

@ -0,0 +1,21 @@
#!/bin/bash
isnum() {
printf "%f" $1 >/dev/null 2>&1
}
check() {
if isnum $1
then
echo "$1 is numeric"
else
echo "$1 is NOT numeric"
fi
}
check 2
check -3
check +45.44
check -33.332
check 33.aa
check 3.3.3