A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
int64x64-double.h
1 #include "ns3/core-config.h"
2 #if !defined(INT64X64_DOUBLE_H) && (defined (INT64X64_USE_DOUBLE) || defined(PYTHON_SCAN))
3 #define INT64X64_DOUBLE_H
4 
5 #include <iostream>
6 #include <cmath>
7 
8 namespace ns3 {
9 
10 class int64x64_t
11 {
12 public:
13  inline int64x64_t ()
14  : _v (0) {}
15  inline int64x64_t (double v)
16  : _v (v) {}
17  inline int64x64_t (int v)
18  : _v (v) {}
19  inline int64x64_t (long int v)
20  : _v (v) {}
21  inline int64x64_t (long long int v)
22  : _v (v) {}
23  inline int64x64_t (unsigned int v)
24  : _v (v) {}
25  inline int64x64_t (unsigned long int v)
26  : _v (v) {}
27  inline int64x64_t (unsigned long long int v)
28  : _v (v) {}
29  inline int64x64_t (int64_t hi, uint64_t lo)
30  : _v (hi) { /* XXX */}
31 
32  inline int64x64_t (const int64x64_t &o)
33  : _v (o._v) {}
34  inline int64x64_t &operator = (const int64x64_t &o)
35  {
36  _v = o._v;
37  return *this;
38  }
39 
40  inline double GetDouble (void) const
41  {
42  return _v;
43  }
44  inline int64_t GetHigh (void) const
45  {
46  return (int64_t)std::floor (_v);
47  }
48  inline uint64_t GetLow (void) const
49  {
50  // XXX
51  return 0;
52  }
53 
54  inline void MulByInvert (const int64x64_t &o)
55  {
56  _v *= o._v;
57  }
58 
59  static inline int64x64_t Invert (uint64_t v)
60  {
61  double d = v;
62  return int64x64_t (1/d);
63  }
64 
65 private:
66  friend bool operator == (const int64x64_t &lhs, const int64x64_t &rhs);
67  friend bool operator != (const int64x64_t &lhs, const int64x64_t &rhs);
68  friend bool operator <= (const int64x64_t &lhs, const int64x64_t &rhs);
69  friend bool operator >= (const int64x64_t &lhs, const int64x64_t &rhs);
70  friend bool operator < (const int64x64_t &lhs, const int64x64_t &rhs);
71  friend bool operator > (const int64x64_t &lhs, const int64x64_t &rhs);
72  friend int64x64_t &operator += (int64x64_t &lhs, const int64x64_t &rhs);
73  friend int64x64_t &operator -= (int64x64_t &lhs, const int64x64_t &rhs);
74  friend int64x64_t &operator *= (int64x64_t &lhs, const int64x64_t &rhs);
75  friend int64x64_t &operator /= (int64x64_t &lhs, const int64x64_t &rhs);
76  friend int64x64_t operator + (const int64x64_t &lhs, const int64x64_t &rhs);
77  friend int64x64_t operator - (const int64x64_t &lhs, const int64x64_t &rhs);
78  friend int64x64_t operator * (const int64x64_t &lhs, const int64x64_t &rhs);
79  friend int64x64_t operator / (const int64x64_t &lhs, const int64x64_t &rhs);
80  friend int64x64_t operator + (const int64x64_t &lhs);
81  friend int64x64_t operator - (const int64x64_t &lhs);
82  friend int64x64_t operator ! (const int64x64_t &lhs);
83 
84  double _v;
85 };
86 
87 inline bool operator == (const int64x64_t &lhs, const int64x64_t &rhs)
88 {
89  return lhs._v == rhs._v;
90 }
91 
92 inline bool operator != (const int64x64_t &lhs, const int64x64_t &rhs)
93 {
94  return lhs._v != rhs._v;
95 }
96 
97 inline bool operator <= (const int64x64_t &lhs, const int64x64_t &rhs)
98 {
99  return lhs._v <= rhs._v;
100 }
101 
102 inline bool operator >= (const int64x64_t &lhs, const int64x64_t &rhs)
103 {
104  return lhs._v >= rhs._v;
105 }
106 inline bool operator < (const int64x64_t &lhs, const int64x64_t &rhs)
107 {
108  return lhs._v < rhs._v;
109 }
110 inline bool operator > (const int64x64_t &lhs, const int64x64_t &rhs)
111 {
112  return lhs._v > rhs._v;
113 }
114 inline int64x64_t &operator += (int64x64_t &lhs, const int64x64_t &rhs)
115 {
116  double tmp = lhs._v;
117  tmp += rhs._v;
118  lhs = int64x64_t (tmp);
119  return lhs;
120 }
121 inline int64x64_t &operator -= (int64x64_t &lhs, const int64x64_t &rhs)
122 {
123  double tmp = lhs._v;
124  tmp -= rhs._v;
125  lhs = int64x64_t (tmp);
126  return lhs;
127 }
128 inline int64x64_t &operator *= (int64x64_t &lhs, const int64x64_t &rhs)
129 {
130  double tmp = lhs._v;
131  tmp *= rhs._v;
132  lhs = int64x64_t (tmp);
133  return lhs;
134 }
135 inline int64x64_t &operator /= (int64x64_t &lhs, const int64x64_t &rhs)
136 {
137  double tmp = lhs._v;
138  tmp /= rhs._v;
139  lhs = int64x64_t (tmp);
140  return lhs;
141 }
142 
143 inline int64x64_t operator + (const int64x64_t &lhs)
144 {
145  return lhs;
146 }
147 
148 inline int64x64_t operator - (const int64x64_t &lhs)
149 {
150  return int64x64_t (-lhs._v);
151 }
152 
153 inline int64x64_t operator ! (const int64x64_t &lhs)
154 {
155  return int64x64_t (!lhs._v);
156 }
157 
158 } // namespace ns3
159 
160 #endif /* INT64X64_DOUBLE_H */