cgal icon indicating copy to clipboard operation
cgal copied to clipboard

support for 64 bit Integer and 128Bit floating Point

Open schnedann opened this issue 1 year ago • 2 comments

Issue Details

I tried to tinker around with the examples of cgal and when I modified statements like

Source Code

typedef CGAL::Box_intersection_d::Box_d<double,2> Box;

to use long int (int64_t) or long double, the compiler throws errors

But I was able to patch Box_intersection_d/include/CGAL/Box_intersection_d/box_limits.h

as following

diff --git a/Box_intersection_d/include/CGAL/Box_intersection_d/box_limits.h b/Box_intersection_d/include/CGAL/Box_intersection_d/box_limits.h
index 205ebb73e94..3bdaa8c0551 100644
--- a/Box_intersection_d/include/CGAL/Box_intersection_d/box_limits.h
+++ b/Box_intersection_d/include/CGAL/Box_intersection_d/box_limits.h
@@ -38,10 +38,22 @@ template<>
 struct box_limits<unsigned int> {
     static int inf() { return 0; }
     static int sup() { return (std::numeric_limits<unsigned int>::max)(); }
 };
 
+template<>
+struct box_limits<long int> {
+    static long int inf() { return (std::numeric_limits<long int>::min)(); }
+    static long int sup() { return (std::numeric_limits<long int>::max)(); }
+};
+
+template<>
+struct box_limits<unsigned long int> {
+    static long int inf() { return 0; }
+    static long int sup() { return (std::numeric_limits<unsigned long int>::max)(); }
+};
+
 template<>
 struct box_limits<float> {
     static float inf() { return -sup(); }
     static float sup() { return (std::numeric_limits<float>::max)(); }
 };
@@ -50,10 +62,16 @@ template<>
 struct box_limits<double> {
     static double inf() { return -sup(); }
     static double sup() { return (std::numeric_limits<double>::max)(); }
 };
 
+template<>
+struct box_limits<long double> {
+    static long double inf() { return -sup(); }
+    static long double sup() { return (std::numeric_limits<long double>::max)(); }
+};
+
 } // end namespace Box_intersection_d
 
 
 } //namespace CGAL

I suggest to extend cgal to support all types in <cstdint> like intXX_t, uintXX_t plus all floating point types Box_intersection_d__box_limits_h.patch.zip

schnedann avatar Oct 27 '23 21:10 schnedann

It looks like inf() is always equivalent to numeric_limits::lowest() and sup() to numeric_limits::max()? (If it is important to get an error for something that is not a standard integer or float, that can still be arranged)

mglisse avatar Nov 01 '23 14:11 mglisse

yes, my fix is just copy/paste to add more specializations...

guess one can rewrite it more clever and more general without specializations but using static_assert to test for integer an float types...

schnedann avatar Nov 01 '23 16:11 schnedann