Number_types: Add Is_zero functor for Gmpq#5584
Conversation
|
@mglisse Do I also have to check the denominator? |
| bool is_zero() const | ||
| { | ||
| const __mpz_struct* zn = mpq_numref(mpq()); | ||
| return mpn_zero_p(zn->_mp_d, zn->_mp_size); |
There was a problem hiding this comment.
Why not use the same code as mpq_class, i.e. mpq_sgn(mpq())==0, or mpz_size(mpq_numref(mpq()))==0? Or if you want to use internals, you only need to check if zn->_mp_size is 0.
Yes! With the changes I suggested, all it does is test if one int is 0, which is definitely faster than anything else.
That would mean that the compiler sucks, because all it does it replace
We should to it as well, using
No. Side note: for |
|
In fact with #5333 this becomes somehow irrelevant, or do I miss something? |
|
@mglisse do I have to add |
I see in number_utils.h so you probably only need one of them (Algebraic_structure_traits being safer), although it doesn't hurt if you put it in both. |
It is still nice to have, for fairer comparisons, or if boost_mp is disabled, or if people use Gmpq directly. I don't think it has been settled yet whether we should use Gmpq or mpq_class/mpq_rational by default for the next release. |
|
As you mention |
I think it already has them? |
|
just found them. |
One type that is missing Is_positive and Is_negative is Mpzf (they can probably be just |
|
Successfully tested in https://cgal.geometryfactory.com/CGAL/testsuite/results-5.3-Ic-158.shtml |
Summary of Changes
Is this faster than a comparison with zero? And in case we change code where we currently compare with zero, we have to find out if it becomes slower when we apply
is_zero()to a double. And what about> 0?Release Management