omni::util Namespace Reference


Detailed Description

Auxiliary constants and functions.

This namespace contains some useful constants and auxiliary functions.

Constants

Conversions

Power of two and parity

Bits packing/unpacking and flip

Polynomials


Function Documentation

double deg2rad ( double  deg  ) 

Convert degrees to the radians.

This function converts the deg value in degrees to the corresponding value in radians.

  double rad = deg * 3.14/180;

Parameters:
[in] deg The value in degrees.
Returns:
The value in radians.
See also:
rad2deg()

double rad2deg ( double  rad  ) 

Convert radians to the degrees.

This function converts the rad value in radians to the corresponding value in degrees.

  double deg = rad * 180/3.14;

Parameters:
[in] rad The value in radians.
Returns:
The value in degrees.
See also:
deg2rad()

double dB2line ( double  dB  ) 

Convert dB to the value in linear scale.

This function converts the dB value in logarithmic (dB) scale to the corresponding value in linear scale.

  double L = pow(10, dB/10);

Parameters:
[in] dB The value in logarithmic scale.
Returns:
The value in linear scale.
See also:
line2dB()

double line2dB ( double  L  ) 

Convert value in linear scale to the dB.

This function converts the L value in linear scale to the corresponding value in logarithmic (dB) scale.

  double dB = 10*log10(L);

Parameters:
[in] L The value in linear scale. Should be positive nonzero value!
Returns:
The value in logarithmic scale.
See also:
dB2line()

double dBm2watt ( double  dBm  ) 

Convert dBm to the watts.

This function converts the dBm value in logarithmic (dBm) scale to the value in watts.

  double W = pow(10, dBm/10) / 1000;

Parameters:
[in] dBm The value in dBm.
Returns:
The value in watts.
See also:
watt2dBm()

double watt2dBm ( double  W  ) 

Convert watts to the dBm.

This function converts the W value in watts to the value in logarithmic (dBm) scale.

  double dBm = 10*log10(W*1000);

Parameters:
[in] W The value in watts. Should be positive nonzero value!
Returns:
The value in dBm.
See also:
dBm2watt()

double kph2mps ( double  kph  ) 

Convert kph to the mps.

This function converts the value in kilometers per hour (kph) to the value in meters per second (mps).

  double mps = kph / 3.6;

Parameters:
[in] kph The value in kph.
Returns:
The value in mps.
See also:
mps2kph()

double mps2kph ( double  mps  ) 

Convert mps to the kph.

This function converts the value in meters per second (mps) to the value in kilometers per hour (kph).

  double kph = mps * 3.6;

Parameters:
[in] mps The value in mps.
Returns:
The value in kph.
See also:
kph2mps()

bool omni::util::is_ipow2 ( x  )  [inline]

Is integer power of two?

This functions checks the x arguments - is it integer power of two?

The valid integer powers of two: 0, 1, 2, 4, 8, 16, 32, 64, 128, etc...

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The unsigned integer.
Returns:
true if argument is integer power of two, otherwise false.
See also:
log2()

flp2()

clp2()

T omni::util::log2 ( x  )  [inline]

Binary integer logarithm.

This function calculates a binary integer logarithm of the x argument. The input argument should be integer power of two and can't be zero.

  log2(1) == 0;
  log2(2) == 1;
  log2(4) == 2;
  log2(8) == 3;

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The unsigned integer.
Returns:
The binary logarithm.
See also:
is_ipow2()

flp2()

clp2()

T omni::util::flp2 ( x  )  [inline]

Nearest (floor) integer power of two.

This function calculates an integer value representing the largest integer power of two that is less than or equal to x argument.

  flp2(4) == 4;
  flp2(5) == 4;
  flp2(7) == 4;
  flp2(9) == 8;

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The unsigned integer.
Returns:
The nearest (floor) integer power of two.
See also:
is_ipow2()

log2()

clp2()

T omni::util::clp2 ( x  )  [inline]

Nearest (ceil) integer power of two.

This function calculates an integer value representing the smallest integer power of two that is greater than or equal to x argument.

  clp2(4) == 4;
  clp2(5) == 8;
  clp2(7) == 8;
  clp2(9) == 16;

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The unsigned integer.
Returns:
The nearest (ceil) integer power of two.
See also:
is_ipow2()

log2()

flp2()

T omni::util::parity ( x  )  [inline]

Parity bit.

This function calculates a parity bit of the input argument x.

The parity bit is equal to:

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The unsigned integer.
Returns:
The parity bit.

T omni::util::bi2de_msb ( In  first,
size_t  Nbits,
x = T() 
) [inline]

Binary to decimal (MSB first).

This function converts input binary sequence [first, first + Nbits) to the one "decimal" value. First element of the input bit sequence is correspond to the most significant bit of the returned "decimal" value.

The number of bits Nbits should be less than or equal to the size of returned "decimal" value (i.e. 8*sizeof(T)).

For example, the following code will print "13" (1101b):

  const int bits[] = { 1, 1, 0, 1 };
  std::cout << bi2de_msb<unsigned>(bits, 4) << "\n";

The last argument x is used for result type deduction. The following two lines are equivalent:

  bi2de_msb<unsigned>(bits, 4);
  bi2de_msb(bits, 4, unsigned(0));

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] first Begin of the input bit sequence.
[in] Nbits Number of bits to converting.
[in] x Initial value, by default is zero.
Returns:
The "decimal" value.

Out omni::util::de2bi_msb ( x,
size_t  Nbits,
Out  first 
) [inline]

Decimal to binary (MSB first).

This function convert "decimal" value x to the output bit sequence [first, first + Nbits). First element of the output bit sequence is correspond to the most significant bit of the input "decimal" value.

The number of bits Nbits should be less than or equal to the size of input "decimal" value (i.e. 8*sizeof(T)).

For example, the following code will print "1101b" (13):

  std::vector<int> bits(4);
  de2bi_msb(13, bits.size(), bits.begin());
  std::copy(bits.begin(), bits.end(),
    std::ostream_iterator<int>(std::cout, ""));
  std::cout << "b\n";

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x Input "decimal" value.
[in] Nbits Number of bits to converting.
[in] first Begin of the output bit sequence.
Returns:
End of the output bit sequence.

T omni::util::bi2de_lsb ( In  first,
size_t  Nbits,
x = T() 
) [inline]

Binary to decimal (LSB first).

This function converts input binary sequence [first, first + Nbits) to the one "decimal" value. First element of the input bit sequence is correspond to the least significant bit of the returned "decimal" value.

The number of bits Nbits should be less than or equal to the size of returned "decimal" value (i.e. 8*sizeof(T)).

For example, the following code will print "13" (1101b):

  const int bits[] = { 1, 0, 1, 1 };
  std::cout << bi2de_lsb<unsigned>(bits, 4) << "\n";

The last argument x is used for result type deduction. The following two lines are equivalent:

  bi2de_lsb<unsigned>(bits, 4);
  bi2de_lsb(bits, 4, unsigned(0));

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] first Begin of the input bit sequence.
[in] Nbits Number of bits to converting.
[in] x Initial value, by default is zero.
Returns:
The "decimal" value.

Out omni::util::de2bi_lsb ( x,
size_t  Nbits,
Out  first 
) [inline]

Decimal to binary (LSB first).

This function convert "decimal" value x to the output bit sequence [first, first + Nbits). First element of the output bit sequence is correspond to the least significant bit of the input "decimal" value.

The number of bits Nbits should be less than or equal to the size of input "decimal" value (i.e. 8*sizeof(T)).

For example, the following code will print "1011b" (13):

  std::vector<int> bits(4);
  de2bi_lsb(13, bits.size(), bits.begin());
  std::copy(bits.begin(), bits.end(),
    std::ostream_iterator<int>(std::cout, ""));
  std::cout << "b\n";

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x Input "decimal" value.
[in] Nbits Number of bits to converting.
[in] first Begin of the output bit sequence.
Returns:
End of the output bit sequence.

T omni::util::bits_flip ( x,
size_t  Nbits 
) [inline]

Reverse the bit order.

This function returns the flipped Nbits least significant bits of the argument x.

To flip all bits, you can use the following code:

  bits_flip(x, sizeof(x)*8);

Note:
The template argument T should be unsigned integer type.
Parameters:
[in] x The input integer value.
[in] Nbits Number of least significant bits.
Returns:
The flipped value.

TY omni::util::poly ( const TX &  x,
Bi  first,
Bi  last,
const TY &   
) [inline]

Calculate the polynomial's function.

This function calculates the value of polynomial's function:

  A[0]*pow(x,N-1) + A[1]*pow(x,N-2)... + A[N-2]*x + A[N-1]

where

The last argument is used for result type deduction.

Parameters:
[in] x The polynomial's argument.
[in] first Begin of polynomial's coefficients.
[in] last End of polynomial's coefficients.
Returns:
The value of polynomial's function.

T omni::util::poly ( const T &  x,
Bi  first,
Bi  last 
) [inline]

Calculate the polynomial's function.

This function calculates the value of polynomial's function:

  A[0]*pow(x,N-1) + A[1]*pow(x,N-2)... + A[N-2]*x + A[N-1]

where

Note:
The result's type is equal to the x argument's type.
Parameters:
[in] x The polynomial's argument.
[in] first Begin of polynomial's coefficients.
[in] last End of polynomial's coefficients.
Returns:
The value of polynomial's function.


Variable Documentation

const double SQRT2

Square root of 2.

const double SQRT3

Square root of 3.

const double LG2

Decimal logarithm of 2.

const double LN2

Natural logarithm of 2.

const double PI

The Pi value.


Generated on Wed Jun 6 17:27:47 2007 for OMNI by  doxygen 1.5.2