Minimal example of indeterminacy of CGAL::to_double ? #6000
-
I have a scenario where I would like the following to hold: Given two I realize that the space of doubles is finite and there are (infinitely) many rationals who share the same closest float, so it's OK if The first candidate for
Is there a minimal example which demonstrates the issue discussed in this note? Does this imply that Would (the much slower) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Here's an attempt at a minimal example, but it'd be great to know if what's going on here is really matching that note. I construct two equivalent numbers with disparate expressions a=1/3 and b=1-2/3. Calling Is my understanding correct? Upon further scrutiny, I'm more confused. #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <cstdio>
int main()
{
CGAL::Epeck::FT a = CGAL::Epeck::FT(1)/ CGAL::Epeck::FT(3);
CGAL::Epeck::FT b = CGAL::Epeck::FT(1) - CGAL::Epeck::FT(2)/ CGAL::Epeck::FT(3);
double c1,d1,c2,d2,c3,d3;
c1 = CGAL::to_double(a);
d1 = CGAL::to_double(b);
printf("a%sb → c%sd\n",a==b?"=":"≠",c1==d1?"=":"≠");
c2 = CGAL::to_double(a.exact());
d2 = CGAL::to_double(b.exact());
printf("a%sb → c%sd\n",a==b?"=":"≠",c2==d2?"=":"≠");
c3 = CGAL::to_double(a);
d3 = CGAL::to_double(b);
printf("a%sb → c%sd\n",a==b?"=":"≠",c3==d3?"=":"≠");
printf("c₁%sc₂\n",c1==c2?"=":"≠");
printf("c₂%sc₃\n",c2==c3?"=":"≠");
printf("c₁%sc₃\n",c1==c3?"=":"≠");
printf("d₁%sd₂\n",d1==d2?"=":"≠");
printf("d₂%sd₃\n",d2==d3?"=":"≠");
printf("d₁%sd₃\n",d1==d3?"=":"≠");
} this will output:
A lingering confusion even if the understand above is correct: why is |
Beta Was this translation helpful? Give feedback.
-
Your function template <typename Lazy_FT>
double cast_to_double(const Lazy_FT& x) {
x.exact();
return CGAL::to_double(x);
} |
Beta Was this translation helpful? Give feedback.
a.exact()
returns the exact type insidea
(of typeCGAL::Epeck::FT::ET
), soc2
is constructed by callingCGAL::to_double(CGAL::Epeck::FT::ET)
, whereasc3
is constructed by callingCGAL::to_double(CGAL::Epeck::FT)
. That explains whyc2
andc3
differ.Your function
cast_to_double
could be implemented that way: