Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -6,7 +6,6 @@
|
|||
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.
|
||||
|
|
@ -18,11 +17,9 @@
|
|||
LINKAGE SECTION.
|
||||
01 Str PIC X(30).
|
||||
|
||||
PROCEDURE DIVISION USING BY VALUE Str.
|
||||
|
||||
PROCEDURE DIVISION USING Str.
|
||||
IF Str = SPACES
|
||||
MOVE Failure TO Return-Code
|
||||
|
||||
GOBACK
|
||||
END-IF
|
||||
|
||||
|
|
@ -31,7 +28,6 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ is-numeric s:
|
|||
not
|
||||
|
||||
for v in [ "1" "0" "3.14" "hello" "12e3" "12ef" "-3" ]:
|
||||
.( v is-numeric v )
|
||||
!.( v is-numeric v )
|
||||
|
|
|
|||
|
|
@ -1,20 +1,15 @@
|
|||
% Is string numeric?
|
||||
|
||||
function [out] = str_isnumeric(string)
|
||||
|
||||
if ~ischar(string)
|
||||
error('str_isnumeric:NonCharacterArray','not a string input');
|
||||
% Is string numeric?
|
||||
function out = is_str_numeric(s)
|
||||
out = ~isempty(parse_float(s));
|
||||
end
|
||||
|
||||
Nd = sum(isstrprop(string,'digit'));
|
||||
Nc = length(string);
|
||||
|
||||
dN = Nc - Nd;
|
||||
|
||||
switch dN
|
||||
case 0
|
||||
out = 1;
|
||||
otherwise
|
||||
out = 0;
|
||||
% Returns the float (double) if true, empty array otherwise.
|
||||
function f = parse_float(s)
|
||||
[f_in_cell, pos] = textscan(s, '%f');
|
||||
% Make sure there are no trailing chars. textscan(..) is greedy.
|
||||
if pos == length(s)
|
||||
f = f_in_cell{:};
|
||||
else
|
||||
f = [];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,30 +2,31 @@
|
|||
yyy=' -123.78' /*or some such.*/
|
||||
|
||||
/*strings below are all numeric (REXX).*/
|
||||
zzz=' -123.78 '
|
||||
zzz=' -123.78 '
|
||||
zzz='-123.78'
|
||||
zzz='2'
|
||||
zzz="2"
|
||||
zzz=2
|
||||
zzz='000000000004'
|
||||
zzz='+5'
|
||||
zzz=' +6 '
|
||||
zzz=' + 7 '
|
||||
zzz=' - 8 '
|
||||
zzz=' - .9'
|
||||
zzz='- 19.'
|
||||
zzz=' +6 '
|
||||
zzz=' + 7 '
|
||||
zzz=' - 8 '
|
||||
zzz=' - .9 '
|
||||
zzz='- 19.'
|
||||
zzz='.7'
|
||||
zzz='2e3'
|
||||
zzz=47e567
|
||||
zzz='2e-3'
|
||||
zzz='1.2e1'
|
||||
zzz=' .2E6'
|
||||
zzz=' 2.e5 '
|
||||
zzz=' +1.2E0002 '
|
||||
zzz=' +1.2e+002 '
|
||||
zzz=' +0000001.200e+002 '
|
||||
zzz=' - 000001.200e+002 '
|
||||
zzz=' - 000008.201e-00000000000000002 '
|
||||
zzz=' .2E6'
|
||||
zzz=' 2.e5 '
|
||||
zzz=' +1.2E0002 '
|
||||
zzz=' +1.2e+002 '
|
||||
zzz=' +0000001.200e+002 '
|
||||
zzz=' - 000001.200e+002 '
|
||||
zzz=' - 000008.201e-00000000000000002 '
|
||||
ifx=i
|
||||
|
||||
/*Note: some REXX interpreters allow use of tab chars as blanks. */
|
||||
|
||||
|
|
@ -44,3 +45,4 @@ if datatype(yyy)¬= 'NUM' then say 'oops, not numeric:' yyy
|
|||
/*note: REXX only looks at the first char for DATATYPE's 2nd arg. */
|
||||
|
||||
/*note: some REXX interpreters don't support the ¬ (not) character.*/
|
||||
/*note: " " " " " the / as negation. */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
def isNumeric2(str: String): Boolean = {
|
||||
str.matches(s"""[+-]?((\d+(e\d+)?[lL]?)|(((\d+(\.\d*)?)|(\.\d+))(e\d+)?[fF]?))""")
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def isNumeric(str: String): Boolean = {
|
||||
!throwsNumberFormatException(str.toLong) || !throwsNumberFormatException(str.toDouble)
|
||||
}
|
||||
|
||||
def throwsNumberFormatException(f: => Any): Boolean = {
|
||||
try { f; false } catch { case e: NumberFormatException => true }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue