CMS 3D CMS Logo

Functions
approx_log.h File Reference
#include "DataFormats/Math/interface/approx_math.h"

Go to the source code of this file.

Functions

template<int DEGREE>
constexpr float approx_logf (float x)
 
template<int DEGREE>
constexpr float approx_logf_P (float p)
 
template<>
constexpr float approx_logf_P< 2 > (float y)
 
template<>
constexpr float approx_logf_P< 3 > (float y)
 
template<>
constexpr float approx_logf_P< 4 > (float y)
 
template<>
constexpr float approx_logf_P< 5 > (float y)
 
template<>
constexpr float approx_logf_P< 6 > (float y)
 
template<>
constexpr float approx_logf_P< 7 > (float y)
 
template<>
constexpr float approx_logf_P< 8 > (float y)
 
template<int DEGREE>
constexpr float unsafe_logf (float x)
 
template<int DEGREE>
constexpr float unsafe_logf_impl (float x)
 

Function Documentation

◆ approx_logf()

template<int DEGREE>
constexpr float approx_logf ( float  x)
constexpr

Definition at line 127 of file approx_log.h.

127  {
128  using namespace approx_math;
129 
130  constexpr float MAXNUMF = 3.4028234663852885981170418348451692544e38f;
131 
132  //x = std::max(std::min(x,MAXNUMF),0.f);
133  float res = unsafe_logf<DEGREE>(x);
135  return (x > 0) ? res : std::numeric_limits<float>::quiet_NaN();
136 }

References infinity.

◆ approx_logf_P()

template<int DEGREE>
constexpr float approx_logf_P ( float  p)
constexpr

◆ approx_logf_P< 2 >()

template<>
constexpr float approx_logf_P< 2 > ( float  y)
constexpr

Definition at line 38 of file approx_log.h.

38  {
39  return y * (float(0x1.0671c4p0) + y * (float(-0x7.27744p-4)));
40 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x1, and detailsBasic3DVector::y.

◆ approx_logf_P< 3 >()

template<>
constexpr float approx_logf_P< 3 > ( float  y)
constexpr

Definition at line 44 of file approx_log.h.

44  {
45  return y * (float(0x1.013354p0) + y * (-float(0x8.33006p-4) + y * float(0x4.0d16cp-4)));
46 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x1, and detailsBasic3DVector::y.

◆ approx_logf_P< 4 >()

template<>
constexpr float approx_logf_P< 4 > ( float  y)
constexpr

Definition at line 50 of file approx_log.h.

50  {
51  return y *
52  (float(0xf.ff5bap-4) + y * (-float(0x8.13e5ep-4) + y * (float(0x5.826ep-4) + y * (-float(0x2.e87fb8p-4)))));
53 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x2, and detailsBasic3DVector::y.

◆ approx_logf_P< 5 >()

template<>
constexpr float approx_logf_P< 5 > ( float  y)
constexpr

Definition at line 57 of file approx_log.h.

57  {
58  return y * (float(0xf.ff652p-4) +
59  y * (-float(0x8.0048ap-4) +
60  y * (float(0x5.72782p-4) + y * (-float(0x4.20904p-4) + y * float(0x2.1d7fd8p-4)))));
61 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x2, and detailsBasic3DVector::y.

◆ approx_logf_P< 6 >()

template<>
constexpr float approx_logf_P< 6 > ( float  y)
constexpr

Definition at line 65 of file approx_log.h.

65  {
66  return y * (float(0xf.fff14p-4) +
67  y * (-float(0x7.ff4bfp-4) +
68  y * (float(0x5.582f6p-4) +
69  y * (-float(0x4.1dcf2p-4) + y * (float(0x3.3863f8p-4) + y * (-float(0x1.9288d4p-4)))))));
70 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x1, and detailsBasic3DVector::y.

◆ approx_logf_P< 7 >()

template<>
constexpr float approx_logf_P< 7 > ( float  y)
constexpr

Definition at line 74 of file approx_log.h.

74  {
75  return y * (float(0x1.000034p0) +
76  y * (-float(0x7.ffe57p-4) +
77  y * (float(0x5.5422ep-4) +
78  y * (-float(0x4.037a6p-4) +
79  y * (float(0x3.541c88p-4) + y * (-float(0x2.af842p-4) + y * float(0x1.48b3d8p-4)))))));
80 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, and detailsBasic3DVector::y.

◆ approx_logf_P< 8 >()

template<>
constexpr float approx_logf_P< 8 > ( float  y)
constexpr

Definition at line 84 of file approx_log.h.

84  {
85  return y *
86  (float(0x1.00000cp0) +
87  y * (float(-0x8.0003p-4) +
88  y * (float(0x5.55087p-4) +
89  y * (float(-0x3.fedcep-4) +
90  y * (float(0x3.3a1dap-4) +
91  y * (float(-0x2.cb55fp-4) + y * (float(0x2.38831p-4) + y * (float(-0xf.e87cap-8)))))))));
92 }

References dqmMemoryStats::float, testProducerWithPsetDescEmpty_cfi::x1, testProducerWithPsetDescEmpty_cfi::x2, and detailsBasic3DVector::y.

◆ unsafe_logf()

template<int DEGREE>
constexpr float unsafe_logf ( float  x)
constexpr

Definition at line 122 of file approx_log.h.

122  {
123  return unsafe_logf_impl<DEGREE>(x);
124 }

References genVertex_cff::x.

◆ unsafe_logf_impl()

template<int DEGREE>
constexpr float unsafe_logf_impl ( float  x)
constexpr

Definition at line 95 of file approx_log.h.

95  {
96  using namespace approx_math;
97 
98  binary32 xx, m;
99  xx.f = x;
100 
101  // as many integer computations as possible, most are 1-cycle only, and lots of ILP.
102  int e = (((xx.i32) >> 23) & 0xFF) - 127; // extract exponent
103  m.i32 = (xx.i32 & 0x007FFFFF) | 0x3F800000; // extract mantissa as an FP number
104 
105  int adjust = (xx.i32 >> 22) & 1; // first bit of the mantissa, tells us if 1.m > 1.5
106  m.i32 -= adjust << 23; // if so, divide 1.m by 2 (exact operation, no rounding)
107  e += adjust; // and update exponent so we still have x=2^E*y
108 
109  // now back to floating-point
110  float y = m.f - 1.0f; // Sterbenz-exact; cancels but we don't care about output relative error
111  // all the computations so far were free of rounding errors...
112 
113  // the following is based on Sollya output
114  float p = approx_logf_P<DEGREE>(y);
115 
116  constexpr float Log2 = 0xb.17218p-4; // 0.693147182464599609375
117  return float(e) * Log2 + p;
118 }

References MillePedeFileConverter_cfg::e, dqmMemoryStats::float, visualization-live-secondInstance_cfg::m, AlCaHLTBitMon_ParallelJobs::p, and geometryCSVtoXML::xx.

dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
approx_math::binary32
Definition: approx_math.h:12
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
infinity
const double infinity
Definition: CSCChamberFitter.cc:10
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
res
Definition: Electron.h:6
approx_math
Definition: approx_math.h:9
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37