suretest Class Reference

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


Detailed Description

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.

Constructor & Destructor Documentation

suretest::suretest (  ) 

Initializes the suretest class and creates a buffer for marginal points.

Definition at line 1832 of file

suretest::~suretest (  ) 

Suretest destructor that deallocates memory for the marginal cases.

Definition at line 1837 of file

Member Function Documentation

void suretest::init ( fpoint  x,
fpoint  y,
fpoint  z,
fpoint  rsq 
) [inline]

Sets up the suretest class with a particular test plane, and removes any special cases from the table.

[in] (x,y,z) the normal vector to the plane.
[in] rsq the distance along this vector of the plane.

Definition at line 1845 of file

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.
-1 if the point is inside the plane, 1 if the point is outside the plane, or 0 if the point is within the plane.

Definition at line 1859 of file

Field Documentation

This is a pointer to the array in the voronoicell class which holds the vertex coordinates.

Definition at line 60 of file cell.hh.

The documentation for this class was generated from the following files:

Generated on Tue Sep 29 11:46:27 2009 for Voro++ by  doxygen 1.6.1