Valgrind

Pierre Abbat phma at leaf.dragonflybsd.org
Tue Feb 2 15:26:24 PST 2016


On 02/ 2/16 08:19 PM, Vasily Postnicov wrote:
> Let me correct my answer a bit. You calculate 'which' as a sum of
> floating point comparisons with some "weight" from 1 to 8, but this is
> ok, as a result of comparison is 0 or 1. But, there might be a problem.
> The greatest possible 'which' is the sum of "weights" 1+2+3+4+8+12=30.
> (Assuming all conditionals return 1). Your ctrltab array has only 16
> elements. So if one floating point conditional wrongly returns 1 (due to
> lack of precision) you will get out-of-bounds error. I think this is the
> most probable scenario

Thanks! I put a breakpoint on the "ctrlpt garbage" line and found that 
which was 23. I then corrected the line

crit=1/2.0*(1/dist(xy(*a),xy(*b))+1/dist(xy(*c),xy(*a))+1/dist(xy(*b),xy(*c)));

to

crit=1/(2.0*(1/dist(xy(*a),xy(*b))+1/dist(xy(*c),xy(*a))+1/dist(xy(*b),xy(*c))));

which fixed the problem. The bug showed up on triangles much smaller 
than a meter.

Pierre



More information about the Users mailing list