Mark Dickinson <dicki...@gmail.com> added the comment: One quibble with Raymond's response:
> 2) Your use case is trivially solved in a portable, trivial, and readable > > way: > > a == int(a) For Decimal, I'd recommend using `a == a.to_integral_value()` instead. Using `a == int(a)` will be inefficient if `a` has large exponent, so it's not a good general-purpose solution (though it's probably good enough in most real-world cases). Here's an extreme example: In [1]: import decimal In [2]: x = decimal.Decimal('1e99999') In [3]: %timeit x == int(x) 1.42 s ± 6.27 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) In [4]: %timeit x == x.to_integral_value() 230 ns ± 2.03 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue26680> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com