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