diff --git a/Algebraic_foundations/include/CGAL/number_utils.h b/Algebraic_foundations/include/CGAL/number_utils.h index 03e2e757477..5fc8c6e4570 100644 --- a/Algebraic_foundations/include/CGAL/number_utils.h +++ b/Algebraic_foundations/include/CGAL/number_utils.h @@ -303,19 +303,21 @@ to_interval( const Real_embeddable& x) { } template -NT approximate_sqrt(const NT& nt, CGAL::Null_functor) +typename Coercion_traits::Type +approximate_sqrt(const NT& x, CGAL::Null_functor) { - return NT(sqrt(CGAL::to_double(nt))); + return sqrt(CGAL::to_double(x)); } template -NT approximate_sqrt(const NT& nt, Sqrt sqrt) +typename Sqrt::result_type +approximate_sqrt(const NT& nt, Sqrt sqrt) { return sqrt(nt); } template -NT approximate_sqrt(const NT& nt) +decltype(auto) approximate_sqrt(const NT& nt) { // the initial version of this function was using Algebraic_category // for the dispatch but some ring type (like Gmpz) provides a Sqrt diff --git a/Number_types/include/CGAL/mpq_class.h b/Number_types/include/CGAL/mpq_class.h index 6250ea95e3a..76611b93cf9 100644 --- a/Number_types/include/CGAL/mpq_class.h +++ b/Number_types/include/CGAL/mpq_class.h @@ -40,7 +40,6 @@ namespace CGAL { - // AST for mpq_class template<> class Algebraic_structure_traits< mpq_class > diff --git a/Number_types/test/Number_types/Gmpzf_new.cpp b/Number_types/test/Number_types/Gmpzf_new.cpp index 95ea8c2de4f..f2ae93fe287 100644 --- a/Number_types/test/Number_types/Gmpzf_new.cpp +++ b/Number_types/test/Number_types/Gmpzf_new.cpp @@ -31,7 +31,7 @@ int main() { CGAL::test_algebraic_structure(); CGAL::test_real_embeddable(); - // assert(CGAL::approximate_sqrt(NT(4)) == NT(2)); + assert(CGAL::approximate_sqrt(NT(4)) == NT(2)); } return 0; diff --git a/Number_types/test/Number_types/include/CGAL/_test_utilities.h b/Number_types/test/Number_types/include/CGAL/_test_utilities.h index 49a0d8e5224..a53184e65c5 100644 --- a/Number_types/test/Number_types/include/CGAL/_test_utilities.h +++ b/Number_types/test/Number_types/include/CGAL/_test_utilities.h @@ -366,6 +366,10 @@ test_utilities(const NT& x) if (!test_gcd(x,typename AST::Algebraic_category())) return false; if (!test_sqrt(x,typename AST::Sqrt())) return false; + // approximate_sqrt + std::cout << " approximate_sqrt()" << std::endl; + if(NT(CGAL::approximate_sqrt(one)) != one) return false; + return true; } diff --git a/Number_types/test/Number_types/utilities.cpp b/Number_types/test/Number_types/utilities.cpp index b4e3e22c81f..f8028bf59d6 100644 --- a/Number_types/test/Number_types/utilities.cpp +++ b/Number_types/test/Number_types/utilities.cpp @@ -1,10 +1,5 @@ #include -// TODO: solve conflict of CORE with GMPXX -#ifdef CGAL_USE_CORE -#undef CGAL_USE_GMPXX -#endif - #include #include #include @@ -77,7 +72,7 @@ int main() TESTIT(long double, "long double") // CGAL number types - //TESTIT(CGAL::MP_Float, "MP_Float") + //TESTIT(CGAL::MP_Float, "MP_Float") // CGAL::div(MP_Float, MP_Float) does not implement _integer_ division TESTIT(CGAL::Quotient, "Quotient") TESTIT(QMPF, "Quotient") TESTIT(CGAL::Lazy_exact_nt, "Lazy_exact_nt >") @@ -129,7 +124,7 @@ int main() // TEST Sqrt_extension #ifdef CGAL_USE_GMP typedef CGAL::Sqrt_extension Ext_int; - TESTIT(Ext_int , "CGAL::Sqrt_extension"); + TESTIT(Ext_int , "CGAL::Sqrt_extension"); typedef CGAL::Sqrt_extension Ext_int_int; TESTIT(Ext_int_int , "CGAL::Sqrt_extension"); typedef CGAL::Sqrt_extension Ext_rat_int; diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp index f1758c33948..c8d1040383d 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_distance.cpp @@ -1,11 +1,11 @@ #include #include + #include #include - - #include - +#include +#include #include #include @@ -194,6 +194,14 @@ struct Custom_traits_Hausdorff }; namespace CGAL{ + +CGAL_DEFINE_COERCION_TRAITS_FOR_SELF(Custom_traits_Hausdorff::FT) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(short, Custom_traits_Hausdorff::FT) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(int, Custom_traits_Hausdorff::FT) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(long, Custom_traits_Hausdorff::FT) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(float, Custom_traits_Hausdorff::FT) +CGAL_DEFINE_COERCION_TRAITS_FROM_TO(double, Custom_traits_Hausdorff::FT) + template<>struct Kernel_traits { typedef Custom_traits_Hausdorff Kernel;