From 907d0f04b0ebf839049e77c417bd944344f9314b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 10 Jan 2024 15:49:44 -0700 Subject: [PATCH] Use std::hypot() instead of std::sqrt(sum of squares). --- source/base/data_out_base.cc | 7 +++---- source/grid/grid_out.cc | 17 +++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) 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)); -- 2.39.5