Move sqrt_3 from constants.h to accurate_norm_test.cc sqrt_3_v and sqrt_3 are only used as test expectations in accurate_norm_test.cc. Move them out of the public ceres::constants namespace and into the test file. Change-Id: I64fa1177cd6695838e10fc48b7cc736400de5241
diff --git a/include/ceres/constants.h b/include/ceres/constants.h index e3c0680..e4c96da 100644 --- a/include/ceres/constants.h +++ b/include/ceres/constants.h
@@ -34,13 +34,12 @@ // TODO(HSHelson): This header should no longer be necessary once C++20's // <numbers> (e.g. std::numbers::pi_v) becomes usable -// The constants are computed using mpmath by the following shell command: +// The constant is computed using mpmath by the following shell command: // // python3 - <<EOF // from mpmath import mp // mp.dps = 64 // print(mp.pi) -// print(mp.sqrt(3)) // EOF namespace ceres::constants { // π @@ -48,11 +47,6 @@ inline constexpr T pi_v( 3.141592653589793238462643383279502884197169399375105820974944592L); inline constexpr double pi = pi_v<double>; -// √3 -template <typename T> -inline constexpr T sqrt_3_v( - 1.732050807568877293527446341505872366942805253810380628055806979L); -inline constexpr double sqrt_3 = sqrt_3_v<double>; } // namespace ceres::constants #endif // CERES_PUBLIC_CONSTANTS_H_
diff --git a/internal/ceres/accurate_norm_test.cc b/internal/ceres/accurate_norm_test.cc index 102cd65..e5d0570 100644 --- a/internal/ceres/accurate_norm_test.cc +++ b/internal/ceres/accurate_norm_test.cc
@@ -36,10 +36,21 @@ #include <limits> #include <type_traits> -#include "ceres/constants.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +// The constant is computed using mpmath by the following shell command: +// +// python3 - <<EOF +// from mpmath import mp +// mp.dps = 64 +// print(mp.sqrt(3)) +// EOF +// √3 +template <typename T> +inline constexpr T kSqrt3( + 1.732050807568877293527446341505872366942805253810380628055806979L); + // Matches if the argument is at most n floating-point values away from the // expected value. MATCHER_P2(MaxNumUlp, expected, n, "") { @@ -180,10 +191,8 @@ MaxNumUlp(1 / (std::sqrt(Scalar{2}) * this->kTiny), 1)); const auto tiny3 = std::sqrt(this->kTiny) / Scalar{3}; - EXPECT_THAT( - ceres::AccurateRNorm(tiny3, tiny3, tiny3), - MaxNumUlp(ceres::constants::sqrt_3_v<Scalar> / std::sqrt(this->kTiny), - 1)); + EXPECT_THAT(ceres::AccurateRNorm(tiny3, tiny3, tiny3), + MaxNumUlp(kSqrt3<Scalar> / std::sqrt(this->kTiny), 1)); const auto tiny4 = std::sqrt(this->kTiny) / Scalar{4}; EXPECT_THAT(ceres::AccurateRNorm(tiny4, tiny4, tiny4, tiny4), @@ -335,7 +344,7 @@ TEST(AccurateNorm, VariadicNormAccuracy) { EXPECT_THAT(ceres::AccurateNorm(1.0, 1.0, 1.0), - MaxNumUlp(ceres::constants::sqrt_3, 0)); + MaxNumUlp(kSqrt3<double>, 0)); // Combination exposing a difference of at least two ULPs in inaccurate // implementations found by random search.