LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 INRIA | 3 * Copyright (c) 2010 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 /** | 92 /** |
93 * Construct from an integral type. | 93 * Construct from an integral type. |
94 * | 94 * |
95 * \param [in] v Integer value to represent | 95 * \param [in] v Integer value to represent |
96 */ | 96 */ |
97 inline int64x64_t (int v) | 97 inline int64x64_t (int v) |
98 : _v (v) {} | 98 : _v (v) {} |
99 inline int64x64_t (long int v) | 99 inline int64x64_t (long int v) |
100 : _v (v) {} | 100 : _v (v) {} |
101 inline int64x64_t (long long int v) | 101 inline int64x64_t (long long int v) |
102 : _v (static_cast<double>(v)) {} | 102 : _v (static_cast<double> (v)) {} |
103 inline int64x64_t (unsigned int v) | 103 inline int64x64_t (unsigned int v) |
104 : _v (v) {} | 104 : _v (v) {} |
105 inline int64x64_t (unsigned long int v) | 105 inline int64x64_t (unsigned long int v) |
106 : _v (v) {} | 106 : _v (v) {} |
107 inline int64x64_t (unsigned long long int v) | 107 inline int64x64_t (unsigned long long int v) |
108 : _v (static_cast<double>(v)) {} | 108 : _v (static_cast<double> (v)) {} |
109 /**@}*/ | 109 /**@}*/ |
110 /** | 110 /** |
111 * Construct from explicit high and low values. | 111 * Construct from explicit high and low values. |
112 * | 112 * |
113 * \param [in] hi Integer portion. | 113 * \param [in] hi Integer portion. |
114 * \param [in] lo Fractional portion, already scaled to HP_MAX_64. | 114 * \param [in] lo Fractional portion, already scaled to HP_MAX_64. |
115 */ | 115 */ |
116 explicit inline int64x64_t (int64_t hi, uint64_t lo) | 116 explicit inline int64x64_t (int64_t hi, uint64_t lo) |
117 { | 117 { |
118 const bool negative = hi < 0; | 118 const bool negative = hi < 0; |
119 const long double fhi = negative ? static_cast<double>(-hi) : static_cast<do
uble>(hi); | 119 const long double hild = static_cast<long double> (hi);· |
| 120 const long double fhi = negative ? -hild : hild; |
120 const long double flo = lo / HP_MAX_64; | 121 const long double flo = lo / HP_MAX_64; |
121 _v = negative ? - fhi : fhi; | 122 _v = negative ? - fhi : fhi; |
122 _v += flo; | 123 _v += flo; |
123 // _v = negative ? -_v : _v; | 124 // _v = negative ? -_v : _v; |
124 } | 125 } |
125 | 126 |
126 /** | 127 /** |
127 * Copy constructor. | 128 * Copy constructor. |
128 * | 129 * |
129 * \param [in] o Value to copy. | 130 * \param [in] o Value to copy. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Add 0.5 to round, which improves the last count | 167 // Add 0.5 to round, which improves the last count |
167 // This breaks these tests: | 168 // This breaks these tests: |
168 // TestSuite devices-mesh-dot11s-regression | 169 // TestSuite devices-mesh-dot11s-regression |
169 // TestSuite devices-mesh-flame-regression | 170 // TestSuite devices-mesh-flame-regression |
170 // TestSuite routing-aodv-regression | 171 // TestSuite routing-aodv-regression |
171 // TestSuite routing-olsr-regression | 172 // TestSuite routing-olsr-regression |
172 // Setting round = 0; breaks: | 173 // Setting round = 0; breaks: |
173 // TestSuite int64x64 | 174 // TestSuite int64x64 |
174 const long double round = 0.5; | 175 const long double round = 0.5; |
175 flo = flo * HP_MAX_64 + round; | 176 flo = flo * HP_MAX_64 + round; |
176 int64_t hi = static_cast<int64_t>(fhi); | 177 int64_t hi = static_cast<int64_t> (fhi); |
177 uint64_t lo = static_cast<uint64_t>(flo); | 178 uint64_t lo = static_cast<uint64_t> (flo); |
178 if (flo >= HP_MAX_64) | 179 if (flo >= HP_MAX_64) |
179 { | 180 { |
180 // conversion to uint64 rolled over | 181 // conversion to uint64 rolled over |
181 ++hi; | 182 ++hi; |
182 } | 183 } |
183 if (negative) | 184 if (negative) |
184 { | 185 { |
185 lo = ~lo; | 186 lo = ~lo; |
186 hi = ~hi; | 187 hi = ~hi; |
187 if (++lo == 0) | 188 if (++lo == 0) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 */ | 341 */ |
341 inline int64x64_t operator ! (const int64x64_t & lhs) | 342 inline int64x64_t operator ! (const int64x64_t & lhs) |
342 { | 343 { |
343 return int64x64_t (!lhs._v); | 344 return int64x64_t (!lhs._v); |
344 } | 345 } |
345 | 346 |
346 | 347 |
347 } // namespace ns3 | 348 } // namespace ns3 |
348 | 349 |
349 #endif /* INT64X64_DOUBLE_H */ | 350 #endif /* INT64X64_DOUBLE_H */ |
LEFT | RIGHT |