INET Framework for OMNeT++/OMNEST
inet::math Namespace Reference

Support functions for mathematical operations. More...

Functions

double mod (double dividend, double divisor)
 Returns the rest of a whole-numbered division. More...
 
double div (double dividend, double divisor)
 Returns the result of a whole-numbered division. More...
 
double modulo (double a, double n)
 Returns the remainder r on division of dividend a by divisor n, using floored division. More...
 
bool close (double one, double two)
 Tests whether two doubles are close enough to be declared equal. More...
 
int stepfunction (double i)
 Returns 0 if i is close to 0, 1 if i is positive and greater than epsilon, or -1 if it is negative and less than epsilon. More...
 
int sign (double i)
 Returns 1 if the parameter is greater or equal to zero, -1 otherwise. More...
 
int round (double d)
 Returns an integer that corresponds to rounded double parameter. More...
 
double floorToZero (double d)
 Discards the fractional part of the parameter, e.g. More...
 
double max (double a, double b)
 Returns the greater of the given parameters. More...
 
double dB2fraction (double dB)
 Converts a dB value to fraction. More...
 
double fraction2dB (double fraction)
 Convert a fraction value to dB. More...
 
double dBm2mW (double dBm)
 Converts a dBm value into milliwatts. More...
 
double mW2dBm (double mW)
 Convert a mW value to dBm. More...
 
double deg2rad (double deg)
 Convert a degree value to radian. More...
 
double rad2deg (double rad)
 Convert a radian value to degree. More...
 
double n_choose_k (int n, int k)
 Implementation of the n choose k (binomial coefficient) function, from the MiXiM Framework Author Karl Wessel. More...
 

Detailed Description

Support functions for mathematical operations.

This namespace contains all kind of mathematical support functions

Function Documentation

bool inet::math::close ( double  one,
double  two 
)
inline
double inet::math::deg2rad ( double  deg)
inline
double inet::math::div ( double  dividend,
double  divisor 
)
inline

Returns the result of a whole-numbered division.

Referenced by inet::Int128::operator%=(), inet::Int128::operator/=(), and inet::Int128::toInt64().

118 {
119  double i;
120  modf(dividend / divisor, &i);
121  return i;
122 }
double inet::math::floorToZero ( double  d)
inline

Discards the fractional part of the parameter, e.g.

-3.8 becomes -3

156 { return (d >= 0.0) ? floor(d) : ceil(d); }
double inet::math::fraction2dB ( double  fraction)
inline
double inet::math::max ( double  a,
double  b 
)
inline

Returns the greater of the given parameters.

Referenced by inet::physicallayer::MappingUtils::applyElementWiseOperator(), inet::VoIPStreamSender::checkSilence(), inet::BVHTree::computeBoundingBox(), inet::Prism::computeBoundingBoxSize(), inet::Polyhedron::computeBoundingBoxSize(), inet::physicallayer::ParabolicAntenna::computeGain(), inet::physicallayer::ConvolutionalCode::computeNetBitErrorRate(), inet::Polygon::computeSize(), inet::physicallayer::ConvolutionalCode::ConvolutionalCode(), inet::tcp::TCPBaseAlg::established(), inet::SimpleVoIPReceiver::evaluateTalkspurt(), inet::IntervalTree::fixupMaxHigh(), inet::LabeledIconFigure::getBounds(), inet::Box::getMax(), inet::GPSR::getPlanarNeighbors(), inet::AODVRouting::handleHelloMessage(), inet::UDPVideoStreamCli::handleNodeStart(), inet::UDPSink::handleNodeStart(), inet::UDPBasicApp::handleNodeStart(), inet::UDPBasicBurst::handleNodeStart(), inet::TelnetApp::handleOperationStage(), inet::TCPBasicClientApp::handleOperationStage(), inet::AODVRouting::handleRREP(), inet::AODVRouting::handleRREQ(), inet::physicallayer::Ieee80211OFDMInterleaver::Ieee80211OFDMInterleaver(), inet::visualizer::MediumCanvasVisualizer::initialize(), inet::physicallayer::SimpleConstMapping::initializeArguments(), inet::MobilityBase::isOutside(), inet::visualizer::isPointOnSegment(), inet::IntervalTree::leftRotate(), inet::SpatialGrid::LineSegmentIterator::LineSegmentIterator(), inet::tcp::memp_init(), inet::PIMDM::multicastPacketArrivedOnRpfInterface(), inet::physicalenvironment::PhysicalEnvironment::parseObjects(), inet::physicallayer::ConstMapping::print(), inet::tcp::TCPNewReno::recalculateSlowStartThreshold(), inet::tcp::TCPReno::recalculateSlowStartThreshold(), inet::tcp::TCPTahoe::recalculateSlowStartThreshold(), inet::tcp::TCPVegas::recalculateSlowStartThreshold(), inet::visualizer::MediumCanvasVisualizer::receptionStarted(), LinearGaugeFigure::redrawTicks(), ThermometerFigure::redrawTicks(), GaugeFigure::redrawTicks(), ProgressMeterFigure::refresh(), CounterFigure::refresh(), inet::SignalFigure::refresh(), inet::BarFigure::refreshDisplay(), inet::visualizer::MediumCanvasVisualizer::refreshSignalFigure(), inet::IntervalTree::rightRotate(), inet::IPv4NetworkConfigurator::routesCanBeNeighbors(), inet::TCPSessionApp::sendData(), inet::tcp::TCPBaseAlg::sendData(), inet::tcp::TCPSegmentTransmitInfoList::set(), inet::SCTPSocket::setHbInterval(), inet::httptools::rdExponential::setMaxLimit(), inet::Posture::setPostureSpeed(), inet::SCTPSocket::setRtoInfo(), inet::TCPSessionApp::socketEstablished(), inet::DHCPServer::startApp(), inet::DHCPClient::startApp(), and inet::AODVRouting::updateValidRouteLifeTime().

161 { return (a < b) ? b : a; }
value< double, units::m > b
Definition: Units.h:1054
double inet::math::modulo ( double  a,
double  n 
)
inline

Returns the remainder r on division of dividend a by divisor n, using floored division.

The remainder r has the same sign as the divisor n.

Referenced by inet::MobilityBase::isOutside(), and inet::MobilityBase::reflectIfOutside().

128 { return a - n * floor(a / n); }
double inet::math::mW2dBm ( double  mW)
inline

Convert a mW value to dBm.

181 { return 10 * log10(mW); }
milli< W >::type mW
Definition: Units.h:903
double inet::math::n_choose_k ( int  n,
int  k 
)
inline

Implementation of the n choose k (binomial coefficient) function, from the MiXiM Framework Author Karl Wessel.

Referenced by inet::physicallayer::DSSSOQPSK16Modulation::calculateBER().

197  {
198  if (n < k)
199  return 0.0;
200 
201  const int iK = (k<<1) > n ? n-k : k;
202  const double dNSubK = (n-iK);
203  int i = 1;
204  double dRes = i > iK ? 1.0 : (dNSubK+i);
205 
206  for (++i; i <= iK; ++i) {
207  dRes *= dNSubK+i;
208  dRes /= i;
209  }
210  return dRes;
211 }
const double k
Definition: QAM16Modulation.cc:24
double inet::math::rad2deg ( double  rad)
inline

Convert a radian value to degree.

191 { return rad * 180 / M_PI; }
#define M_PI
Definition: INETMath.h:64
compose< m, pow< m,-1 > > rad
Definition: Units.h:764
int inet::math::round ( double  d)
inline

Returns an integer that corresponds to rounded double parameter.

Referenced by inet::power::SimpleEpEnergyStorage::handleMessage(), inet::VoIPStreamSender::initialize(), and inet::visualizer::MediumCanvasVisualizer::receptionStarted().

151 { return (int)(ceil(d - 0.5)); }
int inet::math::sign ( double  i)
inline

Returns 1 if the parameter is greater or equal to zero, -1 otherwise.

Referenced by inet::visualizer::LineManager::getLineShift(), inet::MobilityBase::isOutside(), inet::MobilityBase::reflectIfOutside(), and inet::TractorMobility::setTargetPosition().

146 { return (i >= 0) ? 1 : -1; };
int inet::math::stepfunction ( double  i)
inline

Returns 0 if i is close to 0, 1 if i is positive and greater than epsilon, or -1 if it is negative and less than epsilon.

141 { return (i > EPSILON) ? 1 : close(i, 0) ? 0 : -1; };
#define EPSILON
Definition: INETMath.h:98
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:135