Posted 24 April 2013 - 04:33 AM
Well, first, why do you need such a function? These kinds of manipulations usually hide a deeper design problem which means your code is fragile. Ignoring that, as for using epsilons, it seems to be a reasonable approach, and provided you don't lose any precision (dot and cross products are only multiplications and additions so it should be fine) then you could use 1e-6 for floats and 1e-13 for doubles (I'm sure you can push it a bit farther and I have no idea what the ideal value is but it's worked pretty well for me so far in most cases). Due to the nature of floating-point arithmetic I don't think there is an ideal epsilon value, actually, it depends on the input values..
The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.
- Pessimal Algorithms and Simplexity Analysis