A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
int64x64.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
*/
18
19
#ifndef INT64X64_H
20
#define INT64X64_H
21
22
#include "ns3/core-config.h"
23
24
// Order is important here, as it determines which implementation
25
// will generate doxygen API docs. This order mimics the
26
// selection logic in CMakeLists.txt, so we generate docs from the
27
// implementation actually chosen by the configuration.
28
#if defined(INT64X64_USE_128) && !defined(PYTHON_SCAN)
29
#include "
int64x64-128.h
"
30
#elif defined(INT64X64_USE_CAIRO) && !defined(PYTHON_SCAN)
31
#include "
int64x64-cairo.h
"
32
#elif defined(INT64X64_USE_DOUBLE) || defined(PYTHON_SCAN)
33
#include "
int64x64-double.h
"
34
#endif
35
36
#include <iostream>
37
38
/**
39
* \file
40
* \ingroup highprec
41
* Declaration of the ns3::int64x64_t type and associated operators.
42
*/
43
44
namespace
ns3
45
{
46
47
/**
48
* \ingroup core
49
* \defgroup highprec High Precision Q64.64
50
*
51
* Functions and class for high precision Q64.64 fixed point arithmetic.
52
*
53
* A Q64.64 fixed precision number consists of:
54
*
55
* Bits | Function
56
* ---- | --------
57
* 1 | Sign bit
58
* 63 | Integer portion
59
* 64 | Fractional portion
60
*
61
* The `high` word consists of the sign bit and integer value;
62
* the `low` word is the fractional part, unscaled.
63
*
64
* All standard arithmetic operations are supported:
65
*
66
* Category | Operators
67
* ----------- | ---------
68
* Computation | `+`, `+=`, `-`, `-=`, `*`, `*=`, `/`, `/=`
69
* Comparison | `==`, `!=`, `<`, `<=`, `>`, `>=`
70
* Unary | `+`, `-`, `!`
71
*/
72
73
/**
74
* \ingroup highprec
75
* \class int64x64_t
76
*
77
* High precision numerical type, implementing Q64.64 fixed precision.
78
*/
79
80
/**
81
* \ingroup highprec
82
* Addition operator.
83
* \param [in] lhs Left hand argument
84
* \param [in] rhs Right hand argument
85
* \return The result of the operator.
86
*/
87
inline
int64x64_t
88
operator+
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
89
{
90
int64x64_t
tmp = lhs;
91
tmp += rhs;
92
return
tmp;
93
}
94
95
/**
96
* \ingroup highprec
97
* Subtraction operator.
98
* \param [in] lhs Left hand argument
99
* \param [in] rhs Right hand argument
100
* \return The result of the operator.
101
*/
102
inline
int64x64_t
103
operator-
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
104
{
105
int64x64_t
tmp = lhs;
106
tmp -= rhs;
107
return
tmp;
108
}
109
110
/**
111
* \ingroup highprec
112
* Multiplication operator.
113
* \param [in] lhs Left hand argument
114
* \param [in] rhs Right hand argument
115
* \return The result of the operator.
116
*/
117
inline
int64x64_t
118
operator*
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
119
{
120
int64x64_t
tmp = lhs;
121
tmp *= rhs;
122
return
tmp;
123
}
124
125
/**
126
* \ingroup highprec
127
* Division operator.
128
* \param [in] lhs Left hand argument
129
* \param [in] rhs Right hand argument
130
* \return The result of the operator.
131
*/
132
inline
int64x64_t
133
operator/
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
134
{
135
int64x64_t
tmp = lhs;
136
tmp /= rhs;
137
return
tmp;
138
}
139
140
/**
141
* \ingroup highprec
142
* Inequality operator
143
* \param [in] lhs Left hand argument
144
* \param [in] rhs Right hand argument
145
* \return The result of the operator.
146
*/
147
inline
bool
148
operator!=
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
149
{
150
return
!(lhs == rhs);
151
}
152
153
/**
154
* \ingroup highprec
155
* Less or equal operator.
156
* \param [in] lhs Left hand argument
157
* \param [in] rhs Right hand argument
158
* \return The result of the operator.
159
*/
160
inline
bool
161
operator<=
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
162
{
163
return
!(lhs > rhs);
164
}
165
166
/**
167
* \ingroup highprec
168
* Greater or equal operator.
169
* \param [in] lhs Left hand argument
170
* \param [in] rhs Right hand argument
171
* \return The result of the operator.
172
*/
173
inline
bool
174
operator>=
(
const
int64x64_t
& lhs,
const
int64x64_t
& rhs)
175
{
176
return
!(lhs < rhs);
177
}
178
179
/**
180
* \ingroup highprec
181
* Output streamer for int64x64_t.
182
*
183
* Values are printed with the following format flags
184
* (independent of the stream flags):
185
* - `showpos`
186
* - `left`
187
*
188
* The stream `width` is ignored. If `floatfield` is set,
189
* `precision` decimal places are printed. If `floatfield` is not set,
190
* all digits of the fractional part are printed, up to the
191
* representation limit of 20 digits; trailing zeros are omitted.
192
*
193
* \param [in,out] os The output stream.
194
* \param [in] value The numerical value to print.
195
* \returns The stream.
196
*/
197
std::ostream&
operator<<
(std::ostream& os,
const
int64x64_t& value);
198
/**
199
* \ingroup highprec
200
* Input streamer for int64x64_t.
201
*
202
* \param [in,out] is The input stream.
203
* \param [out] value The numerical value to set.
204
* \returns The stream.
205
*/
206
std::istream&
operator>>
(std::istream& is, int64x64_t& value);
207
208
/**
209
* \ingroup highprec
210
* Absolute value.
211
* \param [in] value The value to operate on.
212
* \return The absolute value of \pname{value}.
213
*/
214
inline
int64x64_t
215
Abs
(
const
int64x64_t
& value)
216
{
217
return
(value < 0) ? -value : value;
218
}
219
220
/**
221
* \ingroup highprec
222
* Minimum.
223
*
224
* \param [in] a The first value.
225
* \param [in] b The second value.
226
* \return The smaller of the arguments.
227
*/
228
inline
int64x64_t
229
Min
(
const
int64x64_t
& a,
const
int64x64_t
& b)
230
{
231
return
(a < b) ? a : b;
232
}
233
234
/**
235
* \ingroup highprec
236
* Maximum.
237
*
238
* \param [in] a The first value.
239
* \param [in] b The second value.
240
* \return The larger of the arguments.
241
*/
242
inline
int64x64_t
243
Max
(
const
int64x64_t
& a,
const
int64x64_t
& b)
244
{
245
return
(a > b) ? a : b;
246
}
247
248
}
// namespace ns3
249
250
#endif
/* INT64X64_H */
Max
#define Max(a, b)
Definition:
aarf-wifi-manager.cc:26
Min
#define Min(a, b)
Definition:
aarf-wifi-manager.cc:25
ns3::int64x64_t
High precision numerical type, implementing Q64.64 fixed precision.
Definition:
int64x64-128.h:56
ns3::operator/
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition:
int64x64.h:133
ns3::operator>=
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition:
int64x64.h:174
ns3::operator<=
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition:
int64x64.h:161
ns3::operator-
int64x64_t operator-(const int64x64_t &lhs, const int64x64_t &rhs)
Subtraction operator.
Definition:
int64x64.h:103
ns3::operator+
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition:
int64x64.h:88
ns3::Abs
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition:
int64x64.h:215
ns3::operator*
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition:
int64x64.h:118
int64x64-128.h
Declaration of the ns3::int64x64_t type using a native int128_t type.
int64x64-cairo.h
Declaration of the ns3::int64x64_t type using the Cairo implementation.
int64x64-double.h
Declaration and implementation of the ns3::int64x64_t type using the double type.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator!=
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition:
callback.h:674
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition:
angles.cc:159
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
Definition:
angles.cc:183
src
core
model
int64x64.h
Generated on Tue May 28 2024 23:34:32 for ns-3 by
1.9.6