34 #include <itpp/itexports.h> 47 inline double logb(
double b,
double x)
53 inline int pow2i(
int x) {
return ((x < 0) ? 0 : (1 << x)); }
63 return std::ldexp(1.0,x);
78 it_assert(n >= 0,
"int2bits(): Improper argument value");
94 it_assert(n > 0,
"levels2bits(): Improper argument value");
117 if (std::numeric_limits<double>::is_iec559) {
118 if (x == std::numeric_limits<double>::infinity())
139 if (std::numeric_limits<double>::is_iec559
140 && (x >= log_double_max))
147 ITPP_EXPORT
double log_add(
double log_a,
double log_b);
155 inline vec
exp(
const vec &x)
157 return apply_function<double>(
std::exp, x);
160 inline cvec
exp(
const cvec &x)
162 return apply_function<std::complex<double> >(
std::exp, x);
165 inline mat
exp(
const mat &m)
167 return apply_function<double>(
std::exp, m);
170 inline cmat
exp(
const cmat &m)
172 return apply_function<std::complex<double> >(
std::exp, m);
176 inline vec
pow(
const double x,
const vec &y)
178 return apply_function<double>(
std::pow, x, y);
181 inline mat
pow(
const double x,
const mat &y)
183 return apply_function<double>(
std::pow, x, y);
186 inline vec
pow(
const vec &x,
const double y)
188 return apply_function<double>(
std::pow, x, y);
191 inline mat
pow(
const mat &x,
const double y)
193 return apply_function<double>(
std::pow, x, y);
199 return apply_function<double>(
pow2, x);
206 for(
int i = 0; i < x.length(); i++)
214 return apply_function<double>(
pow2, x);
220 mat out(x.rows(), x.cols());
221 for(
int i = 0; i < x.rows(); i++) {
222 for(
int j = 0; j < x.cols(); j++) {
223 out(i, j) =
pow2(x(i, j));
232 return apply_function<double>(
pow10, x);
237 return apply_function<double>(
pow10, x);
241 inline vec
log(
const vec &x)
243 return apply_function<double>(
std::log, x);
246 inline mat
log(
const mat &x)
248 return apply_function<double>(
std::log, x);
251 inline cvec
log(
const cvec &x)
253 return apply_function<std::complex<double> >(
std::log, x);
256 inline cmat
log(
const cmat &x)
258 return apply_function<std::complex<double> >(
std::log, x);
265 ITPP_EXPORT vec
log2(
const vec &x);
268 ITPP_EXPORT mat
log2(
const mat &x);
282 inline vec
logb(
double b,
const vec &x)
284 return apply_function<double>(
itpp::logb, b, x);
287 inline mat
logb(
double b,
const mat &x)
289 return apply_function<double>(
itpp::logb, b, x);
293 inline vec
dB(
const vec &x)
295 return apply_function<double>(
dB, x);
298 inline mat
dB(
const mat &x)
300 return apply_function<double>(
dB, x);
306 return apply_function<double>(
inv_dB, x);
311 return apply_function<double>(
inv_dB, x);
317 return apply_function<int>(
int2bits, v);
330 #endif // #ifndef LOG_EXP_H double logb(double b, double x)
Base-b logarithm.
double log_add(double log_a, double log_b)
Safe substitute for log(exp(log_a) + exp(log_b))
Help functions to make functions with vec and mat as arguments.
vec log10(const vec &x)
log-10 of the elements
const double log_double_min
Constant definition to speed up trunc_log(), trunc_exp() and log_add()
#define it_assert(t, s)
Abort if t is not true.
double dB(double x)
Decibel of x (10*log10(x))
mat pow(const mat &x, const double y)
Calculates x to the power of y (x^y)
vec log(const vec &x)
The natural logarithm of the elements.
T min(const Vec< T > &in)
Minimum value of vector.
vec exp(const vec &x)
Exp of the elements of a vector x.
vec log2(const vec &x)
log-2 of the elements
T max(const Vec< T > &v)
Maximum value of vector.
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
double inv_dB(double x)
Inverse of decibel of x.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
double pow2(double x)
Calculate two to the power of x (2^x)
double trunc_log(double x)
Truncated natural logarithm function.
mat log10(const mat &x)
log-10 of the elements
double pow10(double x)
Calculate ten to the power of x (10^x)
const double log_double_max
Constant definition to speed up trunc_log() and trunc_exp()
double trunc_exp(double x)
Truncated exponential function.
cmat exp(const cmat &m)
Exp of the elements of a complex matrix m.
int int2bits(int n)
Calculate the number of bits needed to represent an integer n.
int levels2bits(int n)
Calculate the number of bits needed to represent n different values (levels).
cmat log(const cmat &x)
The natural logarithm of the elements.