increment_ulp.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "increment_ulp.h"
  9. #include <cmath>
  10. #include <limits>
  11. // see "Robust BVH Ray Traversal" by Thiago Ize, section 3:
  12. // for why we need this
  13. template <typename Derived>
  14. IGL_INLINE void igl::increment_ulp(
  15. Eigen::MatrixBase<Derived>& inout,
  16. int it
  17. )
  18. {
  19. typedef typename Derived::Scalar Scalar;
  20. inout = inout.unaryExpr([&it](Scalar v){
  21. for (int k = 0; k < it; ++k) {
  22. v = std::nextafter(v, std::signbit(v) ? -std::numeric_limits<Scalar>::infinity(): std::numeric_limits<Scalar>::infinity());
  23. }
  24. return v;
  25. });
  26. }
  27. #ifdef IGL_STATIC_LIBRARY
  28. // Explicit template instantiation
  29. // generated by autoexplicit.sh
  30. template void igl::increment_ulp<Eigen::Matrix<float, 1, -1, 1, 1, -1>>(Eigen::MatrixBase<Eigen::Matrix<float, 1, -1, 1, 1, -1>>&, int);
  31. // generated by autoexplicit.sh
  32. template void igl::increment_ulp<Eigen::Matrix<float, 1, 3, 1, 1, 3>>(Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3>>&, int);
  33. // generated by autoexplicit.sh
  34. template void igl::increment_ulp<Eigen::Matrix<double, 1, 3, 1, 1, 3>>(Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3>>&, int);
  35. #endif