Search code examples
cgal

Floating-point precision selection in CGAL


I wonder that whether there is a way for me to select floating-point bit-width used in CGAL.

For example, the following code is just a convex hull example directly copied from CGAL manual:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef std::vector<Point_2> Points;
int main()
{
  Points points, result;
  points.push_back(Point_2(0,0));
  points.push_back(Point_2(10,0));
  points.push_back(Point_2(10,10));
  points.push_back(Point_2(6,5));
  points.push_back(Point_2(4,1));
  CGAL::convex_hull_2( points.begin(), points.end(), std::back_inserter(result) );
  std::cout << result.size() << " points on the convex hull" << std::endl;
  return 0;
}

However, I cannot choose that the coordinates of points are stored in 32 or 64 bit floating-point numbers. I also wish to choose that the convex hull is computed under 32 or 64 bit arithmetic. (And, yes, I am willing to take the risk of high round-off error.)

Is there anyway to select floating-point precision either in runtime or compile-time?


Solution

  • You can look at the file Exact_predicates_inexact_constructions_kernel.h and adapt it to create your own exact predicates inexact constructions but storing numbers in float