A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
High Precision Q64.64

Functions and class for high precision Q64.64 fixed point arithmetic. More...

+ Collaboration diagram for High Precision Q64.64:

Files

file  cairo-wideint-private.h
 cairo_x function declarations, which provide the fallback high precision arithmetic implementation.
 
file  cairo-wideint.c
 Implementation of the cairo_x functions which implement high precision arithmetic.
 
file  int64x64-128.cc
 Implementation of the ns3::int64x64_t type using a native int128_t type.
 
file  int64x64-128.h
 Declaration of the ns3::int64x64_t type using a native int128_t type.
 
file  int64x64-cairo.cc
 Implementation of the ns3::int64x64_t type using the Cairo implementation.
 
file  int64x64-cairo.h
 Declaration of the ns3::int64x64_t type using the Cairo implementation.
 
file  int64x64-double.h
 Declaration and implementation of the ns3::int64x64_t type using the double type.
 
file  int64x64.cc
 Implementation of the streaming input and output operators for the ns3::int64x64_t type.
 
file  int64x64.h
 Declaration of the ns3::int64x64_t type and associated operators.
 

Classes

class  ns3::int64x64_t
 High precision numerical type, implementing Q64.64 fixed precision. More...
 

Macros

#define HEXHILOW(hi, lo)
 Print the high and low words of an int64x64 in hex, for debugging.
 
#define INT64X64_128_H
 Use uint128_t for int64x64_t implementation.
 

Functions

int64x64_t ns3::Abs (const int64x64_t &value)
 Absolute value.
 
int64x64_t ns3::Max (const int64x64_t &a, const int64x64_t &b)
 Maximum.
 
int64x64_t ns3::Min (const int64x64_t &a, const int64x64_t &b)
 Minimum.
 
bool ns3::operator!= (const int64x64_t &lhs, const int64x64_t &rhs)
 Inequality operator.
 
int64x64_t ns3::operator* (const int64x64_t &lhs, const int64x64_t &rhs)
 Multiplication operator.
 
int64x64_t ns3::operator+ (const int64x64_t &lhs, const int64x64_t &rhs)
 Addition operator.
 
int64x64_t ns3::operator- (const int64x64_t &lhs, const int64x64_t &rhs)
 Subtraction operator.
 
int64x64_t ns3::operator/ (const int64x64_t &lhs, const int64x64_t &rhs)
 Division operator.
 
std::ostream & ns3::operator<< (std::ostream &os, const int64x64_t &value)
 Output streamer for int64x64_t.
 
bool ns3::operator<= (const int64x64_t &lhs, const int64x64_t &rhs)
 Less or equal operator.
 
bool ns3::operator>= (const int64x64_t &lhs, const int64x64_t &rhs)
 Greater or equal operator.
 
std::istream & ns3::operator>> (std::istream &is, int64x64_t &value)
 Input streamer for int64x64_t.
 
static bool ns3::output_sign (const cairo_int128_t sa, const cairo_int128_t sb, cairo_uint128_t &ua, cairo_uint128_t &ub)
 Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.
 
static bool ns3::output_sign (const int128_t sa, const int128_t sb, uint128_t &ua, uint128_t &ub)
 Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.
 
static uint64_t ns3::ReadHiDigits (std::string str)
 Read the integer portion of a number from a string containing just the integral digits (no decimal point or fractional part).
 
static uint64_t ns3::ReadLoDigits (std::string str)
 Read the fractional part of a number from a string containing just the decimal digits of the fractional part (no integral part or decimal point).
 
typedef __uint128_t uint128_t
 Some compilers do not have this defined, so we define it.
 
typedef __int128_t int128_t
 Some compilers do not have this defined, so we define it.
 

Detailed Description

Functions and class for high precision Q64.64 fixed point arithmetic.

A Q64.64 fixed precision number consists of:

Bits Function
1 Sign bit
63 Integer portion
64 Fractional portion

The high word consists of the sign bit and integer value; the low word is the fractional part, unscaled.

All standard arithmetic operations are supported:

Category Operators
Computation +, +=, -, -=, *, *=, /, /=
Comparison ==, !=, <, <=, >, >=
Unary +, -, !

Macro Definition Documentation

◆ HEXHILOW

#define HEXHILOW (   hi,
  lo 
)
Value:
std::hex << std::setfill('0') << std::right << " (0x" << std::setw(16) << hi << " " \
<< std::setw(16) << lo << std::dec << std::setfill(' ') << std::left << ")"

Print the high and low words of an int64x64 in hex, for debugging.

Parameters
[in]hiThe high (integer) word.
[in]loThe low (fractional) work.

Definition at line 51 of file int64x64.cc.

◆ INT64X64_128_H

#define INT64X64_128_H

Use uint128_t for int64x64_t implementation.

Definition at line 26 of file int64x64-128.h.

Typedef Documentation

◆ int128_t

typedef __int128_t int128_t

Some compilers do not have this defined, so we define it.

Definition at line 38 of file int64x64-128.h.

◆ uint128_t

typedef __uint128_t uint128_t

Some compilers do not have this defined, so we define it.

Definition at line 37 of file int64x64-128.h.

Function Documentation

◆ Abs()

int64x64_t ns3::Abs ( const int64x64_t value)
inline

Absolute value.

Parameters
[in]valueThe value to operate on.
Returns
The absolute value of value.

Definition at line 215 of file int64x64.h.

Referenced by ns3::UanPhyCalcSinrFhFsk::CalcSinrDb(), ns3::int64x64::test::Int64x64ArithmeticTestCase::Check(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64InputOutputTestCase::Check(), ns3::int64x64::test::Int64x64InvertTestCase::CheckCase(), ns3::RttMeanDeviation::FloatingPointUpdate(), ns3::DelayJitterEstimation::RecordRx(), and BatteryLifetimeTest::VariableLoadTest().

+ Here is the caller graph for this function:

◆ Max()

int64x64_t ns3::Max ( const int64x64_t a,
const int64x64_t b 
)
inline

Maximum.

Parameters
[in]aThe first value.
[in]bThe second value.
Returns
The larger of the arguments.

Definition at line 243 of file int64x64.h.

◆ Min()

int64x64_t ns3::Min ( const int64x64_t a,
const int64x64_t b 
)
inline

Minimum.

Parameters
[in]aThe first value.
[in]bThe second value.
Returns
The smaller of the arguments.

Definition at line 229 of file int64x64.h.

Referenced by ns3::RemoteChannelBundle::AddChannel().

+ Here is the caller graph for this function:

◆ operator!=()

bool ns3::operator!= ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Inequality operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 148 of file int64x64.h.

◆ operator*()

int64x64_t ns3::operator* ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Multiplication operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 118 of file int64x64.h.

◆ operator+()

int64x64_t ns3::operator+ ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Addition operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 88 of file int64x64.h.

◆ operator-()

int64x64_t ns3::operator- ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Subtraction operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 103 of file int64x64.h.

◆ operator/()

int64x64_t ns3::operator/ ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Division operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 133 of file int64x64.h.

◆ operator<<()

std::ostream & ns3::operator<< ( std::ostream &  os,
const int64x64_t value 
)

Output streamer for int64x64_t.

Internal:
This algorithm is exact to the precision requested, up to the full 64 decimal digits required to exactly represent a 64-bit fraction.

Proper rounding turns out to be surprisingly hard. In y.xxxx5|6, where the | marks follows the last output digit, rounding the 5|6 to 6| is straightforward. However, rounding y.xxx99|6 should result in y.xx100|. Notice the effect of rounding percolates to higher digits. We accumulate the output digits in a string, then carry out the rounding in the string directly.

Values are printed with the following format flags (independent of the stream flags):

  • showpos
  • left

The stream width is ignored. If floatfield is set, precision decimal places are printed. If floatfield is not set, all digits of the fractional part are printed, up to the representation limit of 20 digits; trailing zeros are omitted.

Parameters
[in,out]osThe output stream.
[in]valueThe numerical value to print.
Returns
The stream.

Definition at line 68 of file int64x64.cc.

References ns3::int64x64_t::GetHigh(), ns3::int64x64_t::GetLow(), HEXHILOW, NS_ASSERT_MSG, and NS_LOG_LOGIC.

+ Here is the call graph for this function:

◆ operator<=()

bool ns3::operator<= ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Less or equal operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 160 of file int64x64.h.

◆ operator>=()

bool ns3::operator>= ( const int64x64_t lhs,
const int64x64_t rhs 
)
inline

Greater or equal operator.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 174 of file int64x64.h.

◆ operator>>()

std::istream & ns3::operator>> ( std::istream &  is,
int64x64_t value 
)

Input streamer for int64x64_t.

Parameters
[in,out]isThe input stream.
[out]valueThe numerical value to set.
Returns
The stream.

Definition at line 214 of file int64x64.cc.

References ns3::ReadHiDigits(), and ns3::ReadLoDigits().

+ Here is the call graph for this function:

◆ output_sign() [1/2]

static bool ns3::output_sign ( const cairo_int128_t  sa,
const cairo_int128_t  sb,
cairo_uint128_t &  ua,
cairo_uint128_t &  ub 
)
inlinestatic

Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.

Parameters
[in]saThe signed value of the first operand.
[in]sbThe signed value of the second operand.
[out]uaThe unsigned magnitude of the first operand.
[out]ubThe unsigned magnitude of the second operand.
Returns
True if the result will be negative.

Definition at line 61 of file int64x64-cairo.cc.

References _cairo_int128_negative, _cairo_int128_to_uint128, and _cairo_uint128_negate().

+ Here is the call graph for this function:

◆ output_sign() [2/2]

static bool ns3::output_sign ( const int128_t  sa,
const int128_t  sb,
uint128_t ua,
uint128_t ub 
)
inlinestatic

Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.

Parameters
[in]saThe signed value of the first operand.
[in]sbThe signed value of the second operand.
[out]uaThe unsigned magnitude of the first operand.
[out]ubThe unsigned magnitude of the second operand.
Returns
true if the result will be negative.

Definition at line 51 of file int64x64-128.cc.

Referenced by ns3::int64x64_t::Div(), and ns3::int64x64_t::Mul().

+ Here is the caller graph for this function:

◆ ReadHiDigits()

static uint64_t ns3::ReadHiDigits ( std::string  str)
static

Read the integer portion of a number from a string containing just the integral digits (no decimal point or fractional part).

Parameters
[in]strThe string representation of the integral part of a number, with no fractional part or decimal point.
Returns
The integer.

Definition at line 172 of file int64x64.cc.

Referenced by ns3::operator>>().

+ Here is the caller graph for this function:

◆ ReadLoDigits()

static uint64_t ns3::ReadLoDigits ( std::string  str)
static

Read the fractional part of a number from a string containing just the decimal digits of the fractional part (no integral part or decimal point).

Parameters
[in]strThe string representation of the fractional part of a number, without integral part or decimal point.
Returns
The decimal portion of the input number.

Definition at line 196 of file int64x64.cc.

References ns3::int64x64_t::GetLow(), and NS_ASSERT_MSG.

Referenced by ns3::operator>>().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: