IT++ Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fix_base.h
Go to the documentation of this file.
1 
29 #ifndef FIX_BASE_H
30 #define FIX_BASE_H
31 
32 #include <itpp/base/ittypes.h>
33 #include <itpp/stat/misc_stat.h>
34 
35 
36 namespace itpp
37 {
38 
880 
881 
883 typedef int64_t fixrep;
885 const int MAX_WORDLEN = 64;
886 
888 const uint64_t UINT64_POW2[64] = {
889  uint64_t(1), uint64_t(1) << 1, uint64_t(1) << 2, uint64_t(1) << 3, uint64_t(1) << 4,
890  uint64_t(1) << 5, uint64_t(1) << 6, uint64_t(1) << 7, uint64_t(1) << 8, uint64_t(1) << 9,
891  uint64_t(1) << 10, uint64_t(1) << 11, uint64_t(1) << 12, uint64_t(1) << 13, uint64_t(1) << 14,
892  uint64_t(1) << 15, uint64_t(1) << 16, uint64_t(1) << 17, uint64_t(1) << 18, uint64_t(1) << 19,
893  uint64_t(1) << 20, uint64_t(1) << 21, uint64_t(1) << 22, uint64_t(1) << 23, uint64_t(1) << 24,
894  uint64_t(1) << 25, uint64_t(1) << 26, uint64_t(1) << 27, uint64_t(1) << 28, uint64_t(1) << 29,
895  uint64_t(1) << 30, uint64_t(1) << 31, uint64_t(1) << 32, uint64_t(1) << 33, uint64_t(1) << 34,
896  uint64_t(1) << 35, uint64_t(1) << 36, uint64_t(1) << 37, uint64_t(1) << 38, uint64_t(1) << 39,
897  uint64_t(1) << 40, uint64_t(1) << 41, uint64_t(1) << 42, uint64_t(1) << 43, uint64_t(1) << 44,
898  uint64_t(1) << 45, uint64_t(1) << 46, uint64_t(1) << 47, uint64_t(1) << 48, uint64_t(1) << 49,
899  uint64_t(1) << 50, uint64_t(1) << 51, uint64_t(1) << 52, uint64_t(1) << 53, uint64_t(1) << 54,
900  uint64_t(1) << 55, uint64_t(1) << 56, uint64_t(1) << 57, uint64_t(1) << 58, uint64_t(1) << 59,
901  uint64_t(1) << 60, uint64_t(1) << 61, uint64_t(1) << 62, uint64_t(1) << 63
902 };
903 
905 const double DOUBLE_POW2[128] = {
906  0.5 / UINT64_POW2[63], 1.0 / UINT64_POW2[63], 1.0 / UINT64_POW2[62], 1.0 / UINT64_POW2[61],
907  1.0 / UINT64_POW2[60], 1.0 / UINT64_POW2[59], 1.0 / UINT64_POW2[58], 1.0 / UINT64_POW2[57],
908  1.0 / UINT64_POW2[56], 1.0 / UINT64_POW2[55], 1.0 / UINT64_POW2[54], 1.0 / UINT64_POW2[53],
909  1.0 / UINT64_POW2[52], 1.0 / UINT64_POW2[51], 1.0 / UINT64_POW2[50], 1.0 / UINT64_POW2[49],
910  1.0 / UINT64_POW2[48], 1.0 / UINT64_POW2[47], 1.0 / UINT64_POW2[46], 1.0 / UINT64_POW2[45],
911  1.0 / UINT64_POW2[44], 1.0 / UINT64_POW2[43], 1.0 / UINT64_POW2[42], 1.0 / UINT64_POW2[41],
912  1.0 / UINT64_POW2[40], 1.0 / UINT64_POW2[39], 1.0 / UINT64_POW2[38], 1.0 / UINT64_POW2[37],
913  1.0 / UINT64_POW2[36], 1.0 / UINT64_POW2[35], 1.0 / UINT64_POW2[34], 1.0 / UINT64_POW2[33],
914  1.0 / UINT64_POW2[32], 1.0 / UINT64_POW2[31], 1.0 / UINT64_POW2[30], 1.0 / UINT64_POW2[29],
915  1.0 / UINT64_POW2[28], 1.0 / UINT64_POW2[27], 1.0 / UINT64_POW2[26], 1.0 / UINT64_POW2[25],
916  1.0 / UINT64_POW2[24], 1.0 / UINT64_POW2[23], 1.0 / UINT64_POW2[22], 1.0 / UINT64_POW2[21],
917  1.0 / UINT64_POW2[20], 1.0 / UINT64_POW2[19], 1.0 / UINT64_POW2[18], 1.0 / UINT64_POW2[17],
918  1.0 / UINT64_POW2[16], 1.0 / UINT64_POW2[15], 1.0 / UINT64_POW2[14], 1.0 / UINT64_POW2[13],
919  1.0 / UINT64_POW2[12], 1.0 / UINT64_POW2[11], 1.0 / UINT64_POW2[10], 1.0 / UINT64_POW2[9],
920  1.0 / UINT64_POW2[8], 1.0 / UINT64_POW2[7], 1.0 / UINT64_POW2[6], 1.0 / UINT64_POW2[5],
921  1.0 / UINT64_POW2[4], 1.0 / UINT64_POW2[3], 1.0 / UINT64_POW2[2], 1.0 / UINT64_POW2[1],
922  1.0, 1.0*UINT64_POW2[1], 1.0*UINT64_POW2[2], 1.0*UINT64_POW2[3],
923  1.0*UINT64_POW2[4], 1.0*UINT64_POW2[5], 1.0*UINT64_POW2[6], 1.0*UINT64_POW2[7],
924  1.0*UINT64_POW2[8], 1.0*UINT64_POW2[9], 1.0*UINT64_POW2[10], 1.0*UINT64_POW2[11],
925  1.0*UINT64_POW2[12], 1.0*UINT64_POW2[13], 1.0*UINT64_POW2[14], 1.0*UINT64_POW2[15],
926  1.0*UINT64_POW2[16], 1.0*UINT64_POW2[17], 1.0*UINT64_POW2[18], 1.0*UINT64_POW2[19],
927  1.0*UINT64_POW2[20], 1.0*UINT64_POW2[21], 1.0*UINT64_POW2[22], 1.0*UINT64_POW2[23],
928  1.0*UINT64_POW2[24], 1.0*UINT64_POW2[25], 1.0*UINT64_POW2[26], 1.0*UINT64_POW2[27],
929  1.0*UINT64_POW2[28], 1.0*UINT64_POW2[29], 1.0*UINT64_POW2[30], 1.0*UINT64_POW2[31],
930  1.0*UINT64_POW2[32], 1.0*UINT64_POW2[33], 1.0*UINT64_POW2[34], 1.0*UINT64_POW2[35],
931  1.0*UINT64_POW2[36], 1.0*UINT64_POW2[37], 1.0*UINT64_POW2[38], 1.0*UINT64_POW2[39],
932  1.0*UINT64_POW2[40], 1.0*UINT64_POW2[41], 1.0*UINT64_POW2[42], 1.0*UINT64_POW2[43],
933  1.0*UINT64_POW2[44], 1.0*UINT64_POW2[45], 1.0*UINT64_POW2[46], 1.0*UINT64_POW2[47],
934  1.0*UINT64_POW2[48], 1.0*UINT64_POW2[49], 1.0*UINT64_POW2[50], 1.0*UINT64_POW2[51],
935  1.0*UINT64_POW2[52], 1.0*UINT64_POW2[53], 1.0*UINT64_POW2[54], 1.0*UINT64_POW2[55],
936  1.0*UINT64_POW2[56], 1.0*UINT64_POW2[57], 1.0*UINT64_POW2[58], 1.0*UINT64_POW2[59],
937  1.0*UINT64_POW2[60], 1.0*UINT64_POW2[61], 1.0*UINT64_POW2[62], 1.0*UINT64_POW2[63]
938 };
939 
941 enum e_mode {
942  TC,
943  US
944 };
945 
947 enum o_mode {
948  SAT,
953 };
954 
956 enum q_mode {
957  RND,
963  TRN,
965 };
966 
973 };
974 
980 class Fix_Base
981 {
982 public:
984  explicit Fix_Base(int s = 0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
985  : shift(s), wordlen(w), emode(e), omode(o), qmode(q), stat_ptr(ptr) {init();}
987  Fix_Base(const Fix_Base &x)
990  virtual ~Fix_Base() {}
991 
993  void set_shift(int s) {shift = s;}
995  static void set_output_mode(output_mode o) {outputmode = o;}
997  static void set_output_mode(std::string o);
998 
1000  int get_shift() const {return shift;}
1002  int get_wordlen() const {return wordlen;}
1004  e_mode get_e_mode() const {return emode;}
1006  o_mode get_o_mode() const {return omode;}
1008  q_mode get_q_mode() const {return qmode;}
1010  output_mode get_output_mode() const {return outputmode;}
1012  fixrep get_max() const {return max;}
1014  fixrep get_min() const {return min;}
1016  virtual void print() const;
1017 
1018 protected:
1020  int shift;
1022  int wordlen;
1037 
1039  void init();
1041  fixrep apply_o_mode(fixrep x) const;
1045  fixrep scale_and_apply_modes(double x, q_mode q) const;
1049  fixrep rshift_and_apply_q_mode(fixrep x, int n, q_mode q) const;
1050 
1051 private:
1053  static output_mode outputmode;
1054 };
1055 
1057 inline std::ostream &operator<<(std::ostream &os, const output_mode &o)
1058 {
1060  return os;
1061 }
1062 
1064 
1065 } // namespace itpp
1066 
1067 #endif // #ifndef FIX_BASE_H
SourceForge Logo

Generated on Fri Mar 21 2014 17:14:13 for IT++ by Doxygen 1.8.1.2