This namespace contains some useful constants and auxiliary functions.
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;
[in] | deg | The value in degrees. |
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;
[in] | rad | The value in radians. |
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);
[in] | dB | The value in logarithmic scale. |
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);
[in] | L | The value in linear scale. Should be positive nonzero value! |
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;
[in] | dBm | The value in dBm. |
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);
[in] | W | The value in watts. Should be positive nonzero value! |
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;
[in] | kph | The value in kph. |
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;
[in] | mps | The value in mps. |
bool omni::util::is_ipow2 | ( | T | 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...
[in] | x | The unsigned integer. |
T omni::util::log2 | ( | T | 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.
[in] | x | The unsigned integer. |
T omni::util::flp2 | ( | T | 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.
[in] | x | The unsigned integer. |
T omni::util::clp2 | ( | T | 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.
[in] | x | The unsigned integer. |
T omni::util::parity | ( | T | x | ) | [inline] |
Parity bit.
This function calculates a parity bit of the input argument x.
The parity bit is equal to:
[in] | x | The unsigned integer. |
T omni::util::bi2de_msb | ( | In | first, | |
size_t | Nbits, | |||
T | 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));
[in] | first | Begin of the input bit sequence. |
[in] | Nbits | Number of bits to converting. |
[in] | x | Initial value, by default is zero. |
Out omni::util::de2bi_msb | ( | T | 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";
[in] | x | Input "decimal" value. |
[in] | Nbits | Number of bits to converting. |
[in] | first | Begin of the output bit sequence. |
T omni::util::bi2de_lsb | ( | In | first, | |
size_t | Nbits, | |||
T | 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));
[in] | first | Begin of the input bit sequence. |
[in] | Nbits | Number of bits to converting. |
[in] | x | Initial value, by default is zero. |
Out omni::util::de2bi_lsb | ( | T | 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";
[in] | x | Input "decimal" value. |
[in] | Nbits | Number of bits to converting. |
[in] | first | Begin of the output bit sequence. |
T omni::util::bits_flip | ( | T | 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);
[in] | x | The input integer value. |
[in] | Nbits | Number of least significant bits. |
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.
[in] | x | The polynomial's argument. |
[in] | first | Begin of polynomial's coefficients. |
[in] | last | End of polynomial's coefficients. |
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
[in] | x | The polynomial's argument. |
[in] | first | Begin of polynomial's coefficients. |
[in] | last | End of polynomial's coefficients. |
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.