From: Szilard Pall Date: Mon, 21 May 2012 20:33:11 +0000 (+0200) Subject: added explicit sqrtf to the float version of norm X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=d7e5bdf4f8ae68e75b24060ae98288bb33380239;p=alexxy%2Fgromacs.git added explicit sqrtf to the float version of norm Additionally, as inlining is not a concern nowadays, also cleaned up the code by using iprod in norm. Change-Id: Iabc237906380f848e16ed158809bf22b1de9ddd0 --- diff --git a/include/vec.h b/include/vec.h index 139a9c4514..cbf5706744 100644 --- a/include/vec.h +++ b/include/vec.h @@ -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: