From f882c5d3a63dfc7060d1abf52b9daeba946eebf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 26 Jun 2019 15:09:19 +0200 Subject: [PATCH] Sanitize result of square root --- .../CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h index c6d3f292454..136d4722cae 100644 --- a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h +++ b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Basic_predicates_C2.h @@ -146,8 +146,11 @@ public: static FT to_ft(const Sqrt_3& x) { - FT sqrt_e = compute_sqrt( to_ft(x.e()), FT_Has_sqrt() ); - FT sqrt_f = compute_sqrt( to_ft(x.f()), FT_Has_sqrt() ); + // If the number type does not offer a square root, x.e() and x.f() (which are of type sqrt_1) + // might be negative after (approximately) evaluating them. Taking the max sanitize these values + // to ensure that we do not take the square root of a negative number. + FT sqrt_e = compute_sqrt( (std::max)(FT(0), to_ft(x.e())), FT_Has_sqrt() ); + FT sqrt_f = compute_sqrt( (std::max)(FT(0), to_ft(x.f())), FT_Has_sqrt() ); FT sqrt_ef = sqrt_e * sqrt_f; return to_ft(x.a()) + to_ft(x.b()) * sqrt_e + to_ft(x.c()) * sqrt_f + to_ft(x.d()) * sqrt_ef;