A class to reliably carry out floating point comparisons, storing marginal cases for future reference. More...
#include <cell.hh>
Public Member Functions | |
suretest () | |
~suretest () | |
void | init (fpoint x, fpoint y, fpoint z, fpoint rsq) |
int | test (int n, fpoint &ans) |
Data Fields | |
fpoint * | p |
A class to reliably carry out floating point comparisons, storing marginal cases for future reference.
Floating point comparisons can be unreliable on some processor architectures, and can produce unpredictable results. On a number of popular Intel processors, floating point numbers are held to higher precision when in registers than when in memory. When a register is swapped from a register to memory, a truncation error, and in some situations this can create circumstances where for two numbers c and d, the program finds c>d first, but later c<d. The programmer has no control over when the swaps between memory and registers occur, and recompiling with slightly different code can give different results. One solution to avoid this is to force the compiler to evaluate everything in memory (e.g. by using the -ffloat-store option in the GNU C++ compiler) but this could be viewed overkill, since it slows the code down, and the extra register precision is useful.
In the plane cutting routine of the voronoicell class, we need to reliably know whether a vertex lies inside, outside, or on the cutting plane, since if it changed during the tracing process there would be confusion. This class makes these tests reliable, by storing the results of marginal cases, where the vertex lies within tolerance2 of the cutting plane. If that vertex is tested again, then code looks up the value of the table in a buffer, rather than doing the floating point comparison again. Only vertices which are close to the plane are stored and tested, so this routine should create minimal computational overhead.
Definition at line 56 of file cell.hh.
suretest::suretest | ( | ) |
suretest::~suretest | ( | ) |
int suretest::test | ( | int | n, | |
fpoint & | ans | |||
) | [inline] |
Checks to see if a given vertex is inside, outside or within the test plane. If the point is far away from the test plane, the routine immediately returns whether it is inside or outside. If the routine is close the the plane and within the specified tolerance, then the special check_marginal() routine is called.
[in] | n | the vertex to test. |
[out] | ans | the result of the scalar product used in evaluating the location of the point. |