Test integerness: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Updated to handle ints, floats, and complex types.)
Line 23: Line 23:


=={{header|Python}}==
=={{header|Python}}==
{{incomplete}}
<lang python>>>> def isint(f):
<lang python>>>> def isint(f):
return int(f) == f
return complex(f).imag == 0 and int(complex(f).real) == complex(f).real


>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))]
>>> isint(3.14)
[True, True, True, False, False, False]
False
>>> isint(3.0)
True
>>> </lang>
>>> </lang>