Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 08:21:05

0001 
0002 #ifndef G4HepEmMath_HH
0003 #define G4HepEmMath_HH
0004 
0005 #include <cmath>
0006 
0007 #include "G4HepEmExp.hh"
0008 #include "G4HepEmLog.hh"
0009 
0010 #include "G4HepEmMacros.hh"
0011 
0012 template <typename T>
0013 G4HepEmHostDevice static inline
0014 T G4HepEmMax(T a, T b) {
0015  return a > b ? a : b;
0016 }
0017 
0018 template <typename T>
0019 G4HepEmHostDevice static inline
0020 T G4HepEmMin(T a, T b) {
0021  return a < b ? a : b;
0022 }
0023 
0024 template <typename T>
0025 G4HepEmHostDevice static inline
0026 T G4HepEmX13(T x) {
0027  return std::pow(x, 1./3.);
0028 }
0029 
0030 // --- Log function with VDT (G4Log) specialisations for double and float
0031 template <typename T>
0032 G4HepEmHostDevice inline
0033 T G4HepEmLog(T x) {
0034  return std::log(x);
0035 }
0036 // use the specialisations only on the host
0037 #ifndef __CUDA_ARCH__
0038 template < >
0039 inline
0040 double G4HepEmLog(double x) {
0041  return VDTLog(x);
0042 }
0043 template < >
0044 inline
0045 float G4HepEmLog(float x) {
0046  return VDTLogf(x);
0047 }
0048 #endif // ndef __CUDA_ARCH__
0049 
0050 // --- Exp function with VDT (G4Exp) specialisations for double and float
0051 template <typename T>
0052 G4HepEmHostDevice inline
0053 T G4HepEmExp(T x) {
0054  return std::exp(x);
0055 }
0056 // use the specialisations only on the host
0057 #ifndef __CUDA_ARCH__
0058 template < >
0059 inline
0060 double G4HepEmExp(double x) {
0061  return VDTExp(x);
0062 }
0063 template < >
0064 inline
0065 float G4HepEmExp(float x) {
0066  return VDTExpf(x);
0067 }
0068 #endif // ndef __CUDA_ARCH__
0069 
0070 // --- Pow(x,a) function with the VDT (G4) Exp and Log specialisations for double and float
0071 template <typename T>
0072 G4HepEmHostDevice inline
0073 T G4HepEmPow(T x, T a) {
0074  return std::pow(x, a);
0075 }
0076 // use the specialisations only on the host
0077 #ifndef __CUDA_ARCH__
0078 template < >
0079 inline
0080 double G4HepEmPow(double x, double a) {
0081  return VDTExp(a*VDTLog(x));
0082 }
0083 template < >
0084 inline
0085 float G4HepEmPow(float x, float a) {
0086  return VDTExpf(a*VDTLogf(x));
0087 }
0088 #endif // ndef __CUDA_ARCH__
0089 
0090 #endif // G4HepEmMath_HH