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

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

Definition at line 117 of file approx_log.h.

References constexpr, infinity, cmsBatch::log, and unsafe_logf().

117  {
118  using namespace approx_math;
119 
120 
121  constexpr float MAXNUMF = 3.4028234663852885981170418348451692544e38f;
122 
123  //x = std::max(std::min(x,MAXNUMF),0.f);
124  float res = unsafe_logf<DEGREE>(x);
126  return (x>0) ? res :std::numeric_limits<float>::quiet_NaN();
127 }
Definition: Electron.h:6
const double infinity
#define constexpr
template<int DEGREE>
constexpr float approx_logf_P ( float  p)
template<>
constexpr float approx_logf_P< 2 > ( float  y)

Definition at line 40 of file approx_log.h.

References objects.autophobj::float, globals_cff::x1, and detailsBasic3DVector::y.

40  {
41  return y * ( float(0x1.0671c4p0) + y * ( float(-0x7.27744p-4) )) ;
42 }
template<>
constexpr float approx_logf_P< 3 > ( float  y)

Definition at line 46 of file approx_log.h.

References objects.autophobj::float, globals_cff::x1, and detailsBasic3DVector::y.

46  {
47  return y * (float(0x1.013354p0) + y * (-float(0x8.33006p-4) + y * float(0x4.0d16cp-4))) ;
48 }
template<>
constexpr float approx_logf_P< 4 > ( float  y)

Definition at line 52 of file approx_log.h.

References objects.autophobj::float, globals_cff::x2, and detailsBasic3DVector::y.

52  {
53  return y * (float(0xf.ff5bap-4) + y * (-float(0x8.13e5ep-4) + y * (float(0x5.826ep-4) + y * (-float(0x2.e87fb8p-4))))) ;
54 }
template<>
constexpr float approx_logf_P< 5 > ( float  y)

Definition at line 58 of file approx_log.h.

References objects.autophobj::float, globals_cff::x2, and detailsBasic3DVector::y.

58  {
59  return y * (float(0xf.ff652p-4) + y * (-float(0x8.0048ap-4) + y * (float(0x5.72782p-4) + y * (-float(0x4.20904p-4) + y * float(0x2.1d7fd8p-4))))) ;
60 }
template<>
constexpr float approx_logf_P< 6 > ( float  y)

Definition at line 64 of file approx_log.h.

References objects.autophobj::float, globals_cff::x1, and detailsBasic3DVector::y.

64  {
65  return y * (float(0xf.fff14p-4) + y * (-float(0x7.ff4bfp-4) + y * (float(0x5.582f6p-4) + y * (-float(0x4.1dcf2p-4) + y * (float(0x3.3863f8p-4) + y * (-float(0x1.9288d4p-4))))))) ;
66 }
template<>
constexpr float approx_logf_P< 7 > ( float  y)

Definition at line 70 of file approx_log.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

70  {
71  return y * (float(0x1.000034p0) + y * (-float(0x7.ffe57p-4) + y * (float(0x5.5422ep-4) + y * (-float(0x4.037a6p-4) + y * (float(0x3.541c88p-4) + y * (-float(0x2.af842p-4) + y * float(0x1.48b3d8p-4))))))) ;
72 }
template<>
constexpr float approx_logf_P< 8 > ( float  y)

Definition at line 76 of file approx_log.h.

References objects.autophobj::float, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::y.

76  {
77  return y * ( float(0x1.00000cp0) + y * (float(-0x8.0003p-4) + y * (float(0x5.55087p-4) + y * ( float(-0x3.fedcep-4) + y * (float(0x3.3a1dap-4) + y * (float(-0x2.cb55fp-4) + y * (float(0x2.38831p-4) + y * (float(-0xf.e87cap-8) )))))))) ;
78 }
template<int DEGREE>
constexpr float unsafe_logf ( float  x)

Definition at line 112 of file approx_log.h.

Referenced by approx_logf().

112  {
113  return unsafe_logf_impl<DEGREE>(x);
114 }
template<int DEGREE>
constexpr float unsafe_logf_impl ( float  x)

Definition at line 83 of file approx_log.h.

References constexpr, MillePedeFileConverter_cfg::e, approx_math::binary32::f, objects.autophobj::float, approx_math::binary32::i32, funct::m, AlCaHLTBitMon_ParallelJobs::p, and geometryCSVtoXML::xx.

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