Serhiy Storchaka <[email protected]> added the comment:
As for StackOverflow links provided by Robert, it looks to me that
float.is_integer() is always used improperly.
If keep this method it would be worth to warn against improper use of it.
Bad:
(x/5).is_integer()
Good:
x % 5 == 0
or
not x % 5
Bad:
math.sqrt(x).is_integer()
Good:
int(math.sqrt(x))**2 == x
Bad:
while x < y:
if x.is_integer():
print(x)
x += 0.1
Good (if initial x was integer):
x0 = x
i = 0
while x < y:
x = x0 + i/10
if not i % 10:
print(x)
i += 1
And provide an example of a *proper* use case (if it exists).
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue26680>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com