Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] point lying over a line problem

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] point lying over a line problem


Chronological Thread 
  • From: Camille Wormser <>
  • To:
  • Subject: Re: [cgal-discuss] point lying over a line problem
  • Date: Wed, 23 Jul 2008 23:55:25 +0200

Well, that is subjective because for me 20 is honestly way beyond, so it doesn't make sense to set the precision of cout to 20 for doubles.

You should try to understand why you were advised to use precision(20). The trailing numbers that you see are not at all garbage. They are the REAL digits of the EXACT binary number which is stored in memory. 

The fact that you do not see exactly 0.034, for example, shows that the number stored in memory is NOT EXACTLY 0.034, but a slightly larger number. This is unrelated to CGAL. It is the standard C behavior.

You can easily check that in detail: the stored (double, used by CGAL) value for 0.034 is
0.000010001011010000111001010110000001000001100010010011100
and the real value is
0.000010001011010000111001010110000001000001100010010011011101000001...

As you can see, 0.034 is rounded in memory to the nearest double precision floating point number (which happens to be larger than 0.034, hence the 0.034000000000000002442 output, with precision(20)).

CGAL can only use the data that you provide, i.e. the data IN MEMORY, not the data in your source file. Using precision(20) makes sense, because it allows you to check that CGAL's answer is indeed the correct one.

As for providing inexact answers in case the data are close to be in a degenerate position, check any course in computational geometry to find examples where such an approach will fail: it will not be a question of having a less precise answer, but a crashed program. Very few algorithms exist for dealing with imprecise data, and they are very tricky to design.

Anyways, do you know by chance in which file I can find the code that computes the oriented side? I'm using Eclipse and you may know that the indexer is broken when you work with large projects.

In kernel_ftC2.h, you will find

template <class FT>
inline
typename Same_uncertainty_nt<Oriented_side, FT>::type
side_of_oriented_lineC2(const FT &a, const FT &b, const FT &c,
                        const FT &x, const FT &y)
{
  return CGAL_NTS sign(a*x+b*y+c);
}




Archive powered by MHonArc 2.6.16.

Top of Page