diff options
Diffstat (limited to 'src/Bottleneck_distance/include/gudhi/Bottleneck.h')
-rw-r--r-- | src/Bottleneck_distance/include/gudhi/Bottleneck.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Bottleneck_distance/include/gudhi/Bottleneck.h b/src/Bottleneck_distance/include/gudhi/Bottleneck.h index 41f8b16a..7a553006 100644 --- a/src/Bottleneck_distance/include/gudhi/Bottleneck.h +++ b/src/Bottleneck_distance/include/gudhi/Bottleneck.h @@ -30,12 +30,13 @@ #include <limits> // for numeric_limits #include <cmath> +#include <cfloat> // FLT_EVAL_METHOD namespace Gudhi { namespace persistence_diagram { -double bottleneck_distance_approx(Persistence_graph& g, double e) { +inline double bottleneck_distance_approx(Persistence_graph& g, double e) { double b_lower_bound = 0.; double b_upper_bound = g.diameter_bound(); const double alpha = std::pow(g.size(), 1. / 5.); @@ -43,6 +44,13 @@ double bottleneck_distance_approx(Persistence_graph& g, double e) { Graph_matching biggest_unperfect(g); while (b_upper_bound - b_lower_bound > 2 * e) { double step = b_lower_bound + (b_upper_bound - b_lower_bound) / alpha; +#if !defined FLT_EVAL_METHOD || FLT_EVAL_METHOD < 0 || FLT_EVAL_METHOD > 1 + // On platforms where double computation is done with excess precision, + // we force it to its true precision so the following test is reliable. + volatile double drop_excess_precision = step; + step = drop_excess_precision; + // Alternative: step = CGAL::IA_force_to_double(step); +#endif if (step <= b_lower_bound || step >= b_upper_bound) // Avoid precision problem break; m.set_r(step); @@ -58,7 +66,7 @@ double bottleneck_distance_approx(Persistence_graph& g, double e) { return (b_lower_bound + b_upper_bound) / 2.; } -double bottleneck_distance_exact(Persistence_graph& g) { +inline double bottleneck_distance_exact(Persistence_graph& g) { std::vector<double> sd = g.sorted_distances(); long lower_bound_i = 0; long upper_bound_i = sd.size() - 1; |