Open qwenger opened 3 months ago
In https://github.com/CGAL/cgal/pull/8179 with @afabri , we modified the behavior of the outstream operator for Core Expr and now you would get consistent results:
direct: 0.99999999999999989 1
double: 0.99999999999999989 1
Note that if you ask for more than 17 for the precision, you'll get the old behavior. Even if the outstream operator prints with more precision, if you want to go back into the world of double you will lose that precision. Maybe that would need internally to refine the interval around the real value but I'm not sure if that's already an option available.
Thanks for the answer. So in the future it will be consistent, albeit exactly in the opposite way as what I would like.
if you want to go back into the world of double you will lose that precision
I'm not sure that I completely get this point. Yes in general doubles have limited precision, that is there are only finitely many values that can be represented exactly. But here the exact value is one of them, so doubles are not an excuse per se. It's the process of evaluating an approximation of the expression that returns the "wrong" double.
So, is there a way to get the "correct" one, even if it means sacrificing some performance?
And more generally, what does it mean to have "17 for the precision", when the 16th digit is incorrect? What are the precision guarantees, or is it really that there are no guarantees at all? If so, what would be the point of offering a conversion to double when the result could be arbitrarily far away from the truth? Or is it at least possible to find guarantees for the specific application at hand (Voronoi vertices positions)?
Issue Details
Consider the program below. I get the following output running it:
The first vertex should be at the exact square center, (1,1).
I understand the limitations of converting to floating point values, but here the correct value does have an exact double representation. I also understand the difficulty of evaluating an expression, but the code for printing the value directly does a fine (or at least, better) job.
So:
to_double
return the double value that is actually closest to the exact value?I've read https://github.com/CGAL/cgal/discussions/6000 but it doesn't seem to apply here, as
CORE::Expr
doesn't have anexact
method.The doc for
to_double
writesWhat would then be the appropriate "specific methods" for
CORE::Expr
?Source Code
Environment