Skip to content
Snippets Groups Projects
Commit e4ae3cee authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Avoid floating point exception in Orthonormalize

parent f74a2239
Branches
Tags
2 merge requests!2615Draft: DONTMERGE ME: TEST FOR 1.7.0-rc1 is our 9th official release of VTK-m.,!2527Turn on floating point exception trapping for GCC in tests
......@@ -255,6 +255,7 @@ VTKM_EXEC_CONT int Orthonormalize(const vtkm::Vec<vtkm::Vec<T, N>, N>& inputs,
vtkm::Vec<vtkm::Vec<T, N>, N>& outputs,
T tol = static_cast<T>(1e-6))
{
T tolsqr = tol * tol;
int j = 0; // j is the number of non-zero-length, non-collinear inputs encountered.
vtkm::Vec<vtkm::Vec<T, N>, N> u;
for (int i = 0; i < N; ++i)
......@@ -264,13 +265,13 @@ VTKM_EXEC_CONT int Orthonormalize(const vtkm::Vec<vtkm::Vec<T, N>, N>& inputs,
{
u[j] -= vtkm::Project(inputs[i], u[k]);
}
T rmag = vtkm::RMagnitude(u[j]);
if (rmag * tol > 1.0)
T magsqr = vtkm::MagnitudeSquared(u[j]);
if (magsqr <= tolsqr)
{
// skip this vector, it is zero-length or collinear with others.
continue;
}
outputs[j] = rmag * u[j];
outputs[j] = vtkm::RSqrt(magsqr) * u[j];
++j;
}
for (int i = j; i < N; ++i)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment