Message313645
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) |
|
Date |
User |
Action |
Args |
2018-03-12 12:59:00 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, rhettinger, facundobatista, christian.heimes, skrah, serhiy.storchaka, robert_smallshire, Austin Bingham |
2018-03-12 12:59:00 | mark.dickinson | set | messageid: <1520859540.3.0.467229070634.issue26680@psf.upfronthosting.co.za> |
2018-03-12 12:59:00 | mark.dickinson | link | issue26680 messages |
2018-03-12 12:59:00 | mark.dickinson | create | |
|