8#ifndef INT64X64_CAIRO_H
9#define INT64X64_CAIRO_H
11#include "ns3/core-config.h"
13#if defined(INT64X64_USE_CAIRO) && !defined(PYTHON_SCAN)
38 static const uint64_t
HP_MASK_LO = 0xffffffffffffffffULL;
42 static constexpr long double HP_MAX_64 = (
static_cast<uint64_t
>(1) << 63) * 2.0L;
85 const bool negative = value < 0;
86 const long double v = negative ? -value : value;
89 long double flo = std::modf(v, &fhi);
98 const long double round = 0.5;
101 const cairo_uint64_t lo = (cairo_uint64_t)flo;
166 explicit inline int64x64_t(
const int64_t hi,
const uint64_t lo)
195 inline explicit operator bool()
const
197 return (
_v.hi != 0 ||
_v.lo != 0);
209 const long double fhi =
static_cast<long double>(value.hi);
210 const long double flo = value.lo /
HP_MAX_64;
211 long double retval = fhi;
213 retval = negative ? -retval : retval;
214 return static_cast<double>(retval);
224 return (int64_t)
_v.hi;
246 int64_t retval = value.hi;
247 retval = negative ? -retval : retval;
261 cairo_uint128_t half{1ULL << 63, 0};
263 int64_t retval = value.hi;
264 retval = negative ? -retval : retval;
412 static cairo_uint128_t
Umul(
const cairo_uint128_t a,
const cairo_uint128_t b);
420 static cairo_uint128_t
Udiv(
const cairo_uint128_t a,
const cairo_uint128_t b);
430 static cairo_uint128_t
UmulByInvert(
const cairo_uint128_t a,
const cairo_uint128_t b);
cairo_x function declarations, which provide the fallback high precision arithmetic implementation.
int cairo_I _cairo_int128_lt(cairo_int128_t a, cairo_int128_t b)
cairo_uint128_t cairo_I _cairo_uint128_add(cairo_uint128_t a, cairo_uint128_t b)
#define _cairo_int128_add(a, b)
#define _cairo_int128_eq(a, b)
#define _cairo_int128_negative(a)
#define _cairo_int128_gt(a, b)
#define _cairo_int128_sub(a, b)
#define _cairo_int128_negate(a)
High precision numerical type, implementing Q64.64 fixed precision.
int64_t GetHigh() const
Get the integer portion.
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.
friend int64x64_t & operator-=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
friend int64x64_t operator+(const int64x64_t &lhs)
Unary operator.
static constexpr long double HP_MAX_64
Floating point value of HP_MASK_LO + 1.
int64_t Round() const
Round to the nearest int.
void Mul(const int64x64_t &o)
Implement *=.
static uint128_t Udiv(const uint128_t a, const uint128_t b)
Unsigned division of Q64.64 values.
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.
int64x64_t(const long double value)
Constructor from a floating point.
static uint128_t UmulByInvert(const uint128_t a, const uint128_t b)
Unsigned multiplication of Q64.64 and Q0.128 values.
static enum impl_type implementation
Type tag for this implementation.
friend int64x64_t operator!(const int64x64_t &lhs)
Unary operator.
int128_t _v
The Q64.64 value.
cairo_int128_t _v
The Q64.64 value.
friend int64x64_t & operator*=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
int64x64_t(const int64_t hi, const uint64_t lo)
Construct from explicit high and low values.
void Div(const int64x64_t &o)
Implement /=.
static const uint64_t HPCAIRO_MASK_HI_BIT
High bit of fractional part.
int64x64_t(const unsigned long long int v)
Construct from an integral type.
int64x64_t(const unsigned int v)
Construct from an integral type.
int64x64_t(const long int v)
Construct from an integral type.
int64x64_t(const long long int v)
Construct from an integral type.
double GetDouble() const
Get this value as a double.
friend int64x64_t & operator+=(int64x64_t &lhs, const int64x64_t &rhs)
Arithmetic operator.
int64x64_t(const unsigned long int v)
Construct from an integral type.
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.
int64x64_t(const int v)
Construct from an integral type.
uint64_t GetLow() const
Get the fractional portion of this value, unscaled.
friend int64x64_t operator-(const int64x64_t &lhs)
Unary operator.
int64x64_t(const double value)
Constructor from a floating point.
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.
static uint128_t Umul(const uint128_t a, const uint128_t b)
Unsigned multiplication of Q64.64 values.
static int64x64_t Invert(const uint64_t v)
Compute the inverse of an integer value.
Every class exported by the ns3 library is enclosed in the ns3 namespace.