From: Wolfgang Bangerth Date: Wed, 10 Jan 2024 22:49:44 +0000 (-0700) Subject: Use std::hypot() instead of std::sqrt(sum of squares). X-Git-Tag: relicensing~151^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=907d0f04b0ebf839049e77c417bd944344f9314b;p=dealii.git Use std::hypot() instead of std::sqrt(sum of squares). --- diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index f64f3a23c0..a4e1b0d661 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -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.; diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 519f178682..ff628d015b 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -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));