]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::hypot() instead of std::sqrt(sum of squares). 16441/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 10 Jan 2024 22:49:44 +0000 (15:49 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 10 Jan 2024 22:49:44 +0000 (15:49 -0700)
source/base/data_out_base.cc
source/grid/grid_out.cc

index f64f3a23c0f29a44d5d603959e5785bf274e8098..a4e1b0d6611182da2b5b5d6b3397e1cf44cd02d3 100644 (file)
@@ -4166,10 +4166,9 @@ namespace DataOutBase
                           h1(0) * h2(1) - h1(1) * h2(0);
 
                         // normalize Vector
-                        double norm = std::sqrt(
-                          Utilities::fixed_power<2>(nrml[i * d1 + j * d2](0)) +
-                          Utilities::fixed_power<2>(nrml[i * d1 + j * d2](1)) +
-                          Utilities::fixed_power<2>(nrml[i * d1 + j * d2](2)));
+                        double norm = std::hypot(nrml[i * d1 + j * d2](0),
+                                                 nrml[i * d1 + j * d2](1),
+                                                 nrml[i * d1 + j * d2](2));
 
                         if (nrml[i * d1 + j * d2](1) < 0)
                           norm *= -1.;
index 519f178682f428b44b6ccba0db9a64e6920a31c0..ff628d015b2dd4b5c4825ff597488f70f856cc47 100644 (file)
@@ -2454,10 +2454,10 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
                              std::max(x_dimension, y_dimension);
                 }
 
-              const double distance_to_camera = std::sqrt(
-                Utilities::fixed_power<2>(point[0] - camera_position[0]) +
-                Utilities::fixed_power<2>(point[1] - camera_position[1]) +
-                Utilities::fixed_power<2>(point[2] - camera_position[2]));
+              const double distance_to_camera =
+                std::hypot(point[0] - camera_position[0],
+                           point[1] - camera_position[1],
+                           point[2] - camera_position[2]);
               const double distance_factor =
                 distance_to_camera / (2. * std::max(x_dimension, y_dimension));
 
@@ -2626,12 +2626,9 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
                       if (svg_flags.label_boundary_id)
                         {
                           const double distance_to_camera =
-                            std::sqrt(Utilities::fixed_power<2>(
-                                        point[0] - camera_position[0]) +
-                                      Utilities::fixed_power<2>(
-                                        point[1] - camera_position[1]) +
-                                      Utilities::fixed_power<2>(
-                                        point[2] - camera_position[2]));
+                            std::hypot(point[0] - camera_position[0],
+                                       point[1] - camera_position[1],
+                                       point[2] - camera_position[2]);
                           const double distance_factor =
                             distance_to_camera /
                             (2. * std::max(x_dimension, y_dimension));

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.