19#include "ns3/core-config.h"
20#if !defined(INT64X64_DOUBLE_H) && (defined(INT64X64_USE_DOUBLE) || defined(PYTHON_SCAN))
22#define INT64X64_DOUBLE_H
45 static const uint64_t
HP_MASK_LO = 0xffffffffffffffffULL;
58#define HP_MAX_64 (std::pow(2.0L, 64))
153 const bool negative = hi < 0;
154 const long double hild =
static_cast<long double>(hi);
155 const long double fhi = negative ? -hild : hild;
157 _v = negative ? -fhi : fhi;
185 inline explicit operator bool()
const
208 const bool negative =
_v < 0;
209 const long double v = negative ? -
_v :
_v;
212 long double flo = std::modf(v, &fhi);
221 const long double round = 0.5;
223 int64_t hi =
static_cast<int64_t
>(fhi);
224 uint64_t lo =
static_cast<uint64_t
>(flo);
239 return std::make_pair(hi, lo);
270 int64_t retval =
static_cast<int64_t
>(
_v);
282 int64_t retval = std::round(
_v);
327 return lhs._v == rhs._v;
332 return lhs._v < rhs._v;
337 return lhs._v > rhs._v;
High precision numerical type, implementing Q64.64 fixed precision.
int64_t GetHigh() const
Get the integer portion.
int64x64_t(unsigned long int v)
Construct from an integral type.
int64x64_t(int v)
Construct from an integral type.
friend bool operator==(const int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
static const uint64_t HP_MASK_LO
Mask for fraction part.
impl_type
Type tag for the underlying implementation.
@ int128_impl
Native int128_t implementation.
@ ld_impl
long double implementation
@ cairo_impl
cairo wideint implementation
static int64x64_t Invert(uint64_t v)
Compute the inverse of an integer value.
friend int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
friend int64x64_t operator+(const int64x64_t &lhs)
Unary operator.
int64x64_t(long double value)
Constructor from a floating point.
int64x64_t(unsigned int v)
Construct from an integral type.
int64_t Round() const
Round to the nearest int.
void MulByInvert(const int64x64_t &o)
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division oper...
friend bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
static enum impl_type implementation
Type tag for this implementation.
friend int64x64_t operator!(const int64x64_t &lhs)
Unary operator.
int64x64_t(unsigned long long int v)
Construct from an integral type.
cairo_int128_t _v
The Q64.64 value.
friend int64x64_t & operator*=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
int64x64_t(long long int v)
Construct from an integral type.
int64x64_t(int64_t hi, uint64_t lo)
Construct from explicit high and low values.
double GetDouble() const
Get this value as a double.
friend int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
int64_t GetInt() const
Truncate to an integer.
int64x64_t & operator=(const int64x64_t &o)
Assignment.
friend bool operator>(const int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
long double _v
The Q64.64 value.
std::pair< int64_t, uint64_t > GetHighLow() const
Get the high and low portions of this value.
uint64_t GetLow() const
Get the fractional portion of this value, unscaled.
int64x64_t(double value)
Constructor from a floating point.
friend int64x64_t operator-(const int64x64_t &lhs)
Unary operator.
int64x64_t(const int64x64_t &o)
Copy constructor.
friend int64x64_t & operator/=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
int64x64_t()
Default constructor.
int64x64_t(long int v)
Construct from an integral type.
#define HP_MAX_64
Floating point value of HP_MASK_LO + 1 We really want:
Every class exported by the ns3 library is enclosed in the ns3 namespace.