Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Number_types/include/CGAL/GMP/Gmpq_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ class Gmpq
double to_double() const noexcept;
Sign sign() const noexcept;

bool is_zero() const
{
const __mpz_struct* zn = mpq_numref(mpq());
return mpn_zero_p(zn->_mp_d, zn->_mp_size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}

const mpq_t & mpq() const noexcept { return Ptr()->mpQ; }
mpq_t & mpq() noexcept { return ptr()->mpQ; }

Expand Down
10 changes: 10 additions & 0 deletions Number_types/include/CGAL/Gmpq.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ template <> class Algebraic_structure_traits< Gmpq >
typedef Tag_true Is_exact;
typedef Tag_false Is_numerical_sensitive;

class Is_zero
: public CGAL::cpp98::unary_function<Type&,
bool > {
public:
bool operator()( const Type& x_) const {
return x_.is_zero();
}
};


class Is_square
: public CGAL::cpp98::binary_function< Type, Type&,
bool > {
Expand Down