Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:09:40

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/math/detail/SoftEqualTraits.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 
0011 namespace celeritas
0012 {
0013 namespace detail
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Provide relative errors for soft_equiv based on type.
0018  *
0019  * This also gives compile-time checking for bad values.
0020  */
0021 template<class T>
0022 struct SoftEqualTraits
0023 {
0024     using value_type = T;
0025 
0026     //! Default relative error
0027     static CELER_CONSTEXPR_FUNCTION value_type rel_prec()
0028     {
0029         static_assert(sizeof(T) == 0, "Invalid type for softeq!");
0030         return T();
0031     }
0032 
0033     //! Default absolute error
0034     static CELER_CONSTEXPR_FUNCTION value_type abs_thresh()
0035     {
0036         static_assert(sizeof(T) == 0, "Invalid type for softeq!");
0037         return T();
0038     }
0039 };
0040 
0041 template<>
0042 struct SoftEqualTraits<double>
0043 {
0044     using value_type = double;
0045     static CELER_CONSTEXPR_FUNCTION value_type sqrt_prec() { return 1.0e-6; }
0046     static CELER_CONSTEXPR_FUNCTION value_type rel_prec() { return 1.0e-12; }
0047     static CELER_CONSTEXPR_FUNCTION value_type abs_thresh() { return 1.0e-14; }
0048 };
0049 
0050 template<>
0051 struct SoftEqualTraits<float>
0052 {
0053     using value_type = float;
0054     static CELER_CONSTEXPR_FUNCTION value_type sqrt_prec() { return 1.0e-3f; }
0055     static CELER_CONSTEXPR_FUNCTION value_type rel_prec() { return 1.0e-6f; }
0056     static CELER_CONSTEXPR_FUNCTION value_type abs_thresh() { return 1.0e-6f; }
0057 };
0058 
0059 //---------------------------------------------------------------------------//
0060 }  // namespace detail
0061 }  // namespace celeritas