From 878d90b20ea1b8151ff1b089bf506ef5c0d04d4d Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 25 Jan 2024 17:46:41 +0000 Subject: [PATCH 1/5] Core: Use Expr::is_zero() of AST --- Number_types/include/CGAL/CORE_Expr.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Number_types/include/CGAL/CORE_Expr.h b/Number_types/include/CGAL/CORE_Expr.h index ae0b603b1ed..efeb5ad9363 100644 --- a/Number_types/include/CGAL/CORE_Expr.h +++ b/Number_types/include/CGAL/CORE_Expr.h @@ -115,6 +115,14 @@ template <> class Algebraic_structure_traits< CORE::Expr > }; */ }; + class Is_zero + : public CGAL::cpp98::unary_function< Type, bool > { + public: + bool operator()( const Type& x ) const { + return x.isZero(); + } + }; + }; template <> class Real_embeddable_traits< CORE::Expr > From 13485521941e288a70bf427b2dea9864fb74ef47 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 25 Jan 2024 18:23:49 +0000 Subject: [PATCH 2/5] Add Is_one --- CGAL_Core/examples/Core/CMakeLists.txt | 1 + CGAL_Core/examples/Core/zero-one.cpp | 32 ++++++++++++++++++++++++++ Number_types/include/CGAL/CORE_Expr.h | 16 +++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 CGAL_Core/examples/Core/zero-one.cpp diff --git a/CGAL_Core/examples/Core/CMakeLists.txt b/CGAL_Core/examples/Core/CMakeLists.txt index d4513e22dea..6d9e732db93 100644 --- a/CGAL_Core/examples/Core/CMakeLists.txt +++ b/CGAL_Core/examples/Core/CMakeLists.txt @@ -9,4 +9,5 @@ if(NOT CGAL_Core_FOUND) return() endif() +create_single_source_cgal_program("zero-one.cpp") create_single_source_cgal_program("delaunay.cpp") diff --git a/CGAL_Core/examples/Core/zero-one.cpp b/CGAL_Core/examples/Core/zero-one.cpp new file mode 100644 index 00000000000..cfc5a903c19 --- /dev/null +++ b/CGAL_Core/examples/Core/zero-one.cpp @@ -0,0 +1,32 @@ + +#include + +typedef CORE::Expr Real; + +int main() +{ + Real r(3.14); + + CGAL::is_zero(r); + + CGAL::is_one(r); + + r = CGAL::sqrt(r); + + + CGAL::is_zero(r); + + CGAL::is_one(r); + + r = r * r; + + CGAL::is_zero(r); + + CGAL::is_one(r); + + r = r - r; + + CGAL::is_zero(r); + + return 0; +} diff --git a/Number_types/include/CGAL/CORE_Expr.h b/Number_types/include/CGAL/CORE_Expr.h index efeb5ad9363..3ddb4c7f78f 100644 --- a/Number_types/include/CGAL/CORE_Expr.h +++ b/Number_types/include/CGAL/CORE_Expr.h @@ -123,6 +123,22 @@ template <> class Algebraic_structure_traits< CORE::Expr > } }; + class Is_one + : public CGAL::cpp98::unary_function< Type, bool > { + public: + bool operator()( const Type& x ) const { + double inf, sup; + x.doubleInterval(inf,sup); + if((inf > 1) || (sup < 1)){ + return false; + } + if((inf == 1) && (sup == 1)){ + return true; + } + return x.cmp(Type::getOne()); + } + }; + }; template <> class Real_embeddable_traits< CORE::Expr > From 468b81f9f29c26910b4fa8e7fb7571af4cd7dfb0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 26 Jan 2024 08:47:16 +0100 Subject: [PATCH 3/5] Update Number_types/include/CGAL/CORE_Expr.h Co-authored-by: Marc Glisse --- Number_types/include/CGAL/CORE_Expr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Number_types/include/CGAL/CORE_Expr.h b/Number_types/include/CGAL/CORE_Expr.h index 3ddb4c7f78f..f38681a08e2 100644 --- a/Number_types/include/CGAL/CORE_Expr.h +++ b/Number_types/include/CGAL/CORE_Expr.h @@ -135,7 +135,7 @@ template <> class Algebraic_structure_traits< CORE::Expr > if((inf == 1) && (sup == 1)){ return true; } - return x.cmp(Type::getOne()); + return x.cmp(Type::getOne()) == 0; } }; From 60328a74a7227eb3de179f9089537769ed7fa8eb Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 26 Jan 2024 08:48:28 +0100 Subject: [PATCH 4/5] Update Number_types/include/CGAL/CORE_Expr.h Co-authored-by: Marc Glisse --- Number_types/include/CGAL/CORE_Expr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Number_types/include/CGAL/CORE_Expr.h b/Number_types/include/CGAL/CORE_Expr.h index f38681a08e2..e0f72a22326 100644 --- a/Number_types/include/CGAL/CORE_Expr.h +++ b/Number_types/include/CGAL/CORE_Expr.h @@ -132,7 +132,7 @@ template <> class Algebraic_structure_traits< CORE::Expr > if((inf > 1) || (sup < 1)){ return false; } - if((inf == 1) && (sup == 1)){ + if(inf == sup){ return true; } return x.cmp(Type::getOne()) == 0; From 290f79777ef676fcc7484dadf3a61cc20ba5f9f1 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 22 Feb 2024 08:59:56 +0000 Subject: [PATCH 5/5] Keep only Is_zero --- Number_types/include/CGAL/CORE_Expr.h | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Number_types/include/CGAL/CORE_Expr.h b/Number_types/include/CGAL/CORE_Expr.h index e0f72a22326..efeb5ad9363 100644 --- a/Number_types/include/CGAL/CORE_Expr.h +++ b/Number_types/include/CGAL/CORE_Expr.h @@ -123,22 +123,6 @@ template <> class Algebraic_structure_traits< CORE::Expr > } }; - class Is_one - : public CGAL::cpp98::unary_function< Type, bool > { - public: - bool operator()( const Type& x ) const { - double inf, sup; - x.doubleInterval(inf,sup); - if((inf > 1) || (sup < 1)){ - return false; - } - if(inf == sup){ - return true; - } - return x.cmp(Type::getOne()) == 0; - } - }; - }; template <> class Real_embeddable_traits< CORE::Expr >