Incorrect use of std::sqrt, std::abs.

Issue Details

I have implemented in YADE support for high precision calculations. The problem is that I had to pollute std:: namespace with this:

namespace std {
using ::yade::math::sqrt;
using ::yade::math::abs;
}

See the files in high-precision dir. Best programming practices require that mathematical functions are always called unqualified and let ADL take care of this. See a discussion about this problem in these references (search for word "unqualified"):

  1. boost float128
  2. boost multiprecision
  3. boost real concepts

You can write using std::sqrt or using std::abs inside a function which is going to call this. But write the function call itself unqualified, so that ADL will work.

There are several places in Eigen that use std::pow, for example SelfAdjointEigenSolver.h. The same applies to std::sqrt and std::abs functions. Launching this command in Eigen sources:

grep -E "=.*std::pow|=.*std::sqrt|=.*std::abs" . -r --color

has following hits:

./src/Eigenvalues/SelfAdjointEigenSolver.h:    if(n0>n1) res = c0/std::sqrt(n0);
./src/Eigenvalues/SelfAdjointEigenSolver.h:    else      res = c1/std::sqrt(n1);
./src/SVD/BDCSVD.h:          if(i!=k && std::abs(((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) - 1) > 0.9 )
./src/PardisoSupport/PardisoSupport.h:      bool symmetric = std::abs(m_type) < 10;

I am not sure if that covers all incorrect uses.

Environment

  • Operating system: linux, see gitlab-CI pipeline.
  • Compiler: g++, clang
  • Release or debug mode: both
  • Specific flags used (if any): -Werror -Wformat -Wformat-security -Wformat-nonliteral -Wall -Wextra -Wnarrowing -Wreturn-type -Wuninitialized -Wfloat-conversion -Wcast-align -Wdisabled-optimization -Wtrampolines -Wpointer-arith -Wswitch-bool -Wwrite-strings -Wnon-virtual-dtor -Wreturn-local-addr -Wno-error=cpp
library cmake C++
boost 106700 1.67.0
cgal 4.13
clp 1.16.11 1.16.11
cmake 3.13.4
coinutils 2.10.14 2.10.14
compiler /usr/bin/g++ 8.3.0 gcc 8.3.0
eigen 3.3.7 3.3.7
freeglut 2.8.1
gl 20180725
ipython 5.8.0
metis 5.1.0
mpi 3.1 ompi:3.1.3
mpi4py 2.0.0
openblas OpenBLAS 0.3.5
python 3.7.3 3.7.3
qglviewer 2.6.3
qt 5.11.3
sphinx 1.8.4-final-0
sqlite 3.27.2
suitesparse 5.4.0 5.4.0
vtk 6.3.0 6.3.0

Linux version: Devuan GNU/Linux 3 (beowulf)

Edited by Janek Kozicki