added explicit sqrtf to the float version of norm
authorSzilard Pall <pszilard@cbr.su.se>
Mon, 21 May 2012 20:33:11 +0000 (22:33 +0200)
committerSzilard Pall <pszilard@cbr.su.se>
Tue, 22 May 2012 12:50:46 +0000 (14:50 +0200)
Additionally, as inlining is not a concern nowadays, also cleaned up the
code by using iprod in norm.

Change-Id: Iabc237906380f848e16ed158809bf22b1de9ddd0

include/vec.h

index 139a9c4514f339210ce8be0b2edd756f960f0284..cbf570674450b739b05ab614f31ff0365c6306f6 100644 (file)
@@ -505,14 +505,36 @@ static gmx_inline double dnorm2(const dvec a)
   return a[XX]*a[XX]+a[YY]*a[YY]+a[ZZ]*a[ZZ];
 }
 
+/* WARNING:
+ * As dnorm() uses sqrt() (which is slow) _only_ use it if you are sure you
+ * don't need 1/dnorm(), otherwise use dnorm2()*dinvnorm(). */
+static gmx_inline double dnorm(const dvec a)
+{
+  return sqrt(diprod(a, a));
+}
+
+/* WARNING:
+ * As norm() uses sqrtf() (which is slow) _only_ use it if you are sure you
+ * don't need 1/norm(), otherwise use norm2()*invnorm(). */
 static gmx_inline real norm(const rvec a)
 {
-  return (real)sqrt(a[XX]*a[XX]+a[YY]*a[YY]+a[ZZ]*a[ZZ]);
+  /* This is ugly, but we deliberately do not define gmx_sqrt() and handle the
+   * float/double case here instead to avoid gmx_sqrt() being accidentally used. */
+#ifdef GMX_DOUBLE
+  return dnorm(a);
+#else
+  return sqrtf(iprod(a, a));
+#endif
 }
 
-static gmx_inline double dnorm(const dvec a)
+static gmx_inline real invnorm(const rvec a)
+{
+    return gmx_invsqrt(norm2(a));
+}
+
+static gmx_inline real dinvnorm(const dvec a)
 {
-  return sqrt(a[XX]*a[XX]+a[YY]*a[YY]+a[ZZ]*a[ZZ]);
+    return gmx_invsqrt(dnorm2(a));
 }
 
 /* WARNING: