⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_fxval.h

📁 system C源码 一种替代verilog的语言
💻 H
📖 第 1 页 / 共 5 页
字号:
    static double from_string( const char* );private:    double                          m_val;    mutable sc_fxval_fast_observer* m_observer;};// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII// ----------------------------------------------------------------------------//  CLASS : sc_fxval////  Fixed-point value type; arbitrary precision.// ----------------------------------------------------------------------------// protected methodinlinesc_fxval_observer*sc_fxval::observer() const{    return m_observer;}// internal use only;inlinesc_fxval::sc_fxval( scfx_rep* a ): m_rep( a ),  m_observer( 0 ){}// public constructorsinlinesc_fxval::sc_fxval( sc_fxval_observer* observer_ ): m_rep( new scfx_rep ),  m_observer( observer_ ){    SC_FXVAL_OBSERVER_DEFAULT_    SC_FXVAL_OBSERVER_CONSTRUCT_( *this )}inlinesc_fxval::sc_fxval( const sc_fxval& a,		    sc_fxval_observer* observer_ ): m_rep( new scfx_rep( *a.m_rep ) ),  m_observer( observer_ ){    SC_FXVAL_OBSERVER_DEFAULT_    SC_FXVAL_OBSERVER_READ_( a )    SC_FXVAL_OBSERVER_CONSTRUCT_( *this )    SC_FXVAL_OBSERVER_WRITE_( *this )}#define DEFN_CTOR_T(tp,arg)                                                   \inline                                                                        \sc_fxval::sc_fxval( tp a,                                                     \                    sc_fxval_observer* observer_ )                            \: m_rep( new scfx_rep( arg ) ),                                               \  m_observer( observer_ )                                                     \{                                                                             \    SC_FXVAL_OBSERVER_DEFAULT_                                                \    SC_FXVAL_OBSERVER_CONSTRUCT_( *this )                                     \    SC_FXVAL_OBSERVER_WRITE_( *this )                                         \}#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,a.to_double())#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.value())DEFN_CTOR_T_A(int)DEFN_CTOR_T_A(unsigned int)DEFN_CTOR_T_A(long)DEFN_CTOR_T_A(unsigned long)DEFN_CTOR_T_A(double)DEFN_CTOR_T_A(const char*)DEFN_CTOR_T_B(const sc_fxval_fast&)#ifndef SC_FX_EXCLUDE_OTHERDEFN_CTOR_T_A(int64)DEFN_CTOR_T_A(uint64)DEFN_CTOR_T_C(const sc_int_base&)DEFN_CTOR_T_C(const sc_uint_base&)DEFN_CTOR_T_A(const sc_signed&)DEFN_CTOR_T_A(const sc_unsigned&)#endif#undef DEFN_CTOR_T#undef DEFN_CTOR_T_A#undef DEFN_CTOR_T_B#undef DEFN_CTOR_T_Cinlinesc_fxval::~sc_fxval(){    SC_FXVAL_OBSERVER_DESTRUCT_( *this )    delete m_rep;}// internal use only;inlineconst scfx_rep*sc_fxval::get_rep() const{    SC_FXVAL_OBSERVER_READ_( *this )    return m_rep;}// internal use only;inlinevoidsc_fxval::set_rep( scfx_rep* rep_ ){    delete m_rep;    m_rep = rep_;    SC_FXVAL_OBSERVER_WRITE_( *this )}// unary operatorsinlineconst sc_fxvalsc_fxval::operator - () const{    SC_FXVAL_OBSERVER_READ_( *this )    return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );}inlineconst sc_fxval&sc_fxval::operator + () const{    // SC_FXVAL_OBSERVER_READ_( *this )    return *this;}// unary functionsinlinevoidneg( sc_fxval& c, const sc_fxval& a ){    SC_FXVAL_OBSERVER_READ_( a )    delete c.m_rep;    c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );    SC_FXVAL_OBSERVER_WRITE_( c )}// binary operators#define DEFN_BIN_OP_T(op,fnc,tp)                                              \inline                                                                        \const sc_fxval                                                                \operator op ( const sc_fxval& a, tp b )                                       \{                                                                             \    SC_FXVAL_OBSERVER_READ_( a )                                              \    sc_fxval tmp( b );                                                        \    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) );      \}                                                                             \                                                                              \inline                                                                        \const sc_fxval                                                                \operator op ( tp a, const sc_fxval& b )                                       \{                                                                             \    SC_FXVAL_OBSERVER_READ_( b )                                              \    sc_fxval tmp( a );                                                        \    return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) );      \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_BIN_OP_OTHER(op,fnc)                                             \DEFN_BIN_OP_T(op,fnc,int64)                                                   \DEFN_BIN_OP_T(op,fnc,uint64)                                                  \DEFN_BIN_OP_T(op,fnc,const sc_int_base&)                                      \DEFN_BIN_OP_T(op,fnc,const sc_uint_base&)                                     \DEFN_BIN_OP_T(op,fnc,const sc_signed&)                                        \DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)#else#define DEFN_BIN_OP_OTHER(op,fnc)#endif#define DEFN_BIN_OP(op,fnc)                                                   \inline                                                                        \const sc_fxval                                                                \operator op ( const sc_fxval& a, const sc_fxval& b )                          \{                                                                             \    SC_FXVAL_OBSERVER_READ_( a )                                              \    SC_FXVAL_OBSERVER_READ_( b )                                              \    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );        \}                                                                             \                                                                              \DEFN_BIN_OP_T(op,fnc,int)                                                     \DEFN_BIN_OP_T(op,fnc,unsigned int)                                            \DEFN_BIN_OP_T(op,fnc,long)                                                    \DEFN_BIN_OP_T(op,fnc,unsigned long)                                           \DEFN_BIN_OP_T(op,fnc,double)                                                  \DEFN_BIN_OP_T(op,fnc,const char*)                                             \DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&)                                    \DEFN_BIN_OP_OTHER(op,fnc)DEFN_BIN_OP(*,mult)DEFN_BIN_OP(+,add)DEFN_BIN_OP(-,sub)// don't use macro//DEFN_BIN_OP(/,div)inlineconst sc_fxvaloperator / ( const sc_fxval& a, const sc_fxval& b ){    SC_FXVAL_OBSERVER_READ_( a )    SC_FXVAL_OBSERVER_READ_( b )    return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );}DEFN_BIN_OP_T(/,div,int)DEFN_BIN_OP_T(/,div,unsigned int)DEFN_BIN_OP_T(/,div,long)DEFN_BIN_OP_T(/,div,unsigned long)DEFN_BIN_OP_T(/,div,double)DEFN_BIN_OP_T(/,div,const char*)DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)//DEFN_BIN_OP_OTHER(/,div)#ifndef SC_FX_EXCLUDE_OTHERDEFN_BIN_OP_T(/,div,int64)                                                   \DEFN_BIN_OP_T(/,div,uint64)                                                  \DEFN_BIN_OP_T(/,div,const sc_int_base&)                                      \DEFN_BIN_OP_T(/,div,const sc_uint_base&)                                     \DEFN_BIN_OP_T(/,div,const sc_signed&)                                        \DEFN_BIN_OP_T(/,div,const sc_unsigned&)#endif#undef DEFN_BIN_OP_T#undef DEFN_BIN_OP_OTHER#undef DEFN_BIN_OPinlineconst sc_fxvaloperator << ( const sc_fxval& a, int b ){    SC_FXVAL_OBSERVER_READ_( a )    return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );}inlineconst sc_fxvaloperator >> ( const sc_fxval& a, int b ){    SC_FXVAL_OBSERVER_READ_( a )    return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );}// binary functions#define DEFN_BIN_FNC_T(fnc,tp)                                                \inline                                                                        \void                                                                          \fnc ( sc_fxval& c, const sc_fxval& a, tp b )                                  \{                                                                             \    SC_FXVAL_OBSERVER_READ_( a )                                              \    sc_fxval tmp( b );                                                        \    delete c.m_rep;                                                           \    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep );               \    SC_FXVAL_OBSERVER_WRITE_( c )                                             \}                                                                             \                                                                              \inline                                                                        \void                                                                          \fnc ( sc_fxval& c, tp a, const sc_fxval& b )                                  \{                                                                             \    SC_FXVAL_OBSERVER_READ_( b )                                              \    sc_fxval tmp( a );                                                        \    delete c.m_rep;                                                           \    c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep );               \    SC_FXVAL_OBSERVER_WRITE_( c )                                             \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_BIN_FNC_OTHER(fnc)                                               \DEFN_BIN_FNC_T(fnc,int64)                                                     \DEFN_BIN_FNC_T(fnc,uint64)                                                    \DEFN_BIN_FNC_T(fnc,const sc_int_base&)                                        \DEFN_BIN_FNC_T(fnc,const sc_uint_base&)                                       \DEFN_BIN_FNC_T(fnc,const sc_signed&)                                          \DEFN_BIN_FNC_T(fnc,const sc_unsigned&)#else#define DEFN_BIN_FNC_OTHER(fnc)#endif#define DEFN_BIN_FNC(fnc)                                                     \inline                                                                        \void                                                                          \fnc( sc_fxval& c, const sc_fxval& a, const sc_fxval& b )                      \{                                                                             \    SC_FXVAL_OBSERVER_READ_( a )                                              \    SC_FXVAL_OBSERVER_READ_( b )                                              \    delete c.m_rep;                                                           \    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep );                 \    SC_FXVAL_OBSERVER_WRITE_( c )                                             \}                                                                             \                                                                              \DEFN_BIN_FNC_T(fnc,int)                                                       \DEFN_BIN_FNC_T(fnc,unsigned int)                                              \DEFN_BIN_FNC_T(fnc,long)                                                      \DEFN_BIN_FNC_T(fnc,unsigned long)                                             \DEFN_BIN_FNC_T(fnc,double)                                                    \DEFN_BIN_FNC_T(fnc,const char*)                                               \DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&)                                      \DEFN_BIN_FNC_OTHER(fnc)DEFN_BIN_FNC(mult)DEFN_BIN_FNC(div)DEFN_BIN_FNC(add)DEFN_BIN_FNC(sub)#undef DEFN_BIN_FNC_T#undef DEFN_BIN_FNC_OTHER#undef DEFN_BIN_FNCinlinevoidlshift( sc_fxval& c, const sc_fxval& a, int b ){    SC_FXVAL_OBSERVER_READ_( a )    delete c.m_rep;    c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );    SC_FXVAL_OBSERVER_WRITE_( c )}inlinevoidrshift( sc_fxval& c, const sc_fxval& a, int b ){    SC_FXVAL_OBSERVER_READ_( a )    delete c.m_rep;    c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );    SC_FXVAL_OBSERVER_WRITE_( c )}// relational (including equality) operators#define DEFN_REL_OP_T(op,ret,tp)                                              \inline                                                                        \bool                                                                          \operator op ( const sc_fxval& a, tp b )                                       \{                                                                             \    SC_FXVAL_OBSERVER_READ_( a )                                              \    sc_fxval tmp( b );                                                        \    int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep );                \    return ( ret );                                                           \}                                                                             \                                                                              \inline                                                                        \bool                                                                          \operator op ( tp a, const sc_fxval& b )                                       \{                                                                             \    SC_FXVAL_OBSERVER_READ_( b )                                              \    sc_fxval tmp( a );                                                        \    int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep );                \    return ( ret );                                                           \}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -