Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:48

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