IT++ Logo

fix_functions.cpp

Go to the documentation of this file.
00001 
00031 #include <itpp/fixed/fix_functions.h>
00032 
00033 
00034 namespace itpp
00035 {
00036 
00037 vec to_vec(const fixvec &v)
00038 {
00039   vec temp(v.length());
00040   for (int i = 0; i < v.length(); i++) {
00041     temp(i) = v(i).unfix();
00042   }
00043   return temp;
00044 }
00045 
00046 cvec to_cvec(const cfixvec &v)
00047 {
00048   cvec temp(v.length());
00049   for (int i = 0; i < v.length(); i++) {
00050     temp(i) = v(i).unfix();
00051   }
00052   return temp;
00053 }
00054 
00055 mat to_mat(const fixmat &m)
00056 {
00057   mat temp(m.rows(), m.cols());
00058   for (int i = 0; i < m.rows(); i++) {
00059     for (int j = 0; j < m.cols(); j++) {
00060       temp(i, j) = m(i, j).unfix();
00061     }
00062   }
00063   return temp;
00064 }
00065 
00066 cmat to_cmat(const cfixmat &m)
00067 {
00068   cmat temp(m.rows(), m.cols());
00069   for (int i = 0; i < m.rows(); i++) {
00070     for (int j = 0; j < m.cols(); j++) {
00071       temp(i, j) = m(i, j).unfix();
00072     }
00073   }
00074   return temp;
00075 }
00076 
00077 Fix abs(const Fix &x)
00078 {
00079   fixrep tmp = x.get_re();
00080   return Fix((tmp >= 0 ? tmp : -tmp),  // Risk for overflow!
00081              x.get_shift(),
00082              0, 0);
00083 }
00084 
00085 Fix real(const CFix &x)
00086 {
00087   return Fix(x.get_re(),
00088              x.get_shift(),
00089              0, 0);
00090 }
00091 
00092 Fix imag(const CFix &x)
00093 {
00094   return Fix(x.get_im(),
00095              x.get_shift(),
00096              0, 0);
00097 }
00098 
00099 CFix conj(const CFix &x)
00100 {
00101   return CFix(x.get_re(),
00102               -x.get_im(),
00103               x.get_shift(),
00104               0, 0);
00105 }
00106 
00107 } // namespace itpp
SourceForge Logo

Generated on Sun Jul 26 08:36:51 2009 for IT++ by Doxygen 1.5.9