📄 sc_fxval.h
字号:
const std::string to_dec() const; const std::string to_bin() const; const std::string to_oct() const; const std::string to_hex() const; // query value bool is_neg() const; bool is_zero() const; bool is_nan() const; bool is_inf() const; bool is_normal() const; bool rounding_flag() const; // print or dump content void print( ::std::ostream& = ::std::cout ) const; void scan( ::std::istream& = ::std::cin ); void dump( ::std::ostream& = ::std::cout ) const; // internal use only; bool get_bit( int ) const;protected: sc_fxval_observer* lock_observer() const; void unlock_observer( sc_fxval_observer* ) const; void get_type( int&, int&, sc_enc& ) const; const sc_fxval quantization( const scfx_params&, bool& ) const; const sc_fxval overflow( const scfx_params&, bool& ) const;private: scfx_rep* m_rep; mutable sc_fxval_observer* m_observer;};// ----------------------------------------------------------------------------// CLASS : sc_fxval_fast//// Fixed-point value type; limited precision.// ----------------------------------------------------------------------------class sc_fxval_fast{ friend class sc_fxnum_fast;protected: sc_fxval_fast_observer* observer() const;public: explicit sc_fxval_fast( sc_fxval_fast_observer* = 0 ); sc_fxval_fast( int, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( unsigned int, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( long, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( unsigned long, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( double, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( const char*, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( const sc_fxval&, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( const sc_fxval_fast&, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( const sc_fxnum&, sc_fxval_fast_observer* = 0 ); sc_fxval_fast( const sc_fxnum_fast&, sc_fxval_fast_observer* = 0 );#ifndef SC_FX_EXCLUDE_OTHER explicit sc_fxval_fast( int64, sc_fxval_fast_observer* = 0 ); explicit sc_fxval_fast( uint64, sc_fxval_fast_observer* = 0 ); explicit sc_fxval_fast( const sc_int_base&, sc_fxval_fast_observer* = 0 ); explicit sc_fxval_fast( const sc_uint_base&, sc_fxval_fast_observer* = 0 ); explicit sc_fxval_fast( const sc_signed&, sc_fxval_fast_observer* = 0 ); explicit sc_fxval_fast( const sc_unsigned&, sc_fxval_fast_observer* = 0 );#endif ~sc_fxval_fast(); // internal use only; double get_val() const; void set_val( double ); // unary operators const sc_fxval_fast operator - () const; const sc_fxval_fast& operator + () const; // unary functions friend void neg( sc_fxval_fast&, const sc_fxval_fast& ); // binary operators#define DECL_BIN_OP_T(op,tp) \ friend const sc_fxval_fast operator op ( const sc_fxval_fast&, tp ); \ friend const sc_fxval_fast operator op ( tp, const sc_fxval_fast& );#ifndef SC_FX_EXCLUDE_OTHER#define DECL_BIN_OP_OTHER(op) \ DECL_BIN_OP_T(op,int64) \ DECL_BIN_OP_T(op,uint64) \ DECL_BIN_OP_T(op,const sc_int_base&) \ DECL_BIN_OP_T(op,const sc_uint_base&) \ DECL_BIN_OP_T(op,const sc_signed&) \ DECL_BIN_OP_T(op,const sc_unsigned&)#else#define DECL_BIN_OP_OTHER(op)#endif#define DECL_BIN_OP(op,dummy) \ friend const sc_fxval_fast operator op ( const sc_fxval_fast&, \ const sc_fxval_fast& ); \ DECL_BIN_OP_T(op,int) \ DECL_BIN_OP_T(op,unsigned int) \ DECL_BIN_OP_T(op,long) \ DECL_BIN_OP_T(op,unsigned long) \ DECL_BIN_OP_T(op,double) \ DECL_BIN_OP_T(op,const char*) \ DECL_BIN_OP_OTHER(op) DECL_BIN_OP(*,mult) DECL_BIN_OP(+,add) DECL_BIN_OP(-,sub)// don't use macro// DECL_BIN_OP(/,div) friend const sc_fxval_fast operator / ( const sc_fxval_fast&, const sc_fxval_fast& ); DECL_BIN_OP_T(/,int) DECL_BIN_OP_T(/,unsigned int) DECL_BIN_OP_T(/,long) DECL_BIN_OP_T(/,unsigned long) DECL_BIN_OP_T(/,double) DECL_BIN_OP_T(/,const char*)// DECL_BIN_OP_OTHER(/)#ifndef SC_FX_EXCLUDE_OTHER DECL_BIN_OP_T(/,int64) \ DECL_BIN_OP_T(/,uint64) \ DECL_BIN_OP_T(/,const sc_int_base&) \ DECL_BIN_OP_T(/,const sc_uint_base&) \ DECL_BIN_OP_T(/,const sc_signed&) \ DECL_BIN_OP_T(/,const sc_unsigned&)#endif#undef DECL_BIN_OP_T#undef DECL_BIN_OP_OTHER#undef DECL_BIN_OP friend const sc_fxval_fast operator << ( const sc_fxval_fast&, int ); friend const sc_fxval_fast operator >> ( const sc_fxval_fast&, int ); // binary functions#define DECL_BIN_FNC_T(fnc,tp) \ friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&, tp ); \ friend void fnc ( sc_fxval_fast&, tp, const sc_fxval_fast& );#ifndef SC_FX_EXCLUDE_OTHER#define DECL_BIN_FNC_OTHER(fnc) \ DECL_BIN_FNC_T(fnc,int64) \ DECL_BIN_FNC_T(fnc,uint64) \ DECL_BIN_FNC_T(fnc,const sc_int_base&) \ DECL_BIN_FNC_T(fnc,const sc_uint_base&) \ DECL_BIN_FNC_T(fnc,const sc_signed&) \ DECL_BIN_FNC_T(fnc,const sc_unsigned&)#else#define DECL_BIN_FNC_OTHER(fnc)#endif#define DECL_BIN_FNC(fnc) \ friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&, \ const sc_fxval_fast& ); \ DECL_BIN_FNC_T(fnc,int) \ DECL_BIN_FNC_T(fnc,unsigned int) \ DECL_BIN_FNC_T(fnc,long) \ DECL_BIN_FNC_T(fnc,unsigned long) \ DECL_BIN_FNC_T(fnc,double) \ DECL_BIN_FNC_T(fnc,const char*) \ DECL_BIN_FNC_T(fnc,const sc_fxval&) \ DECL_BIN_FNC_T(fnc,const sc_fxnum&) \ DECL_BIN_FNC_OTHER(fnc) DECL_BIN_FNC(mult) DECL_BIN_FNC(div) DECL_BIN_FNC(add) DECL_BIN_FNC(sub)#undef DECL_BIN_FNC_T#undef DECL_BIN_FNC_OTHER#undef DECL_BIN_FNC friend void lshift( sc_fxval_fast&, const sc_fxval_fast&, int ); friend void rshift( sc_fxval_fast&, const sc_fxval_fast&, int ); // relational (including equality) operators#define DECL_REL_OP_T(op,tp) \ friend bool operator op ( const sc_fxval_fast&, tp ); \ friend bool operator op ( tp, const sc_fxval_fast& );#ifndef SC_FX_EXCLUDE_OTHER#define DECL_REL_OP_OTHER(op) \ DECL_REL_OP_T(op,int64) \ DECL_REL_OP_T(op,uint64) \ DECL_REL_OP_T(op,const sc_int_base&) \ DECL_REL_OP_T(op,const sc_uint_base&) \ DECL_REL_OP_T(op,const sc_signed&) \ DECL_REL_OP_T(op,const sc_unsigned&)#else#define DECL_REL_OP_OTHER(op)#endif#define DECL_REL_OP(op) \ friend bool operator op ( const sc_fxval_fast&, const sc_fxval_fast& ); \ DECL_REL_OP_T(op,int) \ DECL_REL_OP_T(op,unsigned int) \ DECL_REL_OP_T(op,long) \ DECL_REL_OP_T(op,unsigned long) \ DECL_REL_OP_T(op,double) \ DECL_REL_OP_T(op,const char*) \ DECL_REL_OP_OTHER(op) DECL_REL_OP(<) DECL_REL_OP(<=) DECL_REL_OP(>) DECL_REL_OP(>=) DECL_REL_OP(==) DECL_REL_OP(!=)#undef DECL_REL_OP_T#undef DECL_REL_OP_OTHER#undef DECL_REL_OP // assignment operators#define DECL_ASN_OP_T(op,tp) \ sc_fxval_fast& operator op( tp );#ifndef SC_FX_EXCLUDE_OTHER#define DECL_ASN_OP_OTHER(op) \ DECL_ASN_OP_T(op,int64) \ DECL_ASN_OP_T(op,uint64) \ DECL_ASN_OP_T(op,const sc_int_base&) \ DECL_ASN_OP_T(op,const sc_uint_base&) \ DECL_ASN_OP_T(op,const sc_signed&) \ DECL_ASN_OP_T(op,const sc_unsigned&)#else#define DECL_ASN_OP_OTHER(op)#endif#define DECL_ASN_OP(op) \ DECL_ASN_OP_T(op,int) \ DECL_ASN_OP_T(op,unsigned int) \ DECL_ASN_OP_T(op,long) \ DECL_ASN_OP_T(op,unsigned long) \ DECL_ASN_OP_T(op,double) \ DECL_ASN_OP_T(op,const char*) \ DECL_ASN_OP_T(op,const sc_fxval&) \ DECL_ASN_OP_T(op,const sc_fxval_fast&) \ DECL_ASN_OP_T(op,const sc_fxnum&) \ DECL_ASN_OP_T(op,const sc_fxnum_fast&) \ DECL_ASN_OP_OTHER(op) DECL_ASN_OP(=) DECL_ASN_OP(*=) DECL_ASN_OP(/=) DECL_ASN_OP(+=) DECL_ASN_OP(-=) DECL_ASN_OP_T(<<=,int) DECL_ASN_OP_T(>>=,int)#undef DECL_ASN_OP_T#undef DECL_ASN_OP_OTHER#undef DECL_ASN_OP // auto-increment and auto-decrement const sc_fxval_fast operator ++ ( int ); const sc_fxval_fast operator -- ( int ); sc_fxval_fast& operator ++ (); sc_fxval_fast& operator -- (); // implicit conversion operator double() const; // necessary evil! // explicit conversion to primitive types short to_short() const; unsigned short to_ushort() const; int to_int() const; unsigned int to_uint() const; long to_long() const; unsigned long to_ulong() const; int64 to_int64() const; uint64 to_uint64() const; float to_float() const; double to_double() const; // explicit conversion to character string const std::string to_string() const; const std::string to_string( sc_numrep ) const; const std::string to_string( sc_numrep, bool ) const; const std::string to_string( sc_fmt ) const; const std::string to_string( sc_numrep, sc_fmt ) const; const std::string to_string( sc_numrep, bool, sc_fmt ) const; const std::string to_dec() const; const std::string to_bin() const; const std::string to_oct() const; const std::string to_hex() const; // query value bool is_neg() const; bool is_zero() const; bool is_nan() const; bool is_inf() const; bool is_normal() const; bool rounding_flag() const; // print or dump content void print( ::std::ostream& = ::std::cout ) const; void scan( ::std::istream& = ::std::cin ); void dump( ::std::ostream& = ::std::cout ) const; // internal use only; bool get_bit( int ) const;protected: sc_fxval_fast_observer* lock_observer() const; void unlock_observer( sc_fxval_fast_observer* ) const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -