Test integerness: Difference between revisions

→‎{{header|REXX}}: add complex numbers
(→‎{{header|J}}: remove specious {{{incomplete}}} tag; add alternative approach; format entry)
(→‎{{header|REXX}}: add complex numbers)
Line 31:
 
=={{header|REXX}}==
{{incomplete}}
<lang rexx>/* REXX ---------------------------------------------------------------
* 20.06.2014 Walter Pachl
* zero22.06.2014 andWP negativeadd wholecomplex numbers aresuch integers,as right?13-12j etc.
* (using 13e-12 or so is not (yet) supported)
*--------------------------------------------------------------------*/
Call test_integer 3.14
Line 44:
Call test_integer 'AA'
Call test_integer '0'
Call test_integer '1.000-33i'
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 xxx
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 xleft(xx,13) 'is not an integer (not even a number)'
/***********************************************
When x=0 Then
Say x 'is zero and thus not an integer'
When x<0 Then
Say x 'is negative and thus not an integer'
***********************************************/
Otherwise Do
If datatype(x,'W') Then
Say xleft(xx,13) 'is an integer'
Else
Say xleft(xx,13) 'isn''t an integer'
End
End
Return
parse_number: Procedure
</lang>
Parse Upper Arg x
x=translate(x,'I','J')
If pos('I',x)>0 Then Do
pi=verify(x,'+-','M')
Select
When x<0pi>1 Then Do
real=left(x,pi-1)
imag=substr(x,pi)
End
When xpi=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</lang>
'''output'''
<pre>3.14 isn't an integer
331.00000 is an integer
1.0000033 is an integer
999999999 is an integer
99999999999 is an integer
1E272 is an integer
AA is not an integer (not even a number)
0 is an integer
1.000-33i is not an integer</pre> (imaginary part is not zero)
1.000-3.3i is not an integer (imaginary part is not zero)
4j is not an integer (imaginary part is not zero)
2.00000000+0j is an integer
0j Say x 'is zero and thus not is an integer'
333 Say x 'is negative and thus not is an integer'
-1-i is not an integer (imaginary part is not zero)
1+i is not an integer (imaginary part is not zero)
.00i is an integer
j is not an integer (imaginary part is not zero)
0003-00.0j is an integer</pre>
 
=={{header|Tcl}}==
2,298

edits