📄 sc_fxval.h
字号:
#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_REL_OP_OTHER(op,ret) \DEFN_REL_OP_T(op,ret,int64) \DEFN_REL_OP_T(op,ret,uint64) \DEFN_REL_OP_T(op,ret,const sc_int_base&) \DEFN_REL_OP_T(op,ret,const sc_uint_base&) \DEFN_REL_OP_T(op,ret,const sc_signed&) \DEFN_REL_OP_T(op,ret,const sc_unsigned&)#else#define DEFN_REL_OP_OTHER(op,ret)#endif#define DEFN_REL_OP(op,ret) \inline \bool \operator op ( const sc_fxval& a, const sc_fxval& b) \{ \ SC_FXVAL_OBSERVER_READ_( a ) \ SC_FXVAL_OBSERVER_READ_( b ) \ int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep ); \ return ( ret ); \} \ \DEFN_REL_OP_T(op,ret,int) \DEFN_REL_OP_T(op,ret,unsigned int) \DEFN_REL_OP_T(op,ret,long) \DEFN_REL_OP_T(op,ret,unsigned long) \DEFN_REL_OP_T(op,ret,double) \DEFN_REL_OP_T(op,ret,const char*) \DEFN_REL_OP_T(op,ret,const sc_fxval_fast&) \DEFN_REL_OP_OTHER(op,ret)DEFN_REL_OP(<,result < 0)DEFN_REL_OP(<=,result <= 0)DEFN_REL_OP(>,result > 0 && result != 2)DEFN_REL_OP(>=,result >= 0 && result != 2)DEFN_REL_OP(==,result == 0)DEFN_REL_OP(!=,result != 0)#undef DEFN_REL_OP_T#undef DEFN_REL_OP_OTHER#undef DEFN_REL_OP// assignment operatorsinlinesc_fxval&sc_fxval::operator = ( const sc_fxval& a ){ if( &a != this ) { SC_FXVAL_OBSERVER_READ_( a ) *m_rep = *a.m_rep; SC_FXVAL_OBSERVER_WRITE_( *this ) } return *this;}#define DEFN_ASN_OP_T(tp) \inline \sc_fxval& \sc_fxval::operator = ( tp b ) \{ \ sc_fxval tmp( b ); \ *m_rep = *tmp.m_rep; \ SC_FXVAL_OBSERVER_WRITE_( *this ) \ return *this; \}DEFN_ASN_OP_T(int)DEFN_ASN_OP_T(unsigned int)DEFN_ASN_OP_T(long)DEFN_ASN_OP_T(unsigned long)DEFN_ASN_OP_T(double)DEFN_ASN_OP_T(const char*)DEFN_ASN_OP_T(const sc_fxval_fast&)#ifndef SC_FX_EXCLUDE_OTHERDEFN_ASN_OP_T(int64)DEFN_ASN_OP_T(uint64)DEFN_ASN_OP_T(const sc_int_base&)DEFN_ASN_OP_T(const sc_uint_base&)DEFN_ASN_OP_T(const sc_signed&)DEFN_ASN_OP_T(const sc_unsigned&)#endif#undef DEFN_ASN_OP_T#define DEFN_ASN_OP_T(op,fnc,tp) \inline \sc_fxval& \sc_fxval::operator op ( tp b ) \{ \ SC_FXVAL_OBSERVER_READ_( *this ) \ sc_fxval tmp( b ); \ scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep ); \ delete m_rep; \ m_rep = new_rep; \ SC_FXVAL_OBSERVER_WRITE_( *this ) \ return *this; \}#ifndef SC_FX_EXCLUDE_OTHER#define DEFN_ASN_OP_OTHER(op,fnc) \DEFN_ASN_OP_T(op,fnc,int64) \DEFN_ASN_OP_T(op,fnc,uint64) \DEFN_ASN_OP_T(op,fnc,const sc_int_base&) \DEFN_ASN_OP_T(op,fnc,const sc_uint_base&) \DEFN_ASN_OP_T(op,fnc,const sc_signed&) \DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)#else#define DEFN_ASN_OP_OTHER(op,fnc)#endif#define DEFN_ASN_OP(op,fnc) \inline \sc_fxval& \sc_fxval::operator op ( const sc_fxval& b ) \{ \ SC_FXVAL_OBSERVER_READ_( *this ) \ SC_FXVAL_OBSERVER_READ_( b ) \ scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep ); \ delete m_rep; \ m_rep = new_rep; \ SC_FXVAL_OBSERVER_WRITE_( *this ) \ return *this; \} \ \DEFN_ASN_OP_T(op,fnc,int) \DEFN_ASN_OP_T(op,fnc,unsigned int) \DEFN_ASN_OP_T(op,fnc,long) \DEFN_ASN_OP_T(op,fnc,unsigned long) \DEFN_ASN_OP_T(op,fnc,double) \DEFN_ASN_OP_T(op,fnc,const char*) \DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&) \DEFN_ASN_OP_OTHER(op,fnc)DEFN_ASN_OP(*=,mult)DEFN_ASN_OP(/=,div)DEFN_ASN_OP(+=,add)DEFN_ASN_OP(-=,sub)#undef DEFN_ASN_OP_T#undef DEFN_ASN_OP_OTHER#undef DEFN_ASN_OPinlinesc_fxval&sc_fxval::operator <<= ( int b ){ SC_FXVAL_OBSERVER_READ_( *this ) m_rep->lshift( b ); SC_FXVAL_OBSERVER_WRITE_( *this ) return *this;}inlinesc_fxval&sc_fxval::operator >>= ( int b ){ SC_FXVAL_OBSERVER_READ_( *this ) m_rep->rshift( b ); SC_FXVAL_OBSERVER_WRITE_( *this ) return *this;}// auto-increment and auto-decrementinlineconst sc_fxvalsc_fxval::operator ++ ( int ){ sc_fxval c = *this; (*this) += 1; return c;}inlineconst sc_fxvalsc_fxval::operator -- ( int ){ sc_fxval c = *this; (*this) -= 1; return c;}inlinesc_fxval&sc_fxval::operator ++ (){ (*this) += 1; return *this;}inlinesc_fxval&sc_fxval::operator -- (){ (*this) -= 1; return *this;}// implicit conversioninlinesc_fxval::operator double() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->to_double();}// explicit conversion to primitive typesinlineshortsc_fxval::to_short() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<short>( m_rep->to_double() );}inlineunsigned shortsc_fxval::to_ushort() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<unsigned short>( m_rep->to_double() );}inlineintsc_fxval::to_int() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<int>( m_rep->to_double() );}inlineint64sc_fxval::to_int64() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<int64>( m_rep->to_double() );}inlineuint64sc_fxval::to_uint64() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<uint64>( m_rep->to_double() );}inlinelongsc_fxval::to_long() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<long>( m_rep->to_double() );}inlineunsigned intsc_fxval::to_uint() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<unsigned int>( m_rep->to_double() );}inlineunsigned longsc_fxval::to_ulong() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<unsigned long>( m_rep->to_double() );}inlinefloatsc_fxval::to_float() const{ SC_FXVAL_OBSERVER_READ_( *this ) return static_cast<float>( m_rep->to_double() );}inlinedoublesc_fxval::to_double() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->to_double();}// query valueinlineboolsc_fxval::is_neg() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->is_neg();}inlineboolsc_fxval::is_zero() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->is_zero();}inlineboolsc_fxval::is_nan() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->is_nan();}inlineboolsc_fxval::is_inf() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->is_inf();}inlineboolsc_fxval::is_normal() const{ SC_FXVAL_OBSERVER_READ_( *this ) return m_rep->is_normal();}inlineboolsc_fxval::rounding_flag() const{ return m_rep->rounding_flag();}// internal use only;inlineboolsc_fxval::get_bit( int i ) const{ return m_rep->get_bit( i );}// protected methods and friend functionsinlinevoidsc_fxval::get_type( int& wl, int& iwl, sc_enc& enc ) const{ m_rep->get_type( wl, iwl, enc );}inlineconst sc_fxvalsc_fxval::quantization( const scfx_params& params, bool& q_flag ) const{ return sc_fxval( sc_dt::quantization_scfx_rep( *m_rep, params, q_flag ) );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -