Add radius(Interval_nt).

Replace compare_relative_precision() by has_smaller_relative_precision()
fixing the case of [-Inf,+Inf].
This commit is contained in:
Sylvain Pion 2007-08-22 15:41:11 +00:00
parent dcd2ad00ad
commit a0f9754bbe
2 changed files with 17 additions and 6 deletions

View File

@ -433,10 +433,21 @@ width (const Interval_nt<Protected> & d)
// Non-documented
template <bool Protected>
inline
Comparison_result
compare_relative_precision(const Interval_nt<Protected> & d, double prec)
double
radius (const Interval_nt<Protected> & d)
{
return CGAL::compare(width(d), prec * magnitude(d));
return width(d)/2; // This could be improved to avoid overflow.
}
// Non-documented
// This is the relative precision of to_double() (the center of the interval),
// hence we use radius() instead of width().
template <bool Protected>
inline
bool
has_smaller_relative_precision(const Interval_nt<Protected> & d, double prec)
{
return magnitude(d) == 0 || radius(d) < prec * magnitude(d);
}
// Non-documented
@ -446,7 +457,7 @@ relative_precision(const Interval_nt<Protected> & d)
{
if (magnitude(d) == 0.0)
return 0.0;
return width(d) / magnitude(d);
return radius(d) / magnitude(d);
}

View File

@ -1078,8 +1078,8 @@ template < typename ET > class Real_embeddable_traits< Lazy_exact_nt<ET> >
return r;
// If it's precise enough, then OK.
if (compare_relative_precision(app,
Lazy_exact_nt<ET>::get_relative_precision_of_to_double()) <= 0)
if (has_smaller_relative_precision(app,
Lazy_exact_nt<ET>::get_relative_precision_of_to_double()))
return CGAL_NTS to_double(app);
CGAL_PROFILER(std::string("failures of : ") + std::string(CGAL_PRETTY_FUNCTION));