This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Austin Bingham, christian.heimes, facundobatista, mark.dickinson, rhettinger, robert_smallshire, serhiy.storchaka, skrah, tim.peters
Date 2018-03-12.12:59:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520859540.3.0.467229070634.issue26680@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2018-03-12 12:59:00mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, facundobatista, christian.heimes, skrah, serhiy.storchaka, robert_smallshire, Austin Bingham
2018-03-12 12:59:00mark.dickinsonsetmessageid: <1520859540.3.0.467229070634.issue26680@psf.upfronthosting.co.za>
2018-03-12 12:59:00mark.dickinsonlinkissue26680 messages
2018-03-12 12:59:00mark.dickinsoncreate