Test integerness: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: the isInt subroutine (function) was enhanced to handle big (gihugeic) integers.) |
m (→{{header|REXX}}: enhanced isInt subroutine to handle exponents larger than what REXX allows (for the exponent part of exponentiated numbers), added a ginormous number to 3rd version, allowed for wider numbers.) |
||
Line 261: | Line 261: | ||
numeric digits 3000 /*be able to handle big integers.*/ |
numeric digits 3000 /*be able to handle big integers.*/ |
||
parse arg #s /*get optional #s list from C.L. */ |
parse arg #s /*get optional #s list from C.L. */ |
||
if #s='' then #s= '3.14 1.00000 33 999999999 99999999999 1e272 AA 0' , |
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.000-3i 1.000-3.3i 4j 2.00000000+0j 0j 333 -1-i' , |
||
'1+i .00i j 0003-00.0j 1.2d1 |
'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' |
'-.3q+2 -0i +03.0e+01+0.00e+20j -030.0e-001+0.0e-020j' |
||
/* [↑] use these #s for defaults*/ |
/* [↑] use these #s for defaults*/ |
||
Line 270: | Line 270: | ||
x=translate(x, 'EEI', "QDJ") /*alt. exponent & imag indicator.*/ |
x=translate(x, 'EEI', "QDJ") /*alt. exponent & imag indicator.*/ |
||
if right(x,1)=='I' then call tImag /*has the X number an imag. part?*/ |
if right(x,1)=='I' then call tImag /*has the X number an imag. part?*/ |
||
if isInt(x) then say right(ox, |
if isInt(x) then say right(ox,55) " is an integer." /*yup. */ |
||
else say right(ox, |
else say right(ox,55) " isn't an integer." /*nope.*/ |
||
end /*j*/ /* [↑] process each # in list. */ |
end /*j*/ /* [↑] process each # in list. */ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
Line 277: | Line 277: | ||
isInt: procedure; parse arg n /*obtain the number in question. */ |
isInt: procedure; parse arg n /*obtain the number in question. */ |
||
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */ |
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */ |
||
parse var n 'E' p /*separate base from the 10's pow*/ |
|||
⚫ | |||
if p=='' then return 0 /*no exponent, then not integer. */ |
|||
⚫ | |||
return |
return p>0 /*Is power positive? It's an int*/ |
||
/*──────────────────────────────────ISSIGN subroutine───────────────────*/ |
/*──────────────────────────────────ISSIGN subroutine───────────────────*/ |
||
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */ |
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */ |
||
Line 311: | Line 312: | ||
'''output''' using the default input: |
'''output''' using the default input: |
||
<pre> |
<pre> |
||
3.14 isn't an integer. |
3.14 isn't an integer. |
||
1.00000 is an integer. |
1.00000 is an integer. |
||
33 is an integer. |
33 is an integer. |
||
999999999 is an integer. |
999999999 is an integer. |
||
99999999999 is an integer. |
99999999999 is an integer. |
||
1e272 is an integer. |
1e272 is an integer. |
||
AA isn't an integer. |
AA isn't an integer. |
||
0 is an integer. |
0 is an integer. |
||
1.000-3i isn't an integer. |
1.000-3i isn't an integer. |
||
1.000-3.3i isn't an integer. |
1.000-3.3i isn't an integer. |
||
4j isn't an integer. |
4j isn't an integer. |
||
2.00000000+0j is an integer. |
2.00000000+0j is an integer. |
||
0j is an integer. |
0j is an integer. |
||
333 is an integer. |
333 is an integer. |
||
-1-i isn't an integer. |
-1-i isn't an integer. |
||
1+i isn't an integer. |
1+i isn't an integer. |
||
.00i is an integer. |
.00i is an integer. |
||
j isn't an integer. |
j isn't an integer. |
||
0003-00.0j is an integer. |
0003-00.0j is an integer. |
||
1.2d1 is an integer. |
1.2d1 is an integer. |
||
2e55666 is an integer. |
2e55666 is an integer. |
||
+0003-00.0j is an integer. |
+0003-00.0j is an integer. |
||
+0j is an integer. |
+0j is an integer. |
||
-.3q+2 is an integer. |
-.3q+2 is an integer. |
||
-0i is an integer. |
-0i is an integer. |
||
+03.0e+01+0.00e+20j is an integer. |
+03.0e+01+0.00e+20j is an integer. |
||
-030.0e-001+0.0e-020j is an integer. |
-030.0e-001+0.0e-020j is an integer. |
||
</pre> |
</pre> |
||
Line 351: | Line 352: | ||
unaA='+ + - -' /*list of unary operators trans. */ |
unaA='+ + - -' /*list of unary operators trans. */ |
||
parse arg #s /*get optional #s list from C.L. */ |
parse arg #s /*get optional #s list from C.L. */ |
||
if #s='' then #s= '245+-00.0e-12i |
if #s='' then #s= '245+-00.0e-12i 245++++++0e+12j --3450d-1----0.0d-1j' , |
||
'4.5e11111222223333344444555556666677777888889999900' |
|||
/* [↑] use these #s for defaults*/ |
/* [↑] use these #s for defaults*/ |
||
do j=1 for words(#s); ox=word(#s,j) /*obtain a word from the #s list.*/ |
do j=1 for words(#s); ox=word(#s,j) /*obtain a word from the #s list.*/ |
||
Line 366: | Line 368: | ||
if right(x,1)=='J' then call tImag /*has the X number an imag. part?*/ |
if right(x,1)=='J' then call tImag /*has the X number an imag. part?*/ |
||
if isInt(x) then say right(ox, |
if isInt(x) then say right(ox,55) " is an integer." /*yup. */ |
||
else say right(ox, |
else say right(ox,55) " isn't an integer." /*nope.*/ |
||
end /*j*/ |
end /*j*/ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
Line 373: | Line 375: | ||
isInt: procedure; parse arg n /*obtain the number in question. */ |
isInt: procedure; parse arg n /*obtain the number in question. */ |
||
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */ |
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */ |
||
parse var n 'E' p /*separate base from the 10's pow*/ |
|||
⚫ | |||
if p=='' then return 0 /*no exponent, then not integer. */ |
|||
⚫ | |||
return |
return p>0 /*Is power positive? It's an int*/ |
||
/*──────────────────────────────────ISSIGN subroutine───────────────────*/ |
/*──────────────────────────────────ISSIGN subroutine───────────────────*/ |
||
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */ |
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */ |
||
Line 407: | Line 410: | ||
'''output''' using the default input: |
'''output''' using the default input: |
||
<pre> |
<pre> |
||
245+-00.0e-12i is an integer. |
245+-00.0e-12i is an integer. |
||
245++++++0e+12j |
245++++++0e+12j isn't an integer. |
||
--3450d-1----0.0d-1j is an integer. |
--3450d-1----0.0d-1j is an integer. |
||
4.5e11111222223333344444555556666677777888889999900 is an integer. |
|||
</pre> |
</pre> |
||