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.
 
DueThis toversion the way REXXalso handles numbers, anylarger number thatthan can be expressed simplystored (withoutwithin exponential notationREXX) as simple integers within the limits of '''numeric digits''' is considered an integer.
<br>Thus, with '''numeric digits 100''', a number such as '''1e101''' wouldn't be considered an integer (within the rules of REXX).
<lang rexx>/*REXX pgm tests if a # (possibly complex) is equivalent to an integer.*/
numeric digits 100003000 /*be able to handle big integers.*/
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────────────────────*/
/*──────────────────────────────────one-liner subroutines───────────────*/
isInt: returnprocedure; parse datatype(arg(1),'Whole') n /*compactobtain methodthe tonumber testin integerquestion. */
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.
12.3q72e55666 is an integer.
+0003-00.0j is an integer.
+0j is an integer.
Line 343 ⟶ 347:
would be considered an integer &nbsp; (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 100003000 /*be able to handle big integers.*/
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────────────────────*/
/*──────────────────────────────────one-liner subroutines───────────────*/
isInt: returnprocedure; parse datatype(arg(1),'Whole') n /*compactobtain methodthe tonumber testin integerquestion. */
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────────────────────*/