]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::abs instead of abs. 5772/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 20 Jan 2018 21:52:42 +0000 (16:52 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 20 Jan 2018 22:34:01 +0000 (17:34 -0500)
On some compilers (notably GCC 4.8.4, in some configurations) 'abs' refers to
'int abs(int)', and gives the wrong answer for floating point arguments.

tests/base/function_parser_03.cc
tests/base/function_parser_04.cc
tests/bits/find_cell_12.cc
tests/codim_one/integrate_log_2.cc
tests/multigrid/transfer_04.cc

index dfa238731d1f80b5a59b6fa035679254ff71f44d..2d642c4f9eea98284b35f379c10e2177ca9617e6 100644 (file)
@@ -39,17 +39,13 @@ int main ()
   fp.initialize("s,t", "s*t+1", constants);
 
   double value = fp.value(Point<2>(2.0,2.5));
-  Assert(abs(1.0+2.0*2.5 - value) < 1e-10, ExcMessage("wrong value"));
+  Assert(std::abs(1.0+2.0*2.5 - value) < 1e-10, ExcMessage("wrong value"));
 
   std::vector<std::string> expressions;
   expressions.push_back("sin(2*mypi*x)+y");
   constants["mypi"] = numbers::PI;
   fp.initialize("x,y", expressions, constants);
   double value1 = fp.value(Point<2>(1.0,2.5), 0);
-  Assert(abs(2.5 - value1) < 1e-10, ExcMessage("wrong value"));
+  Assert(std::abs(2.5 - value1) < 1e-10, ExcMessage("wrong value"));
 
 }
-
-
-
-
index 1e2aa53716b580f9e89a907d40c7c92907ec08f3..82b4badb37ffb6b47ea677d79703c43a13a5e580 100644 (file)
@@ -48,10 +48,10 @@ void assemble(const std::vector<int>::iterator &it,
 {
   double s = *it;
   double value = fp.value(Point<2>(s, 2.5));
-  Assert(abs(1.0+s*2.5 - value) < 1e-10, ExcMessage("wrong value"));
+  Assert(std::abs(1.0+s*2.5 - value) < 1e-10, ExcMessage("wrong value"));
   std::cout << data.value  << std::endl;
 
-  data.value = (abs(1.0+s*2.5 - value) < 1e-10)?1:0;
+  data.value = (std::abs(1.0+s*2.5 - value) < 1e-10)?1:0;
 }
 
 void copy(int &value, const copy_data &data)
@@ -90,7 +90,3 @@ int main ()
 
   test2();
 }
-
-
-
-
index 61f793947cc4a51937adb734350e0fc88c6ee1c8..5d6a84be5e2fe324783dafb249d1d2dbaf027727 100644 (file)
@@ -66,7 +66,7 @@ void test()
   for (; cell!=endc; ++cell)
     {
       Point<2> cell_center = cell->center();
-      if (abs(cell_center(0) - 1500) < 550)
+      if (std::abs(cell_center(0) - 1500) < 550)
         {
           cell->set_refine_flag ();
         }
index 2da52d72c93e336e6f930282bdc1616abb9616d9..2e750c9e6681016628855294d4998eb0302eea8b 100644 (file)
@@ -95,7 +95,7 @@ int main()
                     {
                       double qpow = pow(quad.point(q)[0], (double) power);
                       approx_integral += qpow  * quad.weight(q);
-                      double factor = log(abs( (factored_quad.point(q)-origins[nos])[0] )/alphas[nas] );
+                      double factor = log(std::abs( (factored_quad.point(q)-origins[nos])[0] )/alphas[nas] );
                       // This code cannot work if factor is equal to
                       // zero. In this case, just pass the other
                       // quadrature formula, which should be valid anyway.
@@ -112,9 +112,9 @@ int main()
 
                   deallog << "   Error(n=" << quad.size()
                           << ") = " << (approx_integral - exact_integral);
-                  if ( abs(approx_integral - approx_integral_factored) > eps )
+                  if ( std::abs(approx_integral - approx_integral_factored) > eps )
                     deallog << ", difference between factored and unfactored: "
-                            << abs(approx_integral - approx_integral_factored);
+                            << std::abs(approx_integral - approx_integral_factored);
                   deallog << endl;
                 }
             }
index fb332cc5ac69ef7cf25b1c3b3d5f0a14e5e473db..a4cf47ac65b1ea854330d011ab5441ea1811bf25 100644 (file)
@@ -153,7 +153,7 @@ void check_fe(FiniteElement<dim> &fe)
     for (unsigned int i=0; i<dofh.locally_owned_dofs().n_elements(); ++i)
       {
         unsigned int index = dofh.locally_owned_dofs().nth_index_in_set(i);
-        if (abs(v[index] - 1.0)>1e-5)
+        if (std::abs(v[index] - 1.0)>1e-5)
           deallog << "ERROR: index=" << index << " is equal to " << v[index] << std::endl;
       }
   }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.