File indexing completed on 2026-08-06 09:25:33
0001
0002
0003
0004
0005 #ifndef NINJA_TYPES_HH
0006 #define NINJA_TYPES_HH
0007
0008 #include <ninja/ninja_config.h>
0009
0010
0011
0012 #if defined(NINJA_QUADRUPLE) || defined(QUADNINJA_TYPES_HH_INSIDE)
0013 # include <ninja/quadruple.hh>
0014 #else
0015 # include <cmath>
0016 # include <complex>
0017 #endif
0018
0019 #include <iostream>
0020 #include <limits>
0021
0022 #include <ninja/static_arrays.hh>
0023 #include <ninja/zero_float.hh>
0024
0025 #if defined(NINJA_NO_EXCEPTIONS)
0026 # define NINJA_THROW(exception) (std::terminate())
0027 #else
0028 # define NINJA_THROW(exception) throw exception
0029 #endif
0030
0031 #define NINJA_REAL(x) (ninja::Real(x))
0032
0033 #if !defined(NINJA_QUADRUPLE) && !defined(QUADNINJA_TYPES_HH_INSIDE)
0034 # define NINJA_REAL_DEF(x) (ninja::Real(x))
0035 # define NINJA_COMPLEX_DEF(r,i) (ninja::Complex(r,i))
0036 #else
0037 # define NINJA_TOKEN_QPASTE0(x,y) x##y
0038 # define NINJA_REAL_DEF(x) (ninja::Real(NINJA_TOKEN_QPASTE0(x,q)))
0039 # define NINJA_COMPLEX_DEF(r,i) (ninja::Complex(NINJA_REAL_DEF(r)),ninja::Complex(NINJA_REAL_DEF(i)))
0040 #endif
0041
0042
0043 namespace ninja {
0044
0045
0046 #if !defined(NINJA_QUADRUPLE) && !defined(QUADNINJA_TYPES_HH_INSIDE)
0047 typedef double Real;
0048 typedef std::complex<Real> Complex;
0049 const Real INFRARED_EPS = 1.0e-09;
0050 const Real REAL_EPS = Real(1.0e+3)*std::numeric_limits<Real>::epsilon();
0051 const Real REAL_MIN = Real(1.0e+20)*std::numeric_limits<Real>::min();
0052 #else
0053 typedef ninja::Quadruple Real;
0054 typedef ninja::ComplexQuadruple Complex;
0055 const Real INFRARED_EPS = 1.0e+15*FLT128_EPSILON;
0056 const Real REAL_EPS = Real(1.0e+3)*FLT128_EPSILON;
0057 const Real REAL_MIN = Real(1.0e+20)*FLT128_MIN;
0058 #endif
0059
0060
0061 typedef Real RealMasses;
0062 typedef Complex ComplexMasses;
0063 typedef ZeroFloat Massless;
0064
0065
0066
0067 const Complex I(Real(0.),Real(1.));
0068
0069
0070 #if !defined(NINJA_QUADRUPLE) && !defined(QUADNINJA_TYPES_HH_INSIDE)
0071
0072 inline Real real(Real z)
0073 {
0074 return z;
0075 }
0076 inline Real real(const Complex & z)
0077 {
0078 return std::real(z);
0079 }
0080
0081 inline Real imag(Real)
0082 {
0083 return 0;
0084 }
0085 inline Real imag(const Complex & z)
0086 {
0087 return std::imag(z);
0088 }
0089
0090 inline Real conj(Real z)
0091 {
0092 return z;
0093 }
0094 inline Complex conj(const Complex & z)
0095 {
0096 return std::conj(z);
0097 }
0098
0099 inline Real abs(Real z)
0100 {
0101 return std::abs(z);
0102 }
0103 inline Real abs(const Complex & z)
0104 {
0105 return std::abs(z);
0106 }
0107
0108 inline Real pow(Real z, unsigned n)
0109 {
0110 return std::pow(z, n);
0111 }
0112 #define NINJA_IMPORT_STD_FUN(fun) \
0113 inline Real fun(Real z) \
0114 { \
0115 return std::fun(z); \
0116 } \
0117 inline Complex fun(const Complex & z) \
0118 { \
0119 return std::fun(z); \
0120 }
0121 NINJA_IMPORT_STD_FUN(sqrt)
0122 NINJA_IMPORT_STD_FUN(log)
0123 NINJA_IMPORT_STD_FUN(cos)
0124 NINJA_IMPORT_STD_FUN(sin)
0125 #undef NINJA_IMPORT_STD_FUN
0126 #endif
0127
0128 inline Real norm2(Real x)
0129 {
0130 return x*x;
0131 }
0132
0133
0134
0135
0136
0137
0138 inline Real taxicab_norm (const Complex & z)
0139 {
0140 return abs(real(z))+abs(imag(z));
0141 }
0142
0143
0144 inline Real taxicab_norm(const Real & x)
0145 {
0146 return abs(x);
0147 }
0148
0149
0150
0151 template<typename X> struct const_pointer
0152 {
0153 typedef const X* type;
0154 };
0155
0156
0157 template<> struct const_pointer<ZeroFloat> {
0158 typedef ZeroFloatArray type;
0159 };
0160
0161
0162
0163 inline Real real (ZeroFloat)
0164 {
0165 return Real();
0166 }
0167
0168
0169 inline Complex toCmplx (const Complex & z)
0170 {
0171 return z;
0172 }
0173 inline Complex toCmplx (const ZeroFloat &)
0174 {
0175 return Complex();
0176 }
0177
0178
0179
0180
0181 const Real ZERO = Real(0.0);
0182 const Real INV8 = Real(0.125);
0183 const Real INV4 = Real(0.25);
0184 const Real HALF = Real(0.5);
0185 const Real ONE = Real(1.);
0186 const Real ONEDOTFIVE = Real(1.5);
0187 const Real TWO = Real(2.);
0188 const Real THREE = Real(3.);
0189 const Real FOUR = Real(4.);
0190 const Real FIVE = Real(5.);
0191 const Real SIX = Real(6.);
0192 const Real EIGHT = Real(8.);
0193 const Real TWELVE = Real(12.);
0194 const Real SIXTEEN = Real(16.);
0195 const Real SQRT2 = sqrt(TWO);
0196 const Real SQRT3 = sqrt(THREE);
0197
0198 const Real INVSQRT2 = HALF*SQRT2;
0199 const Real INVSQRT3 = 1./sqrt(THREE);
0200 const Real INVSQRT6 = 1./sqrt(Real(6.));
0201
0202 #if !defined(NINJA_QUADRUPLE) && !defined(QUADNINJA_TYPES_HH_INSIDE)
0203 const ninja::Real PI = M_PI;
0204 #else
0205 const ninja::Real PI = M_PIq;
0206 #endif
0207
0208 }
0209
0210 #undef QUADNINJA_TYPES_HH_INSIDE
0211
0212 #endif