Skip to content

Commit

Permalink
Merge pull request #6035 from afabri/CORE-boost_mp_number-GF
Browse files Browse the repository at this point in the history
CORE: Use boost::multiprecision::number API
  • Loading branch information
lrineau committed Mar 26, 2024
2 parents a5f7ffb + a42ffde commit 54c5d19
Show file tree
Hide file tree
Showing 125 changed files with 1,596 additions and 3,561 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Advancing_front_surface_reconstruction
Algebraic_foundations
Arithmetic_kernel
BGL
CGAL_Core
Cartesian_kernel
Circulator
Distance_2
Expand Down
6 changes: 3 additions & 3 deletions Algebraic_foundations/include/CGAL/Rational_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ struct Rational_traits_base<Rational, true>
{
private:
typedef Fraction_traits<Rational> FT;
typedef typename FT::Decompose Decomose;
typedef typename FT::Decompose Decompose;
typedef typename FT::Compose Compose;

public:
typedef typename FT::Numerator_type RT;

RT numerator (const Rational& r) const {
RT num,den;
Decomose()(r,num,den);
Decompose()(r,num,den);
return num;
}

RT denominator (const Rational& r) const {
RT num,den;
Decomose()(r,num,den);
Decompose()(r,num,den);
return den;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Convex_combinator_approx_Integer_log {
Integer alpha_num = Integer(1), int log_denom = 1
) : alpha_num_(alpha_num),
beta_num_((Integer(1) << log_denom) - alpha_num),
half_((log_denom > 0) ? (Integer(1) << log_denom-1) : 0),
half_((log_denom > 0) ? Integer(Integer(1) << log_denom-1) : 0),
log_denom_(log_denom)
{
CGAL_precondition(log_denom_ >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ polynomial_power_to_bernstein_approx(
std::vector<Integer> f(n+1);
polynomial_affine_transform_approx_log_denom(
first, beyond, f.begin(),
upper_num - lower_num, lower_num, log_denom,
Integer(upper_num - lower_num), lower_num, log_denom,
p+q,
approx, log, logl
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,10 @@

#include <vector>

#if CGAL_USE_CORE
namespace CORE { class BigInt; }
#endif

namespace CGAL {

namespace internal {

#if CGAL_USE_CORE
// bugfix for CORE by Michael Kerber
// why is there a specialized function for CORE?
inline CORE::BigInt shift_integer_by(CORE::BigInt x, long shift){
if( shift > 0 ){
while(shift>63) {
x = (x >> 63);
shift-=63;
}
x = (x >> shift);
}else{
// add 0 bits
x = (x << -shift);
}
return x;
}
#endif

template <class Shiftable>
Shiftable shift_integer_by(Shiftable x, long shift){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class Real_embeddable_extension< CORE::BigFloat > {
long operator()( CORE::BigFloat x ) const {
CGAL_precondition(!CGAL::zero_in(x));
x = CGAL::abs(x);
return CORE::floorLg(x.m()-x.err())+x.exp()*CORE::CHUNK_BIT;
return CORE::floorLg(CORE::BigInt(x.m()-x.err()))+x.exp()*CORE::CHUNK_BIT;
}
};

Expand All @@ -337,7 +337,7 @@ class Real_embeddable_extension< CORE::BigFloat > {
// (already commented out in EXACUS)...
// NiX_precond(!(NiX::in_zero(x) && NiX::singleton(x)));
x = CGAL::abs(x);
return CORE::ceilLg(x.m()+x.err())+x.exp()*CORE::CHUNK_BIT;
return CORE::ceilLg(CORE::BigInt(x.m()+x.err()))+x.exp()*CORE::CHUNK_BIT;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ simple_bound_between(const Algebraic_real& a,
final_mantissa = final_mantissa << 1;
final_mantissa++;
y_log--;
x_m = x_m==0 ? 0 : x_m & ((Integer(1) << x_log) - 1); //x_m - CGAL::ipower(Integer(2),x_log);
x_m = x_m==0 ? 0 : Integer(x_m & ((Integer(1) << x_log) - 1)); //x_m - CGAL::ipower(Integer(2),x_log);
x_log = x_m==0 ? -1 : CGAL::internal::floor_log2_abs(x_m);
}
final_mantissa = final_mantissa << 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Algebraic_foundations
Algebraic_kernel_for_circles
Arithmetic_kernel
CGAL_Core
Filtered_kernel
Installation
Interval_support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Algebraic_foundations
Algebraic_kernel_for_spheres
Arithmetic_kernel
CGAL_Core
Filtered_kernel
Installation
Interval_support
Expand Down
1 change: 1 addition & 0 deletions Alpha_shapes_2/package_info/Alpha_shapes_2/dependencies
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Algebraic_foundations
Alpha_shapes_2
Arithmetic_kernel
CGAL_Core
Cartesian_kernel
Hash_map
Homogeneous_kernel
Expand Down
1 change: 1 addition & 0 deletions Alpha_shapes_3/package_info/Alpha_shapes_3/dependencies
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Algebraic_foundations
Alpha_shapes_3
Arithmetic_kernel
CGAL_Core
Cartesian_kernel
Circulator
Filtered_kernel
Expand Down
1 change: 1 addition & 0 deletions Alpha_wrap_3/package_info/Alpha_wrap_3/dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Alpha_wrap_3
Arithmetic_kernel
BGL
Box_intersection_d
CGAL_Core
Cartesian_kernel
Circulator
Distance_2
Expand Down
15 changes: 14 additions & 1 deletion Arithmetic_kernel/include/CGAL/BOOST_MP_arithmetic_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,40 @@

#ifdef CGAL_USE_BOOST_MP

#ifdef CGAL_USE_CORE
#include <CGAL/CORE_arithmetic_kernel.h>
#endif

//Currently already included in boost_mp.h
//#include <boost/multiprecision/cpp_int.hpp>
//#ifdef CGAL_USE_GMP
//#include <boost/multiprecision/gmp.hpp>
//#endif

// FIXME: the could be several kernels based on Boost.Multiprecision.

namespace CGAL {
/** \ingroup CGAL_Arithmetic_kernel
* \brief The Boost.Multiprecision set of exact number types
*/

#if !defined(CGAL_USE_CORE) || defined(CGAL_CORE_USE_GMP_BACKEND)
struct BOOST_cpp_arithmetic_kernel : internal::Arithmetic_kernel_base {
typedef boost::multiprecision::cpp_int Integer;
typedef boost::multiprecision::cpp_rational Rational;
};
#else
typedef CORE_arithmetic_kernel BOOST_cpp_arithmetic_kernel;
#endif

#ifdef CGAL_USE_GMP
#if !defined(CGAL_USE_CORE) || !defined(CGAL_CORE_USE_GMP_BACKEND)
struct BOOST_gmp_arithmetic_kernel : internal::Arithmetic_kernel_base {
typedef boost::multiprecision::mpz_int Integer;
typedef boost::multiprecision::mpq_rational Rational;
};
#else
typedef CORE_arithmetic_kernel BOOST_gmp_arithmetic_kernel;
#endif
#endif

template <class T1, class T2, class T3, class T4, class T5>
Expand Down
10 changes: 2 additions & 8 deletions Arithmetic_kernel/include/CGAL/CORE_arithmetic_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ class CORE_arithmetic_kernel : public internal::Arithmetic_kernel_base {
};


template <>
struct Get_arithmetic_kernel<CORE::BigInt>{
typedef CORE_arithmetic_kernel Arithmetic_kernel;
};
template <>
struct Get_arithmetic_kernel<CORE::BigRat>{
typedef CORE_arithmetic_kernel Arithmetic_kernel;
};
template <>
struct Get_arithmetic_kernel<CORE::Expr>{
typedef CORE_arithmetic_kernel Arithmetic_kernel;
Expand All @@ -74,6 +66,8 @@ struct Get_arithmetic_kernel<CORE::BigFloat>{

} //namespace CGAL

#include <CGAL/BOOST_MP_arithmetic_kernel.h>

#endif // CGAL_USE_CORE

#endif // CGAL_CORE_ARITHMETIC_KERNEL_H
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ operator()(const Point_2& p, const X_monotone_curve_2& curve) const {
auto points = painterOstream.getPointsList(curve);

QPoint p_viewport =
view->mapFromScene(QPointF{p.x().doubleValue(), p.y().doubleValue()});
view->mapFromScene(QPointF{CGAL::to_double(p.x()), CGAL::to_double(p.y())});

double min_dist = (std::numeric_limits<double>::max)();
for (auto& vec : points) {
Expand Down
39 changes: 20 additions & 19 deletions Arrangement_on_surface_2/include/CGAL/Arr_conic_traits_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3316,9 +3316,9 @@ class Arr_conic_traits_2 {
// sqrt((r - s)^2 + t^2)
//
const int or_fact = (cv.orientation() == CLOCKWISE) ? -1 : 1;
const Algebraic r = m_nt_traits->convert(or_fact * cv.r());
const Algebraic s = m_nt_traits->convert(or_fact * cv.s());
const Algebraic t = m_nt_traits->convert(or_fact * cv.t());
const Algebraic r = m_nt_traits->convert(Integer(or_fact * cv.r()));
const Algebraic s = m_nt_traits->convert(Integer(or_fact * cv.s()));
const Algebraic t = m_nt_traits->convert(Integer(or_fact * cv.t()));
const Algebraic cos_2phi = (r - s) / m_nt_traits->sqrt((r-s)*(r-s) + t*t);
const Algebraic zero = 0;
const Algebraic one = 1;
Expand Down Expand Up @@ -3363,8 +3363,8 @@ class Arr_conic_traits_2 {
// 4*r*s - t^2 4*r*s - t^2
//
// The denominator (4*r*s - t^2) must be negative for hyperbolas.
const Algebraic u = m_nt_traits->convert(or_fact * cv.u());
const Algebraic v = m_nt_traits->convert(or_fact * cv.v());
const Algebraic u = m_nt_traits->convert(Integer(or_fact * cv.u()));
const Algebraic v = m_nt_traits->convert(Integer(or_fact * cv.v()));
const Algebraic det = 4*r*s - t*t;
Algebraic x0, y0;

Expand Down Expand Up @@ -3803,9 +3803,9 @@ class Arr_conic_traits_2 {
auto u = cv.u();
auto v = cv.v();
auto w = cv.w();
Algebraic* xs_end = m_nt_traits->solve_quadratic_equation(t*t - four*r*s,
two*t*v - four*s*u,
v*v - four*s*w,
Algebraic* xs_end = m_nt_traits->solve_quadratic_equation(Integer(t*t - four*r*s),
Integer(two*t*v - four*s*u),
Integer(v*v - four*s*w),
xs);
auto n_xs = static_cast<int>(xs_end - xs);

Expand All @@ -3816,15 +3816,15 @@ class Arr_conic_traits_2 {

if (CGAL::sign(cv.t()) == ZERO) {
// The two vertical tangency points have the same y coordinate:
ys[0] = m_nt_traits->convert(-v) / m_nt_traits->convert(two*s);
ys[0] = m_nt_traits->convert(Integer(- v)) / m_nt_traits->convert(Integer(two * s));
n_ys = 1;
}
else {
ys_end = m_nt_traits->solve_quadratic_equation(four*r*s*s - s*t*t,
four*r*s*v - two*s*t*u,
r*v*v - t*u*v +
t*t*w,
ys_end = m_nt_traits->solve_quadratic_equation(Integer(four*r*s*s - s*t*t),
Integer(four*r*s*v - two*s*t*u),
Integer((r*v*v - t*u*v) + (t*t*w)),
ys);

n_ys = static_cast<int>(ys_end - ys);
}

Expand All @@ -3837,7 +3837,7 @@ class Arr_conic_traits_2 {
}
else {
for (int j = 0; j < n_ys; ++j) {
if (CGAL::compare(m_nt_traits->convert(two*s) * ys[j],
if (CGAL::compare(m_nt_traits->convert(Integer(two*s)) * ys[j],
-(m_nt_traits->convert(t) * xs[i] +
m_nt_traits->convert(v))) == EQUAL)
{
Expand Down Expand Up @@ -3904,18 +3904,19 @@ class Arr_conic_traits_2 {
auto u = cv.u();
auto v = cv.v();
auto w = cv.w();
Algebraic* ys_end = m_nt_traits->solve_quadratic_equation(t*t - four*r*s,
two*t*u - four*r*v,
u*u - four*r*w,
ys);
Algebraic* ys_end = m_nt_traits->template
solve_quadratic_equation<Integer>(t*t - four*r*s,
two*t*u - four*r*v,
u*u - four*r*w,
ys);
auto n = static_cast<int>(ys_end - ys);

// Compute the x coordinates and construct the horizontal tangency points.
for (int i = 0; i < n; ++i) {
// Having computed y, x is the single solution to the quadratic equation
// above, and since its discriminant is 0, x is simply given by:
Algebraic x = -(m_nt_traits->convert(t)*ys[i] + m_nt_traits->convert(u)) /
m_nt_traits->convert(two*r);
m_nt_traits->convert(Integer(two*r));
ps[i] = Point_2(x, ys[i]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,8 @@ class _X_monotone_circle_segment_2 {
{
// Actually compare the slopes.
const bool swap_res = (sign_denom1 != sign_denom2);
const CoordNT A = (cv.y0() - y0())*p.x() + (y0()*cv.x0() - cv.y0()*x0());
const CoordNT B = (cv.x0() - x0())*p.y();
const CoordNT A = NT(cv.y0() - y0())*p.x() + (y0()*cv.x0() - cv.y0()*x0());
const CoordNT B = NT(cv.x0() - x0())*p.y();

slope_res = CGAL::compare (A, B);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ class Conic_arc_2 {
//
Nt_traits nt_traits;
const int or_fact = (m_orient == CLOCKWISE) ? -1 : 1;
const Algebraic r = nt_traits.convert(or_fact * m_r);
const Algebraic s = nt_traits.convert(or_fact * m_s);
const Algebraic t = nt_traits.convert(or_fact * m_t);
const Algebraic r = nt_traits.convert(Integer(or_fact * m_r));
const Algebraic s = nt_traits.convert(Integer(or_fact * m_s));
const Algebraic t = nt_traits.convert(Integer(or_fact * m_t));
const Algebraic cos_2phi = (r - s) / nt_traits.sqrt((r-s)*(r-s) + t*t);
const Algebraic zero = 0;
const Algebraic one = 1;
Expand Down Expand Up @@ -1158,8 +1158,8 @@ class Conic_arc_2 {
// 4*r*s - t^2 4*r*s - t^2
//
// The denominator (4*r*s - t^2) must be negative for hyperbolas.
const Algebraic u = nt_traits.convert(or_fact * m_u);
const Algebraic v = nt_traits.convert(or_fact * m_v);
const Algebraic u = nt_traits.convert(Integer(or_fact * m_u));
const Algebraic v = nt_traits.convert(Integer(or_fact * m_v));
const Algebraic det = 4*r*s - t*t;
Algebraic x0, y0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ int compute_resultant_roots(const Nt_traits& nt_traits,
}

// Act according to the degree of the first conic curve.
const typename Nt_traits::Integer two = 2;
typename Nt_traits::Integer c[5];
typedef typename Nt_traits::Integer Integer;
const Integer two = 2;
Integer c[5];
unsigned int degree = 4;
typename Nt_traits::Algebraic* xs_end;

if (deg1 == 1) {
// The first curve has no quadratic coefficients, and represents a line.
if (CGAL::sign (v1) == ZERO) {
// The first line is u1*x + w1 = 0, therefore:
xs[0] = nt_traits.convert(-w1) / nt_traits.convert(u1);
xs[0] = nt_traits.convert(Integer(- w1)) / nt_traits.convert(u1);
return 1;
}

Expand All @@ -87,7 +88,7 @@ int compute_resultant_roots(const Nt_traits& nt_traits,
// Return if the two lines are parallel
if (CGAL::sign (c[1]) == ZERO) return 0;

xs[0] = nt_traits.convert(-c[0]) / nt_traits.convert(c[1]);
xs[0] = nt_traits.convert(Integer(- c[0])) / nt_traits.convert(c[1]);
return 1;
}

Expand Down
Loading

0 comments on commit 54c5d19

Please sign in to comment.