High precision numerical type, implementing Q64.64 fixed precision. More...
#include "int64x64-cairo.h"
Public Types | |
enum | impl_type { int128_impl , cairo_impl , ld_impl , int128_impl , cairo_impl , ld_impl } |
Type tag for the underlying implementation. More... | |
enum | impl_type { int128_impl , cairo_impl , ld_impl , int128_impl , cairo_impl , ld_impl } |
Type tag for the underlying implementation. More... | |
Public Member Functions | |
int64x64_t () | |
Default constructor. More... | |
int64x64_t () | |
Default constructor. More... | |
int64x64_t (const int64_t hi, const uint64_t lo) | |
Construct from explicit high and low values. More... | |
int64x64_t (const int64x64_t &o) | |
Copy constructor. More... | |
int64x64_t (const int64x64_t &o) | |
Copy constructor. More... | |
int64x64_t (int64_t hi, uint64_t lo) | |
Construct from explicit high and low values. More... | |
double | GetDouble () const |
Get this value as a double. More... | |
double | GetDouble () const |
Get this value as a double. More... | |
int64_t | GetHigh () const |
Get the integer portion. More... | |
int64_t | GetHigh () const |
Get the integer portion. More... | |
int64_t | GetInt () const |
Truncate to an integer. More... | |
int64_t | GetInt () const |
Truncate to an integer. More... | |
uint64_t | GetLow () const |
Get the fractional portion of this value, unscaled. More... | |
uint64_t | GetLow () const |
Get the fractional portion of this value, unscaled. More... | |
void | MulByInvert (const int64x64_t &o) |
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division operation. More... | |
void | MulByInvert (const int64x64_t &o) |
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division operation. More... | |
operator bool () const | |
Explicit bool conversion. More... | |
operator bool () const | |
Explicit bool conversion. More... | |
int64x64_t & | operator= (const int64x64_t &o) |
Assignment. More... | |
int64x64_t & | operator= (const int64x64_t &o) |
Assignment. More... | |
int64_t | Round () const |
Round to the nearest int. More... | |
int64_t | Round () const |
Round to the nearest int. More... | |
Construct from a floating point value. | |
int64x64_t (const double value) | |
Constructor from a floating point. More... | |
int64x64_t (const long double value) | |
Constructor from a floating point. More... | |
int64x64_t (double value) | |
Constructor from a floating point. More... | |
int64x64_t (long double value) | |
Constructor from a floating point. More... | |
Construct from an integral type. | |
int64x64_t (const int v) | |
Construct from an integral type. More... | |
int64x64_t (const long int v) | |
Construct from an integral type. More... | |
int64x64_t (const long long int v) | |
Construct from an integral type. More... | |
int64x64_t (const unsigned int v) | |
Construct from an integral type. More... | |
int64x64_t (const unsigned long int v) | |
Construct from an integral type. More... | |
int64x64_t (const unsigned long long int v) | |
Construct from an integral type. More... | |
int64x64_t (int v) | |
Construct from an integral type. More... | |
int64x64_t (long int v) | |
Construct from an integral type. More... | |
int64x64_t (long long int v) | |
Construct from an integral type. More... | |
int64x64_t (unsigned int v) | |
Construct from an integral type. More... | |
int64x64_t (unsigned long int v) | |
Construct from an integral type. More... | |
int64x64_t (unsigned long long int v) | |
Construct from an integral type. More... | |
Static Public Member Functions | |
static int64x64_t | Invert (const uint64_t v) |
Compute the inverse of an integer value. More... | |
static int64x64_t | Invert (uint64_t v) |
Compute the inverse of an integer value. More... | |
Static Public Attributes | |
static enum impl_type | implementation = cairo_impl |
Type tag for this implementation. More... | |
Private Member Functions | |
void | Div (const int64x64_t &o) |
Implement /= . More... | |
std::pair< int64_t, uint64_t > | GetHighLow () const |
Get the high and low portions of this value. More... | |
void | Mul (const int64x64_t &o) |
Implement *= . More... | |
Static Private Member Functions | |
static cairo_uint128_t | Udiv (const cairo_uint128_t a, const cairo_uint128_t b) |
Unsigned division of Q64.64 values. More... | |
static cairo_uint128_t | Umul (const cairo_uint128_t a, const cairo_uint128_t b) |
Unsigned multiplication of Q64.64 values. More... | |
static cairo_uint128_t | UmulByInvert (const cairo_uint128_t a, const cairo_uint128_t b) |
Unsigned multiplication of Q64.64 and Q0.128 values. More... | |
Private Attributes | |
cairo_int128_t | _v |
The Q64.64 value. More... | |
long double | _v |
The Q64.64 value. More... | |
Static Private Attributes | |
static const uint64_t | HP_MASK_LO = 0xffffffffffffffffULL |
Mask for fraction part. More... | |
static const uint64_t | HPCAIRO_MASK_HI_BIT = (((uint64_t)1) << 63) |
High bit of fractional part. More... | |
Friends | |
Arithmetic Operators | |
Arithmetic operators for int64x64_t. | |
bool | operator== (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
bool | operator< (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
bool | operator> (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator+= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator-= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator*= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator/= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
bool | operator== (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
bool | operator< (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
bool | operator> (const int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator+= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator-= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator*= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
int64x64_t & | operator/= (int64x64_t &lhs, const int64x64_t &rhs) |
Arithmetic operator. More... | |
Unary Operators | |
Unary operators for int64x64_t. | |
int64x64_t | operator+ (const int64x64_t &lhs) |
Unary operator. More... | |
int64x64_t | operator- (const int64x64_t &lhs) |
Unary operator. More... | |
int64x64_t | operator! (const int64x64_t &lhs) |
Unary operator. More... | |
int64x64_t | operator+ (const int64x64_t &lhs) |
Unary operator. More... | |
int64x64_t | operator- (const int64x64_t &lhs) |
Unary operator. More... | |
int64x64_t | operator! (const int64x64_t &lhs) |
Unary operator. More... | |
High precision numerical type, implementing Q64.64 fixed precision.
Definition at line 41 of file int64x64-cairo.h.
Type tag for the underlying implementation.
A few testcases are sensitive to implementation, specifically the double implementation. To handle this, we expose the underlying implementation type here.
Definition at line 69 of file int64x64-cairo.h.
Type tag for the underlying implementation.
A few testcases are are sensitive to implementation, specifically the double implementation. To handle this, we expose the underlying implementation type here.
Definition at line 68 of file int64x64-double.h.
|
inline |
Default constructor.
Definition at line 80 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Constructor from a floating point.
[in] | value | Floating value to represent. |
Definition at line 95 of file int64x64-cairo.h.
References _v.
|
inline |
Constructor from a floating point.
[in] | value | Floating value to represent. |
Definition at line 101 of file int64x64-cairo.h.
References _cairo_int128_negate, _v, cairo_int128_t::hi, HP_MAX_64, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 141 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 147 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 153 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 159 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 165 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 171 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inlineexplicit |
Construct from explicit high and low values.
[in] | hi | Integer portion. |
[in] | lo | Fractional portion, already scaled to HP_MAX_64. |
Definition at line 184 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inline |
|
inline |
Default constructor.
Definition at line 79 of file int64x64-double.h.
|
inline |
Constructor from a floating point.
[in] | value | Floating value to represent. |
Definition at line 93 of file int64x64-double.h.
|
inline |
Constructor from a floating point.
[in] | value | Floating value to represent. |
Definition at line 98 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 114 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 119 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 124 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 129 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 134 of file int64x64-double.h.
|
inline |
Construct from an integral type.
[in] | v | Integer value to represent |
Definition at line 139 of file int64x64-double.h.
|
inlineexplicit |
Construct from explicit high and low values.
[in] | hi | Integer portion. |
[in] | lo | Fractional portion, already scaled to HP_MAX_64. |
Definition at line 151 of file int64x64-double.h.
|
inline |
|
private |
Implement /=
.
[in] | o | The divisor. |
Definition at line 114 of file int64x64-128.cc.
References _v, ns3::output_sign(), and Udiv().
|
inline |
Get this value as a double.
Definition at line 223 of file int64x64-cairo.h.
References _cairo_int128_negate, _cairo_int128_negative, _v, and HP_MAX_64.
Referenced by ns3::int64x64::test::Int64x64Bug455TestCase::DoRun(), ns3::int64x64::test::Int64x64Bug863TestCase::DoRun(), ns3::ShowProgress::GiveFeedback(), and ns3::Time::ToDouble().
|
inline |
Get this value as a double.
Definition at line 195 of file int64x64-double.h.
References _v.
|
inline |
Get the integer portion.
Definition at line 240 of file int64x64-cairo.h.
References _v, and cairo_int128_t::hi.
Referenced by ns3::OnOffApplication::CancelEvents(), anonymous_namespace{sample-show-progress.cc}::Hold::Event(), Invert(), and ns3::operator<<().
|
inline |
Get the integer portion.
Definition at line 248 of file int64x64-double.h.
References GetHighLow().
|
inlineprivate |
|
inline |
Truncate to an integer.
Truncation is always toward zero,
Definition at line 260 of file int64x64-cairo.h.
References _cairo_int128_negate, _cairo_int128_negative, and _v.
|
inline |
Truncate to an integer.
Truncation is always toward zero,
Definition at line 268 of file int64x64-double.h.
References _v.
|
inline |
Get the fractional portion of this value, unscaled.
Definition at line 250 of file int64x64-cairo.h.
References _v, and cairo_int128_t::lo.
Referenced by ns3::operator<<(), and ns3::ReadLoDigits().
|
inline |
Get the fractional portion of this value, unscaled.
Definition at line 258 of file int64x64-double.h.
References GetHighLow().
|
static |
Compute the inverse of an integer value.
Ordinary division by an integer would be limited to 64 bits of precision. Instead, we multiply by the 128-bit inverse of the divisor. This function computes the inverse to 128-bit precision. MulByInvert() then completes the division.
(Really this should be a separate type representing Q0.128.)
[in] | v | The value to compute the inverse of. |
Definition at line 220 of file int64x64-128.cc.
References _v, GetHigh(), MulByInvert(), NS_ASSERT, and Udiv().
Referenced by ns3::int64x64::test::Int64x64InvertTestCase::Check(), and ns3::Time::SetResolution().
|
inlinestatic |
Compute the inverse of an integer value.
[in] | v | The value to compute the inverse of. |
Definition at line 306 of file int64x64-double.h.
|
private |
Implement *=
.
[in] | o | The other factor. |
Definition at line 61 of file int64x64-128.cc.
References _v, ns3::output_sign(), and Umul().
void ns3::int64x64_t::MulByInvert | ( | const int64x64_t & | o | ) |
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division operation.
[in] | o | The inverse operand. |
Definition at line 189 of file int64x64-128.cc.
References _v, and UmulByInvert().
Referenced by ns3::int64x64::test::Int64x64InvertTestCase::Check(), ns3::Time::From(), Invert(), and ns3::Time::To().
|
inline |
Multiply this value by a Q0.128 value, presumably representing an inverse, completing a division operation.
[in] | o | The inverse operand. |
Definition at line 295 of file int64x64-double.h.
References _v.
|
inlineexplicit |
Explicit bool conversion.
Definition at line 213 of file int64x64-cairo.h.
References _v, cairo_int128_t::hi, and cairo_int128_t::lo.
|
inlineexplicit |
|
inline |
Assignment.
[in] | o | Value to assign to this int64x64_t. |
Definition at line 206 of file int64x64-cairo.h.
References _v.
|
inline |
Assignment.
[in] | o | Value to assign to this int64x64_t. |
Definition at line 178 of file int64x64-double.h.
References _v.
|
inline |
Round to the nearest int.
Similar to std::round this rounds halfway cases away from zero, regardless of the current (floating) rounding mode.
Definition at line 275 of file int64x64-cairo.h.
References _cairo_int128_negate, _cairo_int128_negative, _cairo_uint128_add(), and _v.
|
inline |
Round to the nearest int.
Similar to std::round this rounds halfway cases away from zero, regardless of the current (floating) rounding mode.
Definition at line 280 of file int64x64-double.h.
References _v.
|
staticprivate |
Unsigned division of Q64.64 values.
[in] | a | Numerator. |
[in] | b | Denominator. |
a / b
Definition at line 124 of file int64x64-128.cc.
References NS_ASSERT_MSG.
Referenced by Div(), and Invert().
|
staticprivate |
Unsigned multiplication of Q64.64 values.
Mathematically this should produce a Q128.128 value; we keep the central 128 bits, representing the Q64.64 result. We assert on integer overflow beyond the 64-bit integer portion.
[in] | a | First factor. |
[in] | b | Second factor. |
It might be tempting to just use a *
b and be done with it, but it's not that simple. With a and b as 128-bit integers, a *
b mathematically produces a 256-bit result, which the computer truncates to the lowest 128 bits. In our case, where a and b are interpreted as Q64.64 fixed point numbers, the multiplication mathematically produces a Q128.128 fixed point number. We want the middle 128 bits from the result, truncating both the high and low 64 bits. To achieve this, we carry out the multiplication explicitly with 64-bit operands and 128-bit intermediate results.
Definition at line 71 of file int64x64-128.cc.
References HP_MASK_LO, and NS_ABORT_MSG_IF.
Referenced by Mul().
|
staticprivate |
Unsigned multiplication of Q64.64 and Q0.128 values.
[in] | a | The numerator, a Q64.64 value. |
[in] | b | The inverse of the denominator, a Q0.128 value |
a * b
, representing the ration a / b^-1
Definition at line 199 of file int64x64-128.cc.
References HP_MASK_LO.
Referenced by MulByInvert().
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 387 of file int64x64-cairo.h.
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 386 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 351 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 352 of file int64x64-double.h.
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 375 of file int64x64-cairo.h.
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 376 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 339 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 340 of file int64x64-double.h.
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 380 of file int64x64-cairo.h.
|
friend |
Unary operator.
[in] | lhs | Left hand argument |
Definition at line 381 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 345 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 346 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 357 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 358 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 329 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 330 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 324 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 325 of file int64x64-double.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 334 of file int64x64-cairo.h.
|
friend |
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 335 of file int64x64-double.h.
|
private |
The Q64.64 value.
Definition at line 450 of file int64x64-cairo.h.
Referenced by int64x64_t(), Div(), GetDouble(), GetHigh(), GetHighLow(), GetInt(), GetLow(), Invert(), Mul(), MulByInvert(), operator bool(), operator=(), and Round().
|
private |
The Q64.64 value.
Definition at line 393 of file int64x64-double.h.
|
staticprivate |
Mask for fraction part.
Definition at line 46 of file int64x64-cairo.h.
Referenced by Umul(), and UmulByInvert().
|
staticprivate |
High bit of fractional part.
Definition at line 44 of file int64x64-cairo.h.
|
static |
Type tag for this implementation.
Definition at line 46 of file int64x64-cairo.h.
Referenced by ns3::int64x64::test::Int64x64InvertTestCase::Check(), ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64HiLoTestCase::DoRun(), ns3::int64x64::test::Int64x64InputTestCase::DoRun(), ns3::int64x64::test::Int64x64InputOutputTestCase::DoRun(), ns3::int64x64::test::Int64x64Bug1786TestCase::DoRun(), and ns3::int64x64::test::Int64x64ImplTestCase::DoRun().