Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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/QuantityImpl.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Macros.hh"
0011 
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 //! Helper class for getting attributes about a member function
0054 template<class T>
0055 struct AccessorTraits;
0056 
0057 //! \cond
0058 //! Access the return type using AccessorTraits<decltype(&Foo::bar)>
0059 template<class ResultType, class ClassType>
0060 struct AccessorTraits<ResultType (ClassType::*)() const>
0061 {
0062     using type = ClassType;
0063     using result_type = ResultType;
0064 };
0065 //! \endcond
0066 
0067 //! Get the result type of a class accessor
0068 template<class T>
0069 using AccessorResultType = typename AccessorTraits<T>::result_type;
0070 
0071 //---------------------------------------------------------------------------//
0072 }  // namespace detail
0073 }  // namespace celeritas