Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 08:53:53

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/QuantityImpl.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/Macros.hh"
0010 
0011 #include "../Constant.hh"
0012 #include "../NumericLimits.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace detail
0017 {
0018 //---------------------------------------------------------------------------//
0019 //! Helper tag for special unitless values
0020 enum class QConstant
0021 {
0022     neg_max = -1,
0023     zero = 0,
0024     max = 1
0025 };
0026 
0027 //! Convert unitless values into a particular type
0028 template<class T>
0029 CELER_CONSTEXPR_FUNCTION T get_constant(QConstant qc)
0030 {
0031     if constexpr (std::is_floating_point_v<T>)
0032     {
0033         // Return +/- infinity
0034         return qc == QConstant::neg_max ? -numeric_limits<T>::infinity()
0035                : qc == QConstant::max   ? numeric_limits<T>::infinity()
0036                                         : 0;
0037     }
0038     else
0039     {
0040         // Return lowest and highest values
0041         return qc == QConstant::neg_max ? numeric_limits<T>::lowest()
0042                : qc == QConstant::max   ? numeric_limits<T>::max()
0043                                         : 0;
0044     }
0045 }
0046 
0047 //! Tag class for creating a nonnumeric value comparable to Quantity.
0048 template<QConstant QC>
0049 struct UnitlessQuantity
0050 {
0051 };
0052 
0053 //---------------------------------------------------------------------------//
0054 //! Helper class for getting attributes about a member function
0055 template<class T>
0056 struct AccessorTraits;
0057 
0058 //! \cond
0059 //! Access the return type using AccessorTraits<decltype(&Foo::bar)>
0060 template<class ResultType, class ClassType>
0061 struct AccessorTraits<ResultType (ClassType::*)() const>
0062 {
0063     using type = ClassType;
0064     using result_type = ResultType;
0065 };
0066 //! \endcond
0067 
0068 //! Get the result type of a class accessor
0069 template<class T>
0070 using AccessorResultType = typename AccessorTraits<T>::result_type;
0071 
0072 //---------------------------------------------------------------------------//
0073 }  // namespace detail
0074 }  // namespace celeritas