IT++ Logo Newcom Logo

fix_functions.cpp

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

Generated on Fri Jun 8 02:08:55 2007 for IT++ by Doxygen 1.5.2