Functions and class for high precision Q64.64 fixed point arithmetic. More...
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. More... | |
Functions | |
int64x64_t | ns3::Abs (const int64x64_t &value) |
Absolute value. More... | |
int64x64_t | ns3::Max (const int64x64_t &a, const int64x64_t &b) |
Maximum. More... | |
int64x64_t | ns3::Min (const int64x64_t &a, const int64x64_t &b) |
Minimum. More... | |
int64x64_t | ns3::operator! (const int64x64_t &lhs) |
Logical not operator. More... | |
bool | ns3::operator!= (const int64x64_t &lhs, const int64x64_t &rhs) |
Inequality operator. More... | |
int64x64_t | ns3::operator* (const int64x64_t &lhs, const int64x64_t &rhs) |
Multiplication operator. More... | |
int64x64_t & | ns3::operator*= (int64x64_t &lhs, const int64x64_t &rhs) |
Compound multiplication operator. More... | |
int64x64_t | ns3::operator+ (const int64x64_t &lhs) |
Unary plus operator. More... | |
int64x64_t | ns3::operator+ (const int64x64_t &lhs, const int64x64_t &rhs) |
Addition operator. More... | |
int64x64_t & | ns3::operator+= (int64x64_t &lhs, const int64x64_t &rhs) |
Compound addition operator. More... | |
int64x64_t | ns3::operator- (const int64x64_t &lhs) |
Unary negation operator (change sign operator). More... | |
int64x64_t | ns3::operator- (const int64x64_t &lhs, const int64x64_t &rhs) |
Subtraction operator. More... | |
int64x64_t & | ns3::operator-= (int64x64_t &lhs, const int64x64_t &rhs) |
Compound subtraction operator. More... | |
int64x64_t | ns3::operator/ (const int64x64_t &lhs, const int64x64_t &rhs) |
Division operator. More... | |
int64x64_t & | ns3::operator/= (int64x64_t &lhs, const int64x64_t &rhs) |
Compound division operator. More... | |
bool | ns3::operator< (const int64x64_t &lhs, const int64x64_t &rhs) |
Less than operator. More... | |
std::ostream & | ns3::operator<< (std::ostream &os, const int64x64_t &value) |
Output streamer for int64x64_t. More... | |
bool | ns3::operator<= (const int64x64_t &lhs, const int64x64_t &rhs) |
Less or equal operator. More... | |
bool | ns3::operator== (const int64x64_t &lhs, const int64x64_t &rhs) |
Equality operator. More... | |
bool | ns3::operator> (const int64x64_t &lhs, const int64x64_t &rhs) |
Greater operator. More... | |
bool | ns3::operator>= (const int64x64_t &lhs, const int64x64_t &rhs) |
Greater or equal operator. More... | |
std::istream & | ns3::operator>> (std::istream &is, int64x64_t &value) |
Input streamer for int64x64_t. More... | |
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. More... | |
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. More... | |
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). More... | |
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). More... | |
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 | + , - , ! |
#define HEXHILOW | ( | hi, | |
lo | |||
) |
Print the high and low words of an int64x64 in hex, for debugging.
[in] | hi | The high (integer) word. |
[in] | lo | The low (fractional) work. |
Definition at line 49 of file int64x64.cc.
|
inline |
Absolute value.
[in] | value | The value to operate on. |
Definition at line 205 of file int64x64.h.
Referenced by ns3::UanPhyCalcSinrFhFsk::CalcSinrDb(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64InputOutputTestCase::Check(), ns3::int64x64::test::Int64x64InvertTestCase::CheckCase(), ns3::RttMeanDeviation::FloatingPointUpdate(), ns3::DelayJitterEstimation::RecordRx(), ns3::WifiPhyStateHelper::SwitchFromRxEndError(), ns3::WifiPhyStateHelper::SwitchFromRxEndOk(), and BatteryLifetimeTest::VariableLoadTest().
|
inline |
Maximum.
[in] | a | The first value. |
[in] | b | The second value. |
Definition at line 230 of file int64x64.h.
Referenced by ns3::InterferenceHelper::CalculatePhyHeaderSectionPsr(), ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64InputTestCase::Check(), ns3::WifiMacQueueItem::DoAggregate(), ns3::TcpSocketBase::DoPeerClose(), ns3::AarfWifiManager::DoReportDataFailed(), ns3::AarfcdWifiManager::DoReportDataFailed(), ns3::TcpSocketBase::EstimateRtt(), ns3::WifiPhyStateHelper::GetDelayUntilIdle(), ns3::TcpSocketBase::LastAckTimeout(), ns3::WifiPhyStateHelper::LogPreviousIdleAndCcaBusyStates(), ns3::TcpSocketBase::NewAck(), ns3::MinstrelHtWifiManager::PrintTable(), ns3::TcpSocketBase::SendEmptyPacket(), ns3::TcpSocketSmallAcks::SendEmptyPacket(), ns3::WifiPhyStateHelper::SwitchToChannelSwitching(), ns3::WifiPhyStateHelper::SwitchToOff(), ns3::WifiPhyStateHelper::SwitchToRx(), ns3::WifiPhyStateHelper::SwitchToSleep(), ns3::WifiPhyStateHelper::SwitchToTx(), ns3::RrMultiUserScheduler::TrySendingBasicTf(), and ns3::RrMultiUserScheduler::TrySendingBsrpTf().
|
inline |
Minimum.
[in] | a | The first value. |
[in] | b | The second value. |
Definition at line 218 of file int64x64.h.
Referenced by ns3::RemoteChannelBundle::AddChannel(), ns3::DistributedSimulatorImpl::BoundLookAhead(), ns3::NullMessageSimulatorImpl::CalculateGuaranteeTime(), ns3::InterferenceHelper::CalculatePayloadPer(), ns3::InterferenceHelper::CalculatePhyHeaderSectionPsr(), ns3::MinstrelHtWifiManager::CalculateRetransmits(), ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64InputTestCase::Check(), ns3::ConstantRateWifiManager::DoGetDataTxVector(), ns3::AarfWifiManager::DoReportDataFailed(), ns3::AarfcdWifiManager::DoReportDataFailed(), ns3::RemoteChannelBundleManager::GetSafeTime(), ns3::NullMessageSimulatorImpl::NullMessageEventHandler(), ns3::TcpSocketBase::ReTxTimeout(), and ns3::RrMultiUserScheduler::TrySendingBasicTf().
|
inline |
Logical not operator.
[in] | lhs | Left hand argument |
Definition at line 511 of file int64x64-128.h.
|
inline |
Inequality operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 144 of file int64x64.h.
|
inline |
Multiplication operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 117 of file int64x64.h.
|
inline |
Compound multiplication operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 467 of file int64x64-128.h.
|
inline |
Unary plus operator.
[in] | lhs | Left hand argument |
Definition at line 491 of file int64x64-128.h.
|
inline |
Addition operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 89 of file int64x64.h.
|
inline |
Compound addition operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 443 of file int64x64-128.h.
|
inline |
Unary negation operator (change sign operator).
Unary operator.
Unary negation operator (change sign operator)
[in] | lhs | Left hand argument |
Definition at line 501 of file int64x64-128.h.
|
inline |
Subtraction operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 103 of file int64x64.h.
|
inline |
Compound subtraction operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 455 of file int64x64-128.h.
|
inline |
Division operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 131 of file int64x64.h.
|
inline |
Compound division operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 479 of file int64x64-128.h.
|
inline |
Less than operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 420 of file int64x64-128.h.
std::ostream & ns3::operator<< | ( | std::ostream & | os, |
const int64x64_t & | value | ||
) |
Output streamer for int64x64_t.
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.
[in,out] | os | The output stream. |
[in] | value | The numerical value to print. |
Definition at line 69 of file int64x64.cc.
References ns3::int64x64_t::GetHigh(), ns3::int64x64_t::GetLow(), HEXHILOW, NS_ASSERT_MSG, and NS_LOG_LOGIC.
|
inline |
Less or equal operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 155 of file int64x64.h.
|
inline |
Equality operator.
Arithmetic operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 409 of file int64x64-128.h.
|
inline |
Greater operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 431 of file int64x64-128.h.
|
inline |
Greater or equal operator.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 166 of file int64x64.h.
std::istream & ns3::operator>> | ( | std::istream & | is, |
int64x64_t & | value | ||
) |
Input streamer for int64x64_t.
[in,out] | is | The input stream. |
[out] | value | The numerical value to set. |
Definition at line 222 of file int64x64.cc.
References ns3::ReadHiDigits(), and ns3::ReadLoDigits().
|
inlinestatic |
Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.
[in] | sa | The signed value of the first operand. |
[in] | sb | The signed value of the second operand. |
[out] | ua | The unsigned magnitude of the first operand. |
[out] | ub | The unsigned magnitude of the second operand. |
Definition at line 59 of file int64x64-cairo.cc.
References _cairo_int128_negative, _cairo_int128_to_uint128, and _cairo_uint128_negate().
|
inlinestatic |
Compute the sign of the result of multiplying or dividing Q64.64 fixed precision operands.
[in] | sa | The signed value of the first operand. |
[in] | sb | The signed value of the second operand. |
[out] | ua | The unsigned magnitude of the first operand. |
[out] | ub | The unsigned magnitude of the second operand. |
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().
|
static |
Read the integer portion of a number from a string containing just the integral digits (no decimal point or fractional part).
[in] | str | The string representation of the integral part of a number, with no fractional part or decimal point. |
Definition at line 180 of file int64x64.cc.
Referenced by ns3::operator>>().
|
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).
[in] | str | The string representation of the fractional part of a number, without integral part or decimal point. |
Definition at line 203 of file int64x64.cc.
References ns3::int64x64_t::GetLow(), and NS_ASSERT_MSG.
Referenced by ns3::operator>>().