Opened 10 years ago
Last modified 9 years ago
#7879 new Feature Requests
Optimize equality comparison
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multiprecision |
Version: | Boost 1.53.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
Comparing two numbers for equality should be trivial. However, current implementation uses one or two less-then operators. For rational numbers this is very inefficient because less-then operator is both complex and slow.
Change History (4)
comment:1 by , 10 years ago
Type: | Bugs → Feature Requests |
---|
comment:2 by , 10 years ago
comment:3 by , 10 years ago
You're correct of course, in fact rational_adapter is needlessly slow because of it's dependence on Boost.Rational which often performs a lot of unnecessary copying.
I really need to rewrite rational_adapter not to use Boost.Rational at all.
BTW the front end does have the ability to optimize comparisons when a full compare is expensive, but since we can't access the numerator and denominator of Boost.Rational without copying, it's unlikely to help so much as it should.
comment:4 by , 9 years ago
Wouldn't it be more worth while to merge this effort with improving Boost.Rational ('to kill more flies with a similar amount of effort)?
Also, as I see,
rational<IntType>::operator<
is overcomplicated. It uses some complex algorithm, I think it is to prevent overflow. But with arbitrary-sized integers it can be as simple asa.num*b.den < b.num*a.den
(and also we need to take care about signs). It should be faster than current algorithm that uses divisions.