Fix random typos
[alexxy/gromacs.git] / api / legacy / include / gromacs / math / functions.h
index 271e1cf76035529d27aa07b4fb5313bbb2c62303..91305221678384c686be2f62d94604376adaa0e1 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2018,2019,2020 by the GROMACS development team.
+ * Copyright (c) 2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -441,8 +442,8 @@ constexpr int64_t exactDiv(int64_t a, int64_t b)
 
 /*! \brief Round float to int
  *
- * Rounding behavior is round to nearest. Rounding of halfway cases is implemention defined
- * (either halway to even or halway away from zero).
+ * Rounding behavior is round to nearest. Rounding of halfway cases is implementation defined
+ * (either halfway to even or halfway away from zero).
  */
 /* Implementation details: It is assumed that FE_TONEAREST is default and not changed by anyone.
  * Currently the implementation is using rint(f) because 1) on all known HW that is faster than
@@ -472,6 +473,19 @@ static inline int64_t roundToInt64(double x)
     return static_cast<int>(rint(x));
 }
 
+//! \brief Check whether \p v is an integer power of 2.
+template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
+#if defined(__NVCC__) && !defined(__CUDACC_RELAXED_CONSTEXPR__)
+/* In CUDA 11, a constexpr function cannot be called from a function with incompatible execution
+ * space, unless --expt-relaxed-constexpr flag is set */
+__host__ __device__
+#endif
+        static inline constexpr bool
+        isPowerOfTwo(const T v)
+{
+    return (v > 0) && ((v & (v - 1)) == 0);
+}
+
 } // namespace gmx