Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,88 @@
/* REXX ---------------------------------------------------------------
* 20.06.2014 Walter Pachl
* 22.06.2014 WP add complex numbers such as 13-12j etc.
* (using 13e-12 or so is not (yet) supported)
*--------------------------------------------------------------------*/
Call test_integer 3.14
Call test_integer 1.00000
Call test_integer 33
Call test_integer 999999999
Call test_integer 99999999999
Call test_integer 1e272
Call test_integer 'AA'
Call test_integer '0'
Call test_integer '1.000-3i'
Call test_integer '1.000-3.3i'
Call test_integer '4j'
Call test_integer '2.00000000+0j'
Call test_integer '0j'
Call test_integer '333'
Call test_integer '-1-i'
Call test_integer '1+i'
Call test_integer '.00i'
Call test_integer 'j'
Call test_integer '0003-00.0j'
Exit
test_integer:
Parse Arg xx
Numeric Digits 1000
Parse Value parse_number(xx) With x imag
If imag<>0 Then Do
Say left(xx,13) 'is not an integer (imaginary part is not zero)'
Return
End
Select
When datatype(x)<>'NUM' Then
Say left(xx,13) 'is not an integer (not even a number)'
Otherwise Do
If datatype(x,'W') Then
Say left(xx,13) 'is an integer'
Else
Say left(xx,13) 'isn''t an integer'
End
End
Return
parse_number: Procedure
Parse Upper Arg x
x=translate(x,'I','J')
If pos('I',x)>0 Then Do
pi=verify(x,'+-','M')
Select
When pi>1 Then Do
real=left(x,pi-1)
imag=substr(x,pi)
End
When pi=0 Then Do
real=0
imag=x
End
Otherwise /*pi=1*/Do
p2=verify(substr(x,2),'+-','M')
If p2>0 Then Do
real=left(x,p2)
imag=substr(x,p2+1)
End
Else Do
real=0
imag=x
End
End
End
End
Else Do
real=x
imag='0I'
End
pi=verify(imag,'+-','M')
If pi=0 Then Do
Parse Var imag imag_v 'I'
imag_sign='+'
End
Else
Parse Var imag imag_sign 2 imag_v 'I'
If imag_v='' Then
imag_v=1
imag=imag_sign||imag_v
Return real imag

View file

@ -0,0 +1,24 @@
/* REXX ---------------------------------------------------------------
* Extra credit
* Instead of using the datatype built-in function one could use this
*--------------------------------------------------------------------*/
Call testi 25.000000
Call testi 24.999999
Call testi 25.000100
Call testi 0.9999999
Call testi -0.9999999
Exit
testi:
Parse Arg x
If pos('.',x)>0 Then Do
xx=abs(x)
Parse Value abs(xx) With '.' d
d5=left(d,5,0)
End
Else d5=''
If d5='' | wordpos(d5,'00000 99999')>0 Then
Say x 'is an integer'
Else
Say x 'isn''t an integer'
Return

View file

@ -0,0 +1,50 @@
/*REXX program tests if a number (possibly complex) is equivalent to an integer. */
numeric digits 3000 /*be able to handle gihugic integers. */
parse arg #s /*obtain optional numbers list from CL.*/
if #s='' then #s= '3.14 1.00000 33 999999999 99999999999 1e272 AA 0' ,
'1.000-3i 1.000-3.3i 4j 2.00000000+0j 0j 333 -1-i' ,
'1+i .00i j 0003-00.0j 1.2d1 2e55666 +0003-00.0j +0j' ,
'-.3q+2 -0i +03.0e+01+0.00e+20j -030.0e-001+0.0e-020j'
/* [↑] use these numbers for defaults.*/
do j=1 for words(#s); ox=word(#s, j) /*obtain a number from the numbers list*/
parse upper var ox x /*obtain an uppercase version of OX. */
x=translate(x, 'EEI', "QDJ") /*translate exponent and imag indicator*/
if right(x, 1)=='I' then call tImag /*has the X number an imaginary part?*/
if isInt(x) then say right(ox, 55) " is an integer." /*yuppers, it does. */
else say right(ox, 55) " isn't an integer." /*noppers, it doesn't*/
end /*j*/ /* [↑] process each number in the list*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isInt: procedure; parse arg n /*obtain the number in question. */
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */
parse var n m 'E' p /*separate base from the 10's power. */
if \datatype(p, 'Numb') then return 0 /*Not an integer if P not an integer.*/
return p>0 | m=0 /*is power>0 or mantissa = zero? */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isSign: parse arg ? 2; return ?=='+' | ?=="-" /*a method to test for a leading sign. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tImag: x=left(x, length(x) -1) /*strip the trailing I or J from number*/
if isInt(x) then do /*is what's remaining an integer ? */
if x\=0 then x=. /*what's remaining isn't equal to zero.*/
return /*return to invoker in either case. */
end /* [↑] handle simple imaginary case. */
if isSign(x) then x=substr(x, 2) /*X has a sign? Strip the leading sign*/
e=verify(x, .0123456789) /*find 1st char not a digit or a dot. */
if e==0 then do; x=.; return; end /*Nothing? Then it's not an integer. */
y=substr(x, e, 1) /*Y is the suspect character. */
if isSign(y) then do /*is suspect character a plus or minus?*/
z=substr(x, e+1) /*obtain the imaginary part of X. */
x= left(x, e-1) /* " " real " " " */
if isInt(z) then if z=0 then return /*imaginary part is 0*/
x=. /*the imaginary part isn't zero. */
end /* [↑] end of imaginary part of X. */
if y\=='E' then return /*real part of X doesn't have an expon.*/
p=substr(x, e+1) /*obtain power of real part of X. */
_= left(p, 1) /*obtain the possible sign of the power*/
if isSign(_) then p=substr(p, 2) /*strip the sign from the exponent. */
s=verify(p, '-+', "M") /*is there an imaginary separator char?*/
if s==0 then do; x=.; return; end /*No sign? Then isn't not an integer.*/
z=substr(p, s+1) /*obtain the the imaginary part of X. */
x= left(x, e+s) /* " " " real " " " */
if isInt(z) then if z\=0 then x=. /*Not imaginary part=0? Not an integer.*/
return /*return to the invoker of this sub. */

View file

@ -0,0 +1,59 @@
/*REXX program tests if a number (possibly complex) is equivalent to an integer. */
numeric digits 3000 /*be able to handle gihugic integers. */
unaB= '++ -- -+ +-' /*a list of unary operators.*/
unaA= '+ + - -' /*" " " translated " " */
parse arg #s /*obtain optional numbers list from CL.*/
if #s='' then #s= '245+-00.0e-12i 245++++++0e+12j --3450d-1----0.0d-1j' ,
'4.5e11111222223333344444555556666677777888889999900'
/* [↑] use these numbers for defaults.*/
do j=1 for words(#s); ox=word(#s, j) /*obtain a number from the numbers list*/
parse upper var ox x /*obtain an uppercase version of OX. */
x=translate(x, 'EEJ', "QDI") /*translate exponent and imag indicator*/
do k=1 for words(unaB) /*process every possible unary operator*/
_=word(unaB, k) /*a unary operator to be changed, maybe*/
do while pos(_, x) \== 0 /*keep changing until no more are left.*/
x=changestr(_, x, word(unaA, k) ) /*reduce all unary operators (if any).*/
end /*while*/
end /*k*/
if right(x, 1)=='J' then call tImag /*has the X number an imaginary part?*/
if isInt(x) then say right(ox, 55) " is an integer." /*yuppers, it does. */
else say right(ox, 55) " isn't an integer." /*noppers, it doesn't*/
end /*j*/ /* [↑] process each number in the list*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isInt: procedure; parse arg n /*obtain the number in question. */
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */
parse var n m 'E' p /*separate base from the 10's power. */
if \datatype(p, 'Numb') then return 0 /*Not an integer if P not an integer.*/
return p>0 | m=0 /*is power>0 or mantissa = zero? */
/*──────────────────────────────────────────────────────────────────────────────────────*/
isSign: parse arg ? 2; return ?=='+' | ?=="-" /*a method to test for a leading sign. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tImag: x=left(x, length(x) -1) /*strip the trailing I or J from number*/
if isInt(x) then do /*is what's remaining an integer ? */
if x\=0 then x=. /*what's remaining isn't equal to zero.*/
return /*return to invoker in either case. */
end /* [↑] handle simple imaginary case. */
if isSign(x) then x=substr(x, 2) /*X has a sign? Strip the leading sign*/
e=verify(x, .0123456789) /*find 1st char not a digit or a dot. */
if e==0 then do; x=.; return; end /*Nothing? Then it's not an integer. */
y=substr(x, e, 1) /*Y is the suspect character. */
if isSign(y) then do /*is suspect character a plus or minus?*/
z=substr(x, e+1) /*obtain the imaginary part of X. */
x= left(x, e-1) /* " " real " " " */
if isInt(z) then if z=0 then return /*imaginary part is 0*/
x=. /*the imaginary part isn't zero. */
end /* [↑] end of imaginary part of X. */
if y\=='E' then return /*real part of X doesn't have an expon.*/
p=substr(x, e+1) /*obtain power of real part of X. */
_= left(p, 1) /*obtain the possible sign of the power*/
if isSign(_) then p=substr(p, 2) /*strip the sign from the exponent. */
s=verify(p, '-+', "M") /*is there an imaginary separator char?*/
if s==0 then do; x=.; return; end /*No sign? Then isn't not an integer.*/
z=substr(p, s+1) /*obtain the the imaginary part of X. */
x= left(x, e+s) /* " " " real " " " */
if isInt(z) then if z\=0 then x=. /*Not imaginary part=0? Not an integer.*/
return /*return to the invoker of this sub. */