Anonymous user
Test integerness: Difference between revisions
→{{header|REXX}}: the isInt subroutine (function) was enhanced to handle big (gihugeic) integers.
(→{{header|REXX}}: added version 2 and 3.) |
(→{{header|REXX}}: the isInt subroutine (function) was enhanced to handle big (gihugeic) integers.) |
||
Line 257:
This REXX version handles an exponent indicator of '''E''', '''D''', or '''Q''' (either lower or uppercase), and it also supports a trailing '''I''' or '''J''' imaginary indicator.
<lang rexx>/*REXX pgm tests if a # (possibly complex) is equivalent to an integer.*/
numeric digits
parse arg #s /*get optional #s list from C.L. */
if #s='' then #s= '3.14 1.00000 33 999999999 99999999999 1e272 AA 0' ,
Line 275 ⟶ 274:
end /*j*/ /* [↑] process each # in list. */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────ISINT subroutine────────────────────*/
isInt:
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */
if \datatype(n, 'Numn') then return 0 /*Not an integer if not a number.*/
parse var n 'E' pow /*separate base from the 10's pow*/
return pow>0 /*Exponent positive? It's an int*/
/*──────────────────────────────────ISSIGN subroutine───────────────────*/
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */
/*──────────────────────────────────TIMAG subroutine────────────────────*/
Line 327 ⟶ 331:
0003-00.0j is an integer.
1.2d1 is an integer.
+0003-00.0j is an integer.
+0j is an integer.
Line 343 ⟶ 347:
would be considered an integer (extra blanks were added to show the number with more clarity).
<lang rexx>/*REXX pgm tests if a # (possibly complex) is equivalent to an integer.*/
numeric digits
unaB='++ -- -+ +-' /*list of unary operators. */
unaA='+ + - -' /*list of unary operators trans. */
Line 366 ⟶ 370:
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────ISINT subroutine────────────────────*/
isInt:
if datatype(n, 'Whole') then return 1 /*it's a simple integer (small). */
if \datatype(n, 'Numn') then return 0 /*Not an integer if not a number.*/
parse var n 'E' pow /*separate base from the 10's pow*/
return pow>0 /*Exponent positive? It's an int*/
/*──────────────────────────────────ISSIGN subroutine───────────────────*/
isSign: arg ? 2; return ?=='+' |?=='-' /*concise method to test a sign. */
/*──────────────────────────────────TIMAG subroutine────────────────────*/
|