TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
internal::DiyFp Struct Reference

#include <diyfp.h>

Public Member Functions

 DiyFp ()
 
 DiyFp (uint64_t fp, int exp)
 
 DiyFp (double d)
 
DiyFp operator- (const DiyFp &rhs) const
 
DiyFp operator* (const DiyFp &rhs) const
 
DiyFp Normalize () const
 
DiyFp NormalizeBoundary () const
 
void NormalizedBoundaries (DiyFp *minus, DiyFp *plus) const
 
double ToDouble () const
 

Public Attributes

uint64_t f
 
int e
 

Static Public Attributes

static const int kDiySignificandSize = 64
 
static const int kDpSignificandSize = 52
 
static const int kDpExponentBias = 0x3FF + kDpSignificandSize
 
static const int kDpMaxExponent = 0x7FF - kDpExponentBias
 
static const int kDpMinExponent = -kDpExponentBias
 
static const int kDpDenormalExponent = -kDpExponentBias + 1
 
static const uint64_t kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000)
 
static const uint64_t kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF)
 
static const uint64_t kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)
 

Constructor & Destructor Documentation

internal::DiyFp::DiyFp ( )
inline
38 {}

+ Here is the caller graph for this function:

internal::DiyFp::DiyFp ( uint64_t  fp,
int  exp 
)
inline
40 : f(fp), e(exp) {}
Quat exp(const Quat &q)
Definition: Quat.h:729
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155
internal::DiyFp::DiyFp ( double  d)
inlineexplicit
42  {
43  union {
44  double d;
45  uint64_t u64;
46  } u = { d };
47 
48  int biased_e = static_cast<int>((u.u64 & kDpExponentMask) >> kDpSignificandSize);
49  uint64_t significand = (u.u64 & kDpSignificandMask);
50  if (biased_e != 0) {
51  f = significand + kDpHiddenBit;
52  e = biased_e - kDpExponentBias;
53  }
54  else {
55  f = significand;
56  e = kDpMinExponent + 1;
57  }
58  }
static const int kDpExponentBias
Definition: diyfp.h:146
static const uint64_t kDpSignificandMask
Definition: diyfp.h:151
unsigned __int64 uint64_t
Definition: stdint.h:90
uint64_t f
Definition: diyfp.h:154
static const uint64_t kDpExponentMask
Definition: diyfp.h:150
static const int kDpMinExponent
Definition: diyfp.h:148
int e
Definition: diyfp.h:155
static const uint64_t kDpHiddenBit
Definition: diyfp.h:152
static const int kDpSignificandSize
Definition: diyfp.h:145

Member Function Documentation

DiyFp internal::DiyFp::Normalize ( ) const
inline
95  {
96 #if defined(_MSC_VER) && defined(_M_AMD64)
97  unsigned long index;
98  _BitScanReverse64(&index, f);
99  return DiyFp(f << (63 - index), e - (63 - index));
100 #elif defined(__GNUC__) && __GNUC__ >= 4
101  int s = __builtin_clzll(f);
102  return DiyFp(f << s, e - s);
103 #else
104  DiyFp res = *this;
105  while (!(res.f & (static_cast<uint64_t>(1) << 63))) {
106  res.f <<= 1;
107  res.e--;
108  }
109  return res;
110 #endif
111  }
DiyFp()
Definition: diyfp.h:38
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DiyFp internal::DiyFp::NormalizeBoundary ( ) const
inline
113  {
114  DiyFp res = *this;
115  while (!(res.f & (kDpHiddenBit << 1))) {
116  res.f <<= 1;
117  res.e--;
118  }
119  res.f <<= (kDiySignificandSize - kDpSignificandSize - 2);
120  res.e = res.e - (kDiySignificandSize - kDpSignificandSize - 2);
121  return res;
122  }
static const int kDiySignificandSize
Definition: diyfp.h:144
DiyFp()
Definition: diyfp.h:38
static const uint64_t kDpHiddenBit
Definition: diyfp.h:152
static const int kDpSignificandSize
Definition: diyfp.h:145
void internal::DiyFp::NormalizedBoundaries ( DiyFp minus,
DiyFp plus 
) const
inline
124  {
125  DiyFp pl = DiyFp((f << 1) + 1, e - 1).NormalizeBoundary();
126  DiyFp mi = (f == kDpHiddenBit) ? DiyFp((f << 2) - 1, e - 2) : DiyFp((f << 1) - 1, e - 1);
127  mi.f <<= mi.e - pl.e;
128  mi.e = pl.e;
129  *plus = pl;
130  *minus = mi;
131  }
DiyFp()
Definition: diyfp.h:38
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155
static const uint64_t kDpHiddenBit
Definition: diyfp.h:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DiyFp internal::DiyFp::operator* ( const DiyFp rhs) const
inline

mult_round

64  {
65 #if defined(_MSC_VER) && defined(_M_AMD64)
66  uint64_t h;
67  uint64_t l = _umul128(f, rhs.f, &h);
68  if (l & (uint64_t(1) << 63)) // rounding
69  h++;
70  return DiyFp(h, e + rhs.e + 64);
71 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
72  __extension__ typedef unsigned __int128 uint128;
73  uint128 p = static_cast<uint128>(f) * static_cast<uint128>(rhs.f);
74  uint64_t h = static_cast<uint64_t>(p >> 64);
75  uint64_t l = static_cast<uint64_t>(p);
76  if (l & (uint64_t(1) << 63)) // rounding
77  h++;
78  return DiyFp(h, e + rhs.e + 64);
79 #else
80  const uint64_t M32 = 0xFFFFFFFF;
81  const uint64_t a = f >> 32;
82  const uint64_t b = f & M32;
83  const uint64_t c = rhs.f >> 32;
84  const uint64_t d = rhs.f & M32;
85  const uint64_t ac = a * c;
86  const uint64_t bc = b * c;
87  const uint64_t ad = a * d;
88  const uint64_t bd = b * d;
89  uint64_t tmp = (bd >> 32) + (ad & M32) + (bc & M32);
90  tmp += 1U << 31;
91  return DiyFp(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs.e + 64);
92 #endif
93  }
DiyFp()
Definition: diyfp.h:38
unsigned __int64 uint64_t
Definition: stdint.h:90
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155

+ Here is the call graph for this function:

DiyFp internal::DiyFp::operator- ( const DiyFp rhs) const
inline
60  {
61  return DiyFp(f - rhs.f, e);
62  }
DiyFp()
Definition: diyfp.h:38
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155

+ Here is the call graph for this function:

double internal::DiyFp::ToDouble ( ) const
inline
133  {
134  union {
135  double d;
136  uint64_t u64;
137  }u;
138  const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
139  static_cast<uint64_t>(e + kDpExponentBias);
140  u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
141  return u.d;
142  }
static const int kDpExponentBias
Definition: diyfp.h:146
static const uint64_t kDpSignificandMask
Definition: diyfp.h:151
unsigned __int64 uint64_t
Definition: stdint.h:90
static const int kDpDenormalExponent
Definition: diyfp.h:149
uint64_t f
Definition: diyfp.h:154
int e
Definition: diyfp.h:155
static const uint64_t kDpHiddenBit
Definition: diyfp.h:152
static const int kDpSignificandSize
Definition: diyfp.h:145

+ Here is the caller graph for this function:

Member Data Documentation

int internal::DiyFp::e
uint64_t internal::DiyFp::f
const int internal::DiyFp::kDiySignificandSize = 64
static
const int internal::DiyFp::kDpDenormalExponent = -kDpExponentBias + 1
static
const int internal::DiyFp::kDpExponentBias = 0x3FF + kDpSignificandSize
static
const uint64_t internal::DiyFp::kDpExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000)
static
const uint64_t internal::DiyFp::kDpHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)
static
const int internal::DiyFp::kDpMaxExponent = 0x7FF - kDpExponentBias
static
const int internal::DiyFp::kDpMinExponent = -kDpExponentBias
static
const uint64_t internal::DiyFp::kDpSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF)
static
const int internal::DiyFp::kDpSignificandSize = 52
static

The documentation for this struct was generated from the following file: