Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:19

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Utilities/MathHelpers.hpp"
0013 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0014 
0015 #include <cmath>
0016 
0017 namespace bdata = boost::unit_test::data;
0018 
0019 const auto expDist = bdata::random(
0020     (bdata::engine = std::mt19937{}, bdata::seed = 0,
0021      bdata::distribution = std::uniform_real_distribution<double>(-4, 4)));
0022 
0023 namespace ActsTetsts {
0024 
0025 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0026 
0027 BOOST_DATA_TEST_CASE(fastHypot, expDist ^ expDist ^ bdata::xrange(100), xExp,
0028                      yExp, i) {
0029   (void)i;
0030 
0031   const double x = std::pow(10, xExp);
0032   const double y = std::pow(10, yExp);
0033 
0034   const float fastFloat =
0035       Acts::fastHypot(static_cast<float>(x), static_cast<float>(y));
0036   const double fastDouble = Acts::fastHypot(x, y);
0037 
0038   const float stdFloat =
0039       std::hypot(static_cast<float>(x), static_cast<float>(y));
0040   const double stdDouble = std::hypot(x, y);
0041 
0042   CHECK_CLOSE_REL(stdFloat, fastFloat, 1e-6);
0043   CHECK_CLOSE_REL(stdDouble, fastDouble, 1e-6);
0044 }
0045 
0046 BOOST_AUTO_TEST_CASE(CopySign) {
0047   BOOST_CHECK_EQUAL(Acts::copySign(5, -10), -5);
0048   BOOST_CHECK_EQUAL(Acts::copySign(5, 0), 5);
0049   BOOST_CHECK_EQUAL(Acts::copySign(5, 55), 5);
0050 
0051   static_assert(Acts::copySign(5, -10) == -5);
0052   static_assert(Acts::copySign(5, 0) == 5);
0053   static_assert(Acts::copySign(5, 55) == 5);
0054 
0055   BOOST_CHECK_EQUAL(Acts::copySign(5, -std::numeric_limits<double>::infinity()),
0056                     -5);
0057   BOOST_CHECK_EQUAL(Acts::copySign(5, std::numeric_limits<double>::infinity()),
0058                     5);
0059 
0060   static_assert(Acts::copySign(5., -std::numeric_limits<double>::infinity()) ==
0061                 -5.);
0062   static_assert(Acts::copySign(5., 0) == 5);
0063   static_assert(Acts::copySign(5., std::numeric_limits<double>::infinity()) ==
0064                 5.);
0065 
0066   BOOST_CHECK_EQUAL(Acts::copySign(5., -10.), -5.);
0067   BOOST_CHECK_EQUAL(Acts::copySign(5., 0.), 5.);
0068   BOOST_CHECK_EQUAL(Acts::copySign(5., 55.), 5.);
0069 
0070   enum class CopyEnum : int { b = 1, a = -1, c = 0 };
0071   BOOST_CHECK_EQUAL(Acts::copySign(5, CopyEnum::a), -5);
0072   BOOST_CHECK_EQUAL(Acts::copySign(5, CopyEnum::b), 5);
0073   BOOST_CHECK_EQUAL(Acts::copySign(5, CopyEnum::c), 5);
0074 
0075   const Acts::Vector3 v{Acts::Vector3::UnitZ()};
0076   CHECK_CLOSE_ABS(Acts::copySign(v, -1).dot(v), -1., 1.e-7);
0077   CHECK_CLOSE_ABS(Acts::copySign(v, 1).dot(v), 1., 1.e-7);
0078 }
0079 
0080 BOOST_AUTO_TEST_SUITE_END()
0081 
0082 }  // namespace ActsTetsts