Peter Moulder wrote:
On Tue, Sep 01, 2009 at 08:39:35AM +0200, Tavmjong Bah wrote:
Fundamentally, I think having one value of EPSILON used everywhere in lib2geom is wrong as the way it is used is different in different functions.
Agreed. Presumably it arises because it's difficult to come up with the right number to use :) .
Might I suggest to do it in a fundamentally different way in this particular case (matrix inverse). There are a number of different options that come to mind that would sound a lot more reasonable than any arbitrary constant:
- Use range arithmetic. If you using different rounding modes for the determinant can get you numbers in a range that straddles zero I'd say it's fair to say the matrix is essentially singular. - If changing rounding modes is too problematic, we could always do a poor man's version of range arithmetic using nextafter/nexttoward. - We compute 1.0/det. If det is so small that this (or the value in the resulting matrix with the largest magnitude) is inf(inite) there wouldn't be much sense in computing the inverse, as we can't represent it.