src/sysc/datatypes/fx/sc_fxnum.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_fxnum.h - 
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc.
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033 
00034  *****************************************************************************/
00035 
00036 #ifndef SC_FXNUM_H
00037 #define SC_FXNUM_H
00038 
00039 
00040 #include "sysc/datatypes/bit/sc_lv_base.h"
00041 #include "sysc/datatypes/fx/sc_fxval.h"
00042 #include "sysc/datatypes/fx/scfx_params.h"
00043 #include "sysc/datatypes/fx/sc_fxnum_observer.h"
00044 
00045 
00046 namespace sc_core {
00047         class vcd_sc_fxnum_trace;
00048         class vcd_sc_fxnum_fast_trace;
00049         class wif_sc_fxnum_trace;
00050         class wif_sc_fxnum_fast_trace;
00051 };
00052 
00053 
00054 namespace sc_dt
00055 {
00056 
00057 // classes defined in this module
00058 class sc_fxnum_bitref;
00059 class sc_fxnum_fast_bitref;
00060 class sc_fxnum_subref;
00061 class sc_fxnum_fast_subref;
00062 class sc_fxnum;
00063 class sc_fxnum_fast;
00064 
00065 
00066 // ----------------------------------------------------------------------------
00067 //  CLASS : sc_fxnum_bitref
00068 //
00069 //  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
00070 // ----------------------------------------------------------------------------
00071 
00072 class sc_fxnum_bitref
00073 {
00074     friend class sc_fxnum;
00075     friend class sc_fxnum_fast_bitref;
00076 
00077 
00078     bool get() const;
00079     void set( bool );
00080 
00081 
00082     // constructor
00083 
00084     sc_fxnum_bitref( sc_fxnum&, int );
00085 
00086 public:
00087 
00088     // copy constructor
00089 
00090     sc_fxnum_bitref( const sc_fxnum_bitref& );
00091 
00092 
00093     // assignment operators
00094 
00095 #define DECL_ASN_OP_T(op,tp)                                                  \
00096     sc_fxnum_bitref& operator op ( tp );
00097 
00098 #define DECL_ASN_OP(op)                                                       \
00099     DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
00100     DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
00101     DECL_ASN_OP_T(op,const sc_bit&)                                           \
00102     DECL_ASN_OP_T(op,bool)
00103 
00104     DECL_ASN_OP(=)
00105 
00106     DECL_ASN_OP(&=)
00107     DECL_ASN_OP(|=)
00108     DECL_ASN_OP(^=)
00109 
00110 #undef DECL_ASN_OP_T
00111 #undef DECL_ASN_OP
00112 
00113 
00114     // implicit conversion
00115 
00116     operator bool() const;
00117 
00118 
00119     // print or dump content
00120 
00121     void print( ::std::ostream& = ::std::cout ) const;
00122     void scan( ::std::istream& = ::std::cin );
00123     void dump( ::std::ostream& = ::std::cout ) const;
00124 
00125 private:
00126 
00127     sc_fxnum& m_num;
00128     int       m_idx;
00129 
00130 private:
00131 
00132     // disabled
00133     sc_fxnum_bitref();
00134 };
00135 
00136 
00137 // ----------------------------------------------------------------------------
00138 //  CLASS : sc_fxnum_fast_bitref
00139 //
00140 //  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
00141 // ----------------------------------------------------------------------------
00142 
00143 class sc_fxnum_fast_bitref
00144 {
00145     friend class sc_fxnum_fast;
00146     friend class sc_fxnum_bitref;
00147 
00148 
00149     bool get() const;
00150     void set( bool );
00151 
00152 
00153     // constructor
00154 
00155     sc_fxnum_fast_bitref( sc_fxnum_fast&, int );
00156 
00157 public:
00158 
00159     // copy constructor
00160 
00161     sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& );
00162 
00163 
00164     // assignment operators
00165 
00166 #define DECL_ASN_OP_T(op,tp)                                                  \
00167     sc_fxnum_fast_bitref& operator op ( tp );
00168 
00169 #define DECL_ASN_OP(op)                                                       \
00170     DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
00171     DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
00172     DECL_ASN_OP_T(op,const sc_bit&)                                           \
00173     DECL_ASN_OP_T(op,bool)
00174 
00175     DECL_ASN_OP(=)
00176 
00177     DECL_ASN_OP(&=)
00178     DECL_ASN_OP(|=)
00179     DECL_ASN_OP(^=)
00180 
00181 #undef DECL_ASN_OP_T
00182 #undef DECL_ASN_OP
00183 
00184 
00185     // implicit conversion
00186 
00187     operator bool() const;
00188 
00189 
00190     // print or dump content
00191 
00192     void print( ::std::ostream& = ::std::cout ) const;
00193     void scan( ::std::istream& = ::std::cin );
00194     void dump( ::std::ostream& = ::std::cout ) const;
00195 
00196 private:
00197 
00198     sc_fxnum_fast& m_num;
00199     int            m_idx;
00200 
00201 private:
00202 
00203     // disabled
00204     sc_fxnum_fast_bitref();
00205 };
00206 
00207 
00208 // ----------------------------------------------------------------------------
00209 //  CLASS : sc_fxnum_subref
00210 //
00211 //  Proxy class for part-selection in class sc_fxnum,
00212 //  behaves like sc_bv_base.
00213 // ----------------------------------------------------------------------------
00214 
00215 class sc_fxnum_subref
00216 {
00217     friend class sc_fxnum;
00218     friend class sc_fxnum_fast_subref;
00219 
00220     bool get() const;
00221     bool set();
00222 
00223 
00224     // constructor
00225 
00226     sc_fxnum_subref( sc_fxnum&, int, int );
00227 
00228 public:
00229 
00230     // copy constructor
00231 
00232     sc_fxnum_subref( const sc_fxnum_subref& );
00233 
00234 
00235     // destructor
00236 
00237     ~sc_fxnum_subref();
00238 
00239 
00240     // assignment operators
00241 
00242 #define DECL_ASN_OP_T(tp)                                                     \
00243     sc_fxnum_subref& operator = ( tp );
00244 
00245     DECL_ASN_OP_T(const sc_fxnum_subref&)
00246     DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
00247     DECL_ASN_OP_T(const sc_bv_base&)
00248     DECL_ASN_OP_T(const sc_lv_base&)
00249     DECL_ASN_OP_T(const char*)
00250     DECL_ASN_OP_T(const bool*)
00251     DECL_ASN_OP_T(const sc_signed&)
00252     DECL_ASN_OP_T(const sc_unsigned&)
00253     DECL_ASN_OP_T(const sc_int_base&)
00254     DECL_ASN_OP_T(const sc_uint_base&)
00255     DECL_ASN_OP_T(int64)
00256     DECL_ASN_OP_T(uint64)
00257     DECL_ASN_OP_T(int)
00258     DECL_ASN_OP_T(unsigned int)
00259     DECL_ASN_OP_T(long)
00260     DECL_ASN_OP_T(unsigned long)
00261     DECL_ASN_OP_T(char)
00262 
00263 #undef DECL_ASN_OP_T
00264 
00265 #define DECL_ASN_OP_T_A(op,tp)                                                \
00266     sc_fxnum_subref& operator op ## = ( tp );
00267 
00268 #define DECL_ASN_OP_A(op)                                                     \
00269     DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
00270     DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
00271     DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
00272     DECL_ASN_OP_T_A(op,const sc_lv_base&)
00273 
00274     DECL_ASN_OP_A(&)
00275     DECL_ASN_OP_A(|)
00276     DECL_ASN_OP_A(^)
00277 
00278 #undef DECL_ASN_OP_T_A
00279 #undef DECL_ASN_OP_A
00280 
00281 
00282     // relational operators
00283 
00284 #define DECL_REL_OP_T(op,tp)                                                  \
00285     friend bool operator op ( const sc_fxnum_subref&, tp );                   \
00286     friend bool operator op ( tp, const sc_fxnum_subref& );
00287 
00288 #define DECL_REL_OP(op)                                                       \
00289     friend bool operator op ( const sc_fxnum_subref&,                         \
00290                               const sc_fxnum_subref& );                       \
00291     friend bool operator op ( const sc_fxnum_subref&,                         \
00292                               const sc_fxnum_fast_subref& );                  \
00293     DECL_REL_OP_T(op,const sc_bv_base&)                                       \
00294     DECL_REL_OP_T(op,const sc_lv_base&)                                       \
00295     DECL_REL_OP_T(op,const char*)                                             \
00296     DECL_REL_OP_T(op,const bool*)                                             \
00297     DECL_REL_OP_T(op,const sc_signed&)                                        \
00298     DECL_REL_OP_T(op,const sc_unsigned&)                                      \
00299     DECL_REL_OP_T(op,int)                                                     \
00300     DECL_REL_OP_T(op,unsigned int)                                            \
00301     DECL_REL_OP_T(op,long)                                                    \
00302     DECL_REL_OP_T(op,unsigned long)
00303 
00304     DECL_REL_OP(==)
00305     DECL_REL_OP(!=)
00306 
00307 #undef DECL_REL_OP_T
00308 #undef DECL_REL_OP
00309 
00310 
00311     // reduce functions
00312 
00313     bool and_reduce() const;
00314     bool nand_reduce() const;
00315     bool or_reduce() const;
00316     bool nor_reduce() const;
00317     bool xor_reduce() const;
00318     bool xnor_reduce() const;
00319 
00320 
00321     // query parameter
00322 
00323     int length() const;
00324 
00325 
00326     // explicit conversions
00327 
00328     int           to_int() const;
00329     unsigned int  to_uint() const;
00330     long          to_long() const;
00331     unsigned long to_ulong() const;
00332     int64         to_int64() const;
00333     uint64        to_uint64() const;
00334 
00335 #ifdef SC_DT_DEPRECATED
00336     int           to_signed() const;
00337     unsigned int  to_unsigned() const;
00338 #endif
00339 
00340     const std::string to_string() const;
00341     const std::string to_string( sc_numrep ) const;
00342     const std::string to_string( sc_numrep, bool ) const;
00343 
00344 
00345     // implicit conversion
00346 
00347     operator sc_bv_base() const;
00348 
00349 
00350     // print or dump content
00351 
00352     void print( ::std::ostream& = ::std::cout ) const;
00353     void scan( ::std::istream& = ::std::cin );
00354     void dump( ::std::ostream& = ::std::cout ) const;
00355 
00356 private:
00357 
00358     sc_fxnum& m_num;
00359     int       m_from;
00360     int       m_to;
00361 
00362     sc_bv_base& m_bv;
00363 
00364 private:
00365 
00366     // disabled
00367     sc_fxnum_subref();
00368 };
00369 
00370 
00371 // ----------------------------------------------------------------------------
00372 //  CLASS : sc_fxnum_fast_subref
00373 //
00374 //  Proxy class for part-selection in class sc_fxnum_fast,
00375 //  behaves like sc_bv_base.
00376 // ----------------------------------------------------------------------------
00377 
00378 class sc_fxnum_fast_subref
00379 {
00380     friend class sc_fxnum_fast;
00381     friend class sc_fxnum_subref;
00382 
00383     bool get() const;
00384     bool set();
00385 
00386 
00387     // constructor
00388 
00389     sc_fxnum_fast_subref( sc_fxnum_fast&, int, int );
00390 
00391 public:
00392 
00393     // copy constructor
00394 
00395     sc_fxnum_fast_subref( const sc_fxnum_fast_subref& );
00396 
00397 
00398     // destructor
00399 
00400     ~sc_fxnum_fast_subref();
00401 
00402 
00403     // assignment operators
00404 
00405 #define DECL_ASN_OP_T(tp)                                                     \
00406     sc_fxnum_fast_subref& operator = ( tp );
00407 
00408     DECL_ASN_OP_T(const sc_fxnum_subref&)
00409     DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
00410     DECL_ASN_OP_T(const sc_bv_base&)
00411     DECL_ASN_OP_T(const sc_lv_base&)
00412     DECL_ASN_OP_T(const char*)
00413     DECL_ASN_OP_T(const bool*)
00414     DECL_ASN_OP_T(const sc_signed&)
00415     DECL_ASN_OP_T(const sc_unsigned&)
00416     DECL_ASN_OP_T(const sc_int_base&)
00417     DECL_ASN_OP_T(const sc_uint_base&)
00418     DECL_ASN_OP_T(int64)
00419     DECL_ASN_OP_T(uint64)
00420     DECL_ASN_OP_T(int)
00421     DECL_ASN_OP_T(unsigned int)
00422     DECL_ASN_OP_T(long)
00423     DECL_ASN_OP_T(unsigned long)
00424     DECL_ASN_OP_T(char)
00425 
00426 #undef DECL_ASN_OP_T
00427 
00428 #define DECL_ASN_OP_T_A(op,tp)                                                \
00429     sc_fxnum_fast_subref& operator op ## = ( tp );
00430 
00431 #define DECL_ASN_OP_A(op)                                                     \
00432     DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
00433     DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
00434     DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
00435     DECL_ASN_OP_T_A(op,const sc_lv_base&)
00436 
00437     DECL_ASN_OP_A(&)
00438     DECL_ASN_OP_A(|)
00439     DECL_ASN_OP_A(^)
00440 
00441 #undef DECL_ASN_OP_T_A
00442 #undef DECL_ASN_OP_A
00443 
00444 
00445     // relational operators
00446 
00447 #define DECL_REL_OP_T(op,tp)                                                  \
00448     friend bool operator op ( const sc_fxnum_fast_subref&, tp );              \
00449     friend bool operator op ( tp, const sc_fxnum_fast_subref& );
00450 
00451 #define DECL_REL_OP(op)                                                       \
00452     friend bool operator op ( const sc_fxnum_fast_subref&,                    \
00453                               const sc_fxnum_fast_subref& );                  \
00454     friend bool operator op ( const sc_fxnum_fast_subref&,                    \
00455                               const sc_fxnum_subref& );                       \
00456     DECL_REL_OP_T(op,const sc_bv_base&)                                       \
00457     DECL_REL_OP_T(op,const sc_lv_base&)                                       \
00458     DECL_REL_OP_T(op,const char*)                                             \
00459     DECL_REL_OP_T(op,const bool*)                                             \
00460     DECL_REL_OP_T(op,const sc_signed&)                                        \
00461     DECL_REL_OP_T(op,const sc_unsigned&)                                      \
00462     DECL_REL_OP_T(op,int)                                                     \
00463     DECL_REL_OP_T(op,unsigned int)                                            \
00464     DECL_REL_OP_T(op,long)                                                    \
00465     DECL_REL_OP_T(op,unsigned long)
00466 
00467     DECL_REL_OP(==)
00468     DECL_REL_OP(!=)
00469 
00470 #undef DECL_REL_OP_T
00471 #undef DECL_REL_OP
00472 
00473 
00474     // reduce functions
00475 
00476     bool and_reduce() const;
00477     bool nand_reduce() const;
00478     bool or_reduce() const;
00479     bool nor_reduce() const;
00480     bool xor_reduce() const;
00481     bool xnor_reduce() const;
00482 
00483 
00484     // query parameter
00485 
00486     int length() const;
00487 
00488 
00489     // explicit conversions
00490 
00491     int           to_int() const;
00492     unsigned int  to_uint() const;
00493     long          to_long() const;
00494     unsigned long to_ulong() const;
00495     int64         to_int64() const;
00496     uint64        to_uint64() const;
00497 
00498 #ifdef SC_DT_DEPRECATED
00499     int           to_signed() const;
00500     unsigned int  to_unsigned() const;
00501 #endif
00502 
00503     const std::string to_string() const;
00504     const std::string to_string( sc_numrep ) const;
00505     const std::string to_string( sc_numrep, bool ) const;
00506 
00507 
00508     // implicit conversion
00509 
00510     operator sc_bv_base() const;
00511 
00512 
00513     // print or dump content
00514 
00515     void print( ::std::ostream& = ::std::cout ) const;
00516     void scan( ::std::istream& = ::std::cin );
00517     void dump( ::std::ostream& = ::std::cout ) const;
00518 
00519 private:
00520 
00521     sc_fxnum_fast& m_num;
00522     int            m_from;
00523     int            m_to;
00524 
00525     sc_bv_base& m_bv;
00526 
00527 private:
00528 
00529     // disabled
00530     sc_fxnum_fast_subref();
00531 };
00532 
00533 
00534 // ----------------------------------------------------------------------------
00535 //  CLASS : sc_fxnum
00536 //
00537 //  Base class for the fixed-point types; arbitrary precision.
00538 // ----------------------------------------------------------------------------
00539 
00540 class sc_fxnum
00541 {
00542     friend class sc_fxval;
00543 
00544     friend class sc_fxnum_bitref;
00545     friend class sc_fxnum_subref;
00546     friend class sc_fxnum_fast_bitref;
00547     friend class sc_fxnum_fast_subref;
00548 
00549     friend class sc_core::vcd_sc_fxnum_trace;
00550     friend class sc_core::wif_sc_fxnum_trace;
00551 
00552 protected:
00553 
00554     sc_fxnum_observer* observer() const;
00555 
00556 
00557     void cast();
00558 
00559 
00560     // constructors
00561 
00562     sc_fxnum( const sc_fxtype_params&,
00563               sc_enc,
00564               const sc_fxcast_switch&,
00565               sc_fxnum_observer* );
00566 
00567 #define DECL_CTOR_T(tp)                                                       \
00568     sc_fxnum( tp,                                                             \
00569               const sc_fxtype_params&,                                        \
00570               sc_enc,                                                         \
00571               const sc_fxcast_switch&,                                        \
00572               sc_fxnum_observer* );
00573 
00574     DECL_CTOR_T(int)
00575     DECL_CTOR_T(unsigned int)
00576     DECL_CTOR_T(long)
00577     DECL_CTOR_T(unsigned long)
00578     DECL_CTOR_T(double)
00579     DECL_CTOR_T(const char*)
00580     DECL_CTOR_T(const sc_fxval&)
00581     DECL_CTOR_T(const sc_fxval_fast&)
00582     DECL_CTOR_T(const sc_fxnum&)
00583     DECL_CTOR_T(const sc_fxnum_fast&)
00584 #ifndef SC_FX_EXCLUDE_OTHER
00585     DECL_CTOR_T(int64)
00586     DECL_CTOR_T(uint64)
00587     DECL_CTOR_T(const sc_int_base&)
00588     DECL_CTOR_T(const sc_uint_base&)
00589     DECL_CTOR_T(const sc_signed&)
00590     DECL_CTOR_T(const sc_unsigned&)
00591 #endif
00592 
00593 #undef DECL_CTOR_T
00594 
00595     ~sc_fxnum();
00596 
00597 
00598     // internal use only;
00599     const scfx_rep* get_rep() const;
00600 
00601 public:
00602 
00603     // unary operators
00604 
00605     const sc_fxval operator - () const;
00606     const sc_fxval operator + () const;
00607 
00608 
00609     // unary functions
00610 
00611     friend void neg( sc_fxval&, const sc_fxnum& );
00612     friend void neg( sc_fxnum&, const sc_fxnum& );
00613 
00614 
00615     // binary operators
00616 
00617 #define DECL_BIN_OP_T(op,tp)                                                  \
00618     friend const sc_fxval operator op ( const sc_fxnum&, tp );                \
00619     friend const sc_fxval operator op ( tp, const sc_fxnum& );
00620 
00621 #ifndef SC_FX_EXCLUDE_OTHER
00622 #define DECL_BIN_OP_OTHER(op)                                                 \
00623     DECL_BIN_OP_T(op,int64)                                                   \
00624     DECL_BIN_OP_T(op,uint64)                                                  \
00625     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
00626     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
00627     DECL_BIN_OP_T(op,const sc_signed&)                                        \
00628     DECL_BIN_OP_T(op,const sc_unsigned&)
00629 #else
00630 #define DECL_BIN_OP_OTHER(op)
00631 #endif
00632 
00633 #define DECL_BIN_OP(op,dummy)                                                 \
00634     friend const sc_fxval operator op ( const sc_fxnum&, const sc_fxnum& );   \
00635     DECL_BIN_OP_T(op,int)                                                     \
00636     DECL_BIN_OP_T(op,unsigned int)                                            \
00637     DECL_BIN_OP_T(op,long)                                                    \
00638     DECL_BIN_OP_T(op,unsigned long)                                           \
00639     DECL_BIN_OP_T(op,double)                                                  \
00640     DECL_BIN_OP_T(op,const char*)                                             \
00641     DECL_BIN_OP_T(op,const sc_fxval&)                                         \
00642     DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
00643     DECL_BIN_OP_T(op,const sc_fxnum_fast&)                                    \
00644     DECL_BIN_OP_OTHER(op)
00645 
00646     DECL_BIN_OP(*,mult)
00647     DECL_BIN_OP(+,add)
00648     DECL_BIN_OP(-,sub)
00649 // don't use macros
00650 //    DECL_BIN_OP(/,div)
00651     friend const sc_fxval operator / ( const sc_fxnum&, const sc_fxnum& );
00652     DECL_BIN_OP_T(/,int)
00653     DECL_BIN_OP_T(/,unsigned int)
00654     DECL_BIN_OP_T(/,long)
00655     DECL_BIN_OP_T(/,unsigned long)
00656     DECL_BIN_OP_T(/,double)
00657     DECL_BIN_OP_T(/,const char*)
00658     DECL_BIN_OP_T(/,const sc_fxval&)
00659     DECL_BIN_OP_T(/,const sc_fxval_fast&)
00660     DECL_BIN_OP_T(/,const sc_fxnum_fast&)
00661 //    DECL_BIN_OP_OTHER(op)
00662 #ifndef SC_FX_EXCLUDE_OTHER
00663     DECL_BIN_OP_T(/,int64)
00664     DECL_BIN_OP_T(/,uint64)
00665     DECL_BIN_OP_T(/,const sc_int_base&)
00666     DECL_BIN_OP_T(/,const sc_uint_base&)
00667     DECL_BIN_OP_T(/,const sc_signed&)
00668     DECL_BIN_OP_T(/,const sc_unsigned&)
00669 #endif
00670 
00671 #undef DECL_BIN_OP_T
00672 #undef DECL_BIN_OP_OTHER
00673 #undef DECL_BIN_OP
00674 
00675     friend const sc_fxval operator << ( const sc_fxnum&, int );
00676     friend const sc_fxval operator >> ( const sc_fxnum&, int );
00677 
00678 
00679     // binary functions
00680 
00681 #define DECL_BIN_FNC_T(fnc,tp)                                                \
00682     friend void fnc ( sc_fxval&, const sc_fxnum&, tp );                       \
00683     friend void fnc ( sc_fxval&, tp, const sc_fxnum& );                       \
00684     friend void fnc ( sc_fxnum&, const sc_fxnum&, tp );                       \
00685     friend void fnc ( sc_fxnum&, tp, const sc_fxnum& );
00686 
00687 #ifndef SC_FX_EXCLUDE_OTHER
00688 #define DECL_BIN_FNC_OTHER(fnc)                                               \
00689     DECL_BIN_FNC_T(fnc,int64)                                                 \
00690     DECL_BIN_FNC_T(fnc,uint64)                                                \
00691     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
00692     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
00693     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
00694     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
00695 #else
00696 #define DECL_BIN_FNC_OTHER(fnc)
00697 #endif
00698 
00699 #define DECL_BIN_FNC(fnc)                                                     \
00700     friend void fnc ( sc_fxval&, const sc_fxnum&, const sc_fxnum& );          \
00701     friend void fnc ( sc_fxnum&, const sc_fxnum&, const sc_fxnum& );          \
00702     DECL_BIN_FNC_T(fnc,int)                                                   \
00703     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
00704     DECL_BIN_FNC_T(fnc,long)                                                  \
00705     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
00706     DECL_BIN_FNC_T(fnc,double)                                                \
00707     DECL_BIN_FNC_T(fnc,const char*)                                           \
00708     DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
00709     DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
00710     DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                  \
00711     DECL_BIN_FNC_OTHER(fnc)
00712 
00713     DECL_BIN_FNC(mult)
00714     DECL_BIN_FNC(div)
00715     DECL_BIN_FNC(add)
00716     DECL_BIN_FNC(sub)
00717 
00718 #undef DECL_BIN_FNC_T
00719 #undef DECL_BIN_FNC_OTHER
00720 #undef DECL_BIN_FNC
00721 
00722     friend void lshift( sc_fxval&, const sc_fxnum&, int );
00723     friend void rshift( sc_fxval&, const sc_fxnum&, int );
00724     friend void lshift( sc_fxnum&, const sc_fxnum&, int );
00725     friend void rshift( sc_fxnum&, const sc_fxnum&, int );
00726 
00727 
00728     // relational (including equality) operators
00729 
00730 #define DECL_REL_OP_T(op,tp)                                                  \
00731     friend bool operator op ( const sc_fxnum&, tp );                          \
00732     friend bool operator op ( tp, const sc_fxnum& );
00733 
00734 #ifndef SC_FX_EXCLUDE_OTHER
00735 #define DECL_REL_OP_OTHER(op)                                                 \
00736     DECL_REL_OP_T(op,int64)                                                   \
00737     DECL_REL_OP_T(op,uint64)                                                  \
00738     DECL_REL_OP_T(op,const sc_int_base&)                                      \
00739     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
00740     DECL_REL_OP_T(op,const sc_signed&)                                        \
00741     DECL_REL_OP_T(op,const sc_unsigned&)
00742 #else
00743 #define DECL_REL_OP_OTHER(op)
00744 #endif
00745 
00746 #define DECL_REL_OP(op)                                                       \
00747     friend bool operator op ( const sc_fxnum&, const sc_fxnum& );             \
00748     DECL_REL_OP_T(op,int)                                                     \
00749     DECL_REL_OP_T(op,unsigned int)                                            \
00750     DECL_REL_OP_T(op,long)                                                    \
00751     DECL_REL_OP_T(op,unsigned long)                                           \
00752     DECL_REL_OP_T(op,double)                                                  \
00753     DECL_REL_OP_T(op,const char*)                                             \
00754     DECL_REL_OP_T(op,const sc_fxval&)                                         \
00755     DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
00756     DECL_REL_OP_T(op,const sc_fxnum_fast&)                                    \
00757     DECL_REL_OP_OTHER(op)
00758 
00759     DECL_REL_OP(<)
00760     DECL_REL_OP(<=)
00761     DECL_REL_OP(>)
00762     DECL_REL_OP(>=)
00763     DECL_REL_OP(==)
00764     DECL_REL_OP(!=)
00765 
00766 #undef DECL_REL_OP_T
00767 #undef DECL_REL_OP_OTHER
00768 #undef DECL_REL_OP
00769 
00770 
00771     // assignment operators
00772 
00773 #define DECL_ASN_OP_T(op,tp)                                                  \
00774     sc_fxnum& operator op( tp );
00775 
00776 #ifndef SC_FX_EXCLUDE_OTHER
00777 #define DECL_ASN_OP_OTHER(op)                                                 \
00778     DECL_ASN_OP_T(op,int64)                                                   \
00779     DECL_ASN_OP_T(op,uint64)                                                  \
00780     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
00781     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
00782     DECL_ASN_OP_T(op,const sc_signed&)                                        \
00783     DECL_ASN_OP_T(op,const sc_unsigned&)
00784 #else
00785 #define DECL_ASN_OP_OTHER(op)
00786 #endif
00787 
00788 #define DECL_ASN_OP(op)                                                       \
00789     DECL_ASN_OP_T(op,int)                                                     \
00790     DECL_ASN_OP_T(op,unsigned int)                                            \
00791     DECL_ASN_OP_T(op,long)                                                    \
00792     DECL_ASN_OP_T(op,unsigned long)                                           \
00793     DECL_ASN_OP_T(op,double)                                                  \
00794     DECL_ASN_OP_T(op,const char*)                                             \
00795     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
00796     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
00797     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
00798     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
00799     DECL_ASN_OP_OTHER(op)
00800 
00801     DECL_ASN_OP(=)
00802 
00803     DECL_ASN_OP(*=)
00804     DECL_ASN_OP(/=)
00805     DECL_ASN_OP(+=)
00806     DECL_ASN_OP(-=)
00807 
00808     DECL_ASN_OP_T(<<=,int)
00809     DECL_ASN_OP_T(>>=,int)
00810 
00811 #undef DECL_ASN_OP_T
00812 #undef DECL_ASN_OP_OTHER
00813 #undef DECL_ASN_OP
00814 
00815 
00816     // auto-increment and auto-decrement
00817 
00818     const sc_fxval operator ++ ( int );
00819     const sc_fxval operator -- ( int );
00820 
00821     sc_fxnum& operator ++ ();
00822     sc_fxnum& operator -- ();
00823 
00824 
00825     // bit selection
00826 
00827     const sc_fxnum_bitref operator [] ( int ) const;
00828     sc_fxnum_bitref       operator [] ( int );
00829 
00830     const sc_fxnum_bitref bit( int ) const;
00831     sc_fxnum_bitref       bit( int );
00832 
00833 
00834     // part selection
00835 
00836     const sc_fxnum_subref operator () ( int, int ) const;
00837     sc_fxnum_subref       operator () ( int, int );
00838 
00839     const sc_fxnum_subref range( int, int ) const;
00840     sc_fxnum_subref       range( int, int );
00841 
00842 
00843     const sc_fxnum_subref operator () () const;
00844     sc_fxnum_subref       operator () ();
00845 
00846     const sc_fxnum_subref range() const;
00847     sc_fxnum_subref       range();
00848 
00849 
00850     // implicit conversion
00851 
00852     operator double() const;            // necessary evil!
00853 
00854 
00855     // explicit conversion to primitive types
00856 
00857     short          to_short() const;
00858     unsigned short to_ushort() const;
00859     int            to_int() const;
00860     unsigned int   to_uint() const;
00861     long           to_long() const;
00862     unsigned long  to_ulong() const;
00863     int64          to_int64() const;
00864     uint64         to_uint64() const;
00865     float          to_float() const;
00866     double         to_double() const;
00867 
00868 
00869     // explicit conversion to character string
00870 
00871     const std::string to_string() const;
00872     const std::string to_string( sc_numrep ) const;
00873     const std::string to_string( sc_numrep, bool ) const;
00874     const std::string to_string( sc_fmt ) const;
00875     const std::string to_string( sc_numrep, sc_fmt ) const;
00876     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
00877 
00878     const std::string to_dec() const;
00879     const std::string to_bin() const;
00880     const std::string to_oct() const;
00881     const std::string to_hex() const;
00882 
00883 
00884     // query value
00885 
00886     bool is_neg() const;
00887     bool is_zero() const;
00888 
00889     // internal use only;
00890     bool is_normal() const;
00891 
00892     bool quantization_flag() const;
00893     bool overflow_flag() const;
00894 
00895     const sc_fxval value() const;
00896 
00897 
00898     // query parameters
00899 
00900     int       wl() const;
00901     int       iwl() const;
00902     sc_q_mode q_mode() const;
00903     sc_o_mode o_mode() const;
00904     int       n_bits() const;
00905 
00906     const sc_fxtype_params& type_params() const;
00907 
00908     const sc_fxcast_switch& cast_switch() const;
00909 
00910 
00911     // print or dump content
00912 
00913     void print( ::std::ostream& = ::std::cout ) const;
00914     void scan( ::std::istream& = ::std::cin );
00915     void dump( ::std::ostream& = ::std::cout ) const;
00916 
00917 
00918     // internal use only;
00919     void observer_read() const;
00920 
00921 
00922     // internal use only;
00923     bool get_bit( int ) const;
00924 
00925 protected:
00926 
00927     bool set_bit( int, bool );
00928 
00929 
00930     bool get_slice( int, int, sc_bv_base& ) const;
00931     bool set_slice( int, int, const sc_bv_base& );
00932 
00933 
00934     sc_fxnum_observer* lock_observer() const;
00935     void unlock_observer( sc_fxnum_observer* ) const;
00936 
00937 private:
00938 
00939     scfx_rep*                  m_rep;
00940 
00941     scfx_params                m_params;
00942     bool                       m_q_flag;
00943     bool                       m_o_flag;
00944 
00945     mutable sc_fxnum_observer* m_observer;
00946 
00947 private:
00948 
00949     // disabled
00950     sc_fxnum();
00951     sc_fxnum( const sc_fxnum& );
00952 };
00953 
00954 
00955 // ----------------------------------------------------------------------------
00956 //  CLASS : sc_fxnum_fast
00957 //
00958 //  Base class for the fixed-point types; limited precision.
00959 // ----------------------------------------------------------------------------
00960 
00961 class sc_fxnum_fast
00962 {
00963     friend class sc_fxval_fast;
00964 
00965     friend class sc_fxnum_bitref;
00966     friend class sc_fxnum_subref;
00967     friend class sc_fxnum_fast_bitref;
00968     friend class sc_fxnum_fast_subref;
00969 
00970     friend class sc_core::vcd_sc_fxnum_fast_trace;
00971     friend class sc_core::wif_sc_fxnum_fast_trace;
00972 
00973 protected:
00974 
00975     sc_fxnum_fast_observer* observer() const;
00976 
00977 
00978     void cast();
00979 
00980 
00981     // constructors
00982 
00983     sc_fxnum_fast( const sc_fxtype_params&,
00984                    sc_enc,
00985                    const sc_fxcast_switch&,
00986                    sc_fxnum_fast_observer* );
00987 
00988 #define DECL_CTOR_T(tp)                                                       \
00989     sc_fxnum_fast( tp,                                                        \
00990                    const sc_fxtype_params&,                                   \
00991                    sc_enc,                                                    \
00992                    const sc_fxcast_switch&,                                   \
00993                    sc_fxnum_fast_observer* );
00994 
00995     DECL_CTOR_T(int)
00996     DECL_CTOR_T(unsigned int)
00997     DECL_CTOR_T(long)
00998     DECL_CTOR_T(unsigned long)
00999     DECL_CTOR_T(double)
01000     DECL_CTOR_T(const char*)
01001     DECL_CTOR_T(const sc_fxval&)
01002     DECL_CTOR_T(const sc_fxval_fast&)
01003     DECL_CTOR_T(const sc_fxnum&)
01004     DECL_CTOR_T(const sc_fxnum_fast&)
01005 #ifndef SC_FX_EXCLUDE_OTHER
01006     DECL_CTOR_T(int64)
01007     DECL_CTOR_T(uint64)
01008     DECL_CTOR_T(const sc_int_base&)
01009     DECL_CTOR_T(const sc_uint_base&)
01010     DECL_CTOR_T(const sc_signed&)
01011     DECL_CTOR_T(const sc_unsigned&)
01012 #endif
01013 
01014 #undef DECL_CTOR_T
01015 
01016     ~sc_fxnum_fast();
01017 
01018 
01019     // internal use only;
01020     double get_val() const;
01021 
01022 public:
01023 
01024     // unary operators
01025 
01026     const sc_fxval_fast operator - () const;
01027     const sc_fxval_fast operator + () const;
01028 
01029 
01030     // unary functions
01031 
01032     friend void neg( sc_fxval_fast&, const sc_fxnum_fast& );
01033     friend void neg( sc_fxnum_fast&, const sc_fxnum_fast& );
01034 
01035 
01036     // binary operators
01037 
01038 #define DECL_BIN_OP_T(op,tp)                                                  \
01039     friend const sc_fxval_fast operator op ( const sc_fxnum_fast&, tp );      \
01040     friend const sc_fxval_fast operator op ( tp, const sc_fxnum_fast& );
01041 
01042 #ifndef SC_FX_EXCLUDE_OTHER
01043 #define DECL_BIN_OP_OTHER(op)                                                 \
01044     DECL_BIN_OP_T(op,int64)                                                   \
01045     DECL_BIN_OP_T(op,uint64)                                                  \
01046     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
01047     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
01048     DECL_BIN_OP_T(op,const sc_signed&)                                        \
01049     DECL_BIN_OP_T(op,const sc_unsigned&)
01050 #else
01051 #define DECL_BIN_OP_OTHER(op)
01052 #endif
01053 
01054 #define DECL_BIN_OP(op,dummy)                                                 \
01055     friend const sc_fxval_fast operator op ( const sc_fxnum_fast&,            \
01056                                              const sc_fxnum_fast& );          \
01057     DECL_BIN_OP_T(op,int)                                                     \
01058     DECL_BIN_OP_T(op,unsigned int)                                            \
01059     DECL_BIN_OP_T(op,long)                                                    \
01060     DECL_BIN_OP_T(op,unsigned long)                                           \
01061     DECL_BIN_OP_T(op,double)                                                  \
01062     DECL_BIN_OP_T(op,const char*)                                             \
01063     DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
01064     DECL_BIN_OP_OTHER(op)
01065 
01066     DECL_BIN_OP(*,mult)
01067     DECL_BIN_OP(+,add)
01068     DECL_BIN_OP(-,sub)
01069 //    DECL_BIN_OP(/,div)
01070     friend const sc_fxval_fast operator / ( const sc_fxnum_fast&,
01071                                              const sc_fxnum_fast& );
01072     DECL_BIN_OP_T(/,int)
01073     DECL_BIN_OP_T(/,unsigned int)
01074     DECL_BIN_OP_T(/,long)
01075     DECL_BIN_OP_T(/,unsigned long)
01076     DECL_BIN_OP_T(/,double)
01077     DECL_BIN_OP_T(/,const char*)
01078     DECL_BIN_OP_T(/,const sc_fxval_fast&)
01079 //    DECL_BIN_OP_OTHER(op)
01080 #ifndef SC_FX_EXCLUDE_OTHER
01081     DECL_BIN_OP_T(/,int64)                                                   \
01082     DECL_BIN_OP_T(/,uint64)                                                  \
01083     DECL_BIN_OP_T(/,const sc_int_base&)                                      \
01084     DECL_BIN_OP_T(/,const sc_uint_base&)                                     \
01085     DECL_BIN_OP_T(/,const sc_signed&)                                        \
01086     DECL_BIN_OP_T(/,const sc_unsigned&)
01087 #endif
01088 
01089 #undef DECL_BIN_OP_T
01090 #undef DECL_BIN_OP_OTHER
01091 #undef DECL_BIN_OP
01092 
01093     friend const sc_fxval_fast operator << ( const sc_fxnum_fast&, int );
01094     friend const sc_fxval_fast operator >> ( const sc_fxnum_fast&, int );
01095 
01096 
01097     // binary functions
01098 
01099 #define DECL_BIN_FNC_T(fnc,tp)                                                \
01100     friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&, tp );             \
01101     friend void fnc ( sc_fxval_fast&, tp, const sc_fxnum_fast& );             \
01102     friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&, tp );             \
01103     friend void fnc ( sc_fxnum_fast&, tp, const sc_fxnum_fast& );
01104 
01105 #ifndef SC_FX_EXCLUDE_OTHER
01106 #define DECL_BIN_FNC_OTHER(fnc)                                               \
01107     DECL_BIN_FNC_T(fnc,int64)                                                 \
01108     DECL_BIN_FNC_T(fnc,uint64)                                                \
01109     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
01110     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
01111     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
01112     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
01113 #else
01114 #define DECL_BIN_FNC_OTHER(fnc)
01115 #endif
01116 
01117 #define DECL_BIN_FNC(fnc)                                                     \
01118     friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&,                   \
01119                                       const sc_fxnum_fast& );                 \
01120     friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&,                   \
01121                                       const sc_fxnum_fast& );                 \
01122     DECL_BIN_FNC_T(fnc,int)                                                   \
01123     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
01124     DECL_BIN_FNC_T(fnc,long)                                                  \
01125     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
01126     DECL_BIN_FNC_T(fnc,double)                                                \
01127     DECL_BIN_FNC_T(fnc,const char*)                                           \
01128     DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
01129     DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
01130     DECL_BIN_FNC_T(fnc,const sc_fxnum&)                                       \
01131     DECL_BIN_FNC_OTHER(fnc)
01132 
01133     DECL_BIN_FNC(mult)
01134     DECL_BIN_FNC(div)
01135     DECL_BIN_FNC(add)
01136     DECL_BIN_FNC(sub)
01137 
01138 #undef DECL_BIN_FNC_T
01139 #undef DECL_BIN_FNC_OTHER
01140 #undef DECL_BIN_FNC
01141 
01142     friend void lshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
01143     friend void rshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
01144     friend void lshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
01145     friend void rshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
01146 
01147 
01148     // relational (including equality) operators
01149 
01150 #define DECL_REL_OP_T(op,tp)                                                  \
01151     friend bool operator op ( const sc_fxnum_fast&, tp );                     \
01152     friend bool operator op ( tp, const sc_fxnum_fast& );
01153 
01154 #ifndef SC_FX_EXCLUDE_OTHER
01155 #define DECL_REL_OP_OTHER(op)                                                 \
01156     DECL_REL_OP_T(op,int64)                                                   \
01157     DECL_REL_OP_T(op,uint64)                                                  \
01158     DECL_REL_OP_T(op,const sc_int_base&)                                      \
01159     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
01160     DECL_REL_OP_T(op,const sc_signed&)                                        \
01161     DECL_REL_OP_T(op,const sc_unsigned&)
01162 #else
01163 #define DECL_REL_OP_OTHER(op)
01164 #endif
01165 
01166 #define DECL_REL_OP(op)                                                       \
01167     friend bool operator op ( const sc_fxnum_fast&, const sc_fxnum_fast& );   \
01168     DECL_REL_OP_T(op,int)                                                     \
01169     DECL_REL_OP_T(op,unsigned int)                                            \
01170     DECL_REL_OP_T(op,long)                                                    \
01171     DECL_REL_OP_T(op,unsigned long)                                           \
01172     DECL_REL_OP_T(op,double)                                                  \
01173     DECL_REL_OP_T(op,const char*)                                             \
01174     DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
01175     DECL_REL_OP_OTHER(op)
01176 
01177     DECL_REL_OP(<)
01178     DECL_REL_OP(<=)
01179     DECL_REL_OP(>)
01180     DECL_REL_OP(>=)
01181     DECL_REL_OP(==)
01182     DECL_REL_OP(!=)
01183 
01184 #undef DECL_REL_OP_T
01185 #undef DECL_REL_OP_OTHER
01186 #undef DECL_REL_OP
01187 
01188 
01189     // assignment operators
01190 
01191 #define DECL_ASN_OP_T(op,tp)                                                  \
01192     sc_fxnum_fast& operator op( tp );
01193 
01194 #ifndef SC_FX_EXCLUDE_OTHER
01195 #define DECL_ASN_OP_OTHER(op)                                                 \
01196     DECL_ASN_OP_T(op,int64)                                                   \
01197     DECL_ASN_OP_T(op,uint64)                                                  \
01198     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
01199     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
01200     DECL_ASN_OP_T(op,const sc_signed&)                                        \
01201     DECL_ASN_OP_T(op,const sc_unsigned&)
01202 #else
01203 #define DECL_ASN_OP_OTHER(op)
01204 #endif
01205 
01206 #define DECL_ASN_OP(op)                                                       \
01207     DECL_ASN_OP_T(op,int)                                                     \
01208     DECL_ASN_OP_T(op,unsigned int)                                            \
01209     DECL_ASN_OP_T(op,long)                                                    \
01210     DECL_ASN_OP_T(op,unsigned long)                                           \
01211     DECL_ASN_OP_T(op,double)                                                  \
01212     DECL_ASN_OP_T(op,const char*)                                             \
01213     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
01214     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
01215     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
01216     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
01217     DECL_ASN_OP_OTHER(op)
01218 
01219     DECL_ASN_OP(=)
01220 
01221     DECL_ASN_OP(*=)
01222     DECL_ASN_OP(/=)
01223     DECL_ASN_OP(+=)
01224     DECL_ASN_OP(-=)
01225 
01226     DECL_ASN_OP_T(<<=,int)
01227     DECL_ASN_OP_T(>>=,int)
01228 
01229 #undef DECL_ASN_OP_T
01230 #undef DECL_ASN_OP_OTHER
01231 #undef DECL_ASN_OP
01232 
01233 
01234     // auto-increment and auto-decrement
01235 
01236     const sc_fxval_fast operator ++ ( int );
01237     const sc_fxval_fast operator -- ( int );
01238 
01239     sc_fxnum_fast& operator ++ ();
01240     sc_fxnum_fast& operator -- ();
01241 
01242 
01243     // bit selection
01244 
01245     const sc_fxnum_fast_bitref operator [] ( int ) const;
01246     sc_fxnum_fast_bitref       operator [] ( int );
01247 
01248     const sc_fxnum_fast_bitref bit( int ) const;
01249     sc_fxnum_fast_bitref       bit( int );
01250 
01251 
01252     // part selection
01253 
01254     const sc_fxnum_fast_subref operator () ( int, int ) const;
01255     sc_fxnum_fast_subref       operator () ( int, int );
01256 
01257     const sc_fxnum_fast_subref range( int, int ) const;
01258     sc_fxnum_fast_subref       range( int, int );
01259 
01260 
01261     const sc_fxnum_fast_subref operator () () const;
01262     sc_fxnum_fast_subref       operator () ();
01263 
01264     const sc_fxnum_fast_subref range() const;
01265     sc_fxnum_fast_subref       range();
01266 
01267 
01268     // implicit conversion
01269 
01270     operator double() const;            // necessary evil!
01271 
01272 
01273     // explicit conversion to primitive types
01274 
01275     short          to_short() const;
01276     unsigned short to_ushort() const;
01277     int            to_int() const;
01278     unsigned int   to_uint() const;
01279     long           to_long() const;
01280     unsigned long  to_ulong() const;
01281     int64          to_int64() const;
01282     uint64         to_uint64() const;
01283     float          to_float() const;
01284     double         to_double() const;
01285 
01286 
01287     // explicit conversion to character string
01288 
01289     const std::string to_string() const;
01290     const std::string to_string( sc_numrep ) const;
01291     const std::string to_string( sc_numrep, bool ) const;
01292     const std::string to_string( sc_fmt ) const;
01293     const std::string to_string( sc_numrep, sc_fmt ) const;
01294     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
01295 
01296     const std::string to_dec() const;
01297     const std::string to_bin() const;
01298     const std::string to_oct() const;
01299     const std::string to_hex() const;
01300 
01301 
01302     // query value
01303 
01304     bool is_neg() const;
01305     bool is_zero() const;
01306 
01307     // internal use only;
01308     bool is_normal() const;
01309 
01310     bool quantization_flag() const;
01311     bool overflow_flag() const;
01312 
01313     const sc_fxval_fast value() const;
01314 
01315 
01316     // query parameters
01317 
01318     int       wl() const;
01319     int       iwl() const;
01320     sc_q_mode q_mode() const;
01321     sc_o_mode o_mode() const;
01322     int       n_bits() const;
01323 
01324     const sc_fxtype_params& type_params() const;
01325 
01326     const sc_fxcast_switch& cast_switch() const;
01327 
01328 
01329     // print or dump content
01330 
01331     void print( ::std::ostream& = ::std::cout ) const;
01332     void scan( ::std::istream& = ::std::cin );
01333     void dump( ::std::ostream& = ::std::cout ) const;
01334 
01335 
01336     // internal use only;
01337     void observer_read() const;
01338 
01339 
01340     // internal use only;
01341     bool get_bit( int ) const;
01342 
01343 protected:
01344 
01345     bool set_bit( int, bool );
01346 
01347 
01348     bool get_slice( int, int, sc_bv_base& ) const;
01349     bool set_slice( int, int, const sc_bv_base& );
01350 
01351 
01352     sc_fxnum_fast_observer* lock_observer() const;
01353     void unlock_observer( sc_fxnum_fast_observer* ) const;
01354 
01355 private:
01356 
01357     double                          m_val;
01358 
01359     scfx_params                     m_params;
01360     bool                            m_q_flag;
01361     bool                            m_o_flag;
01362 
01363     mutable sc_fxnum_fast_observer* m_observer;
01364 
01365 private:
01366 
01367     // disabled
01368     sc_fxnum_fast();
01369     sc_fxnum_fast( const sc_fxnum_fast& );
01370 };
01371 
01372 
01373 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
01374 
01375 // ----------------------------------------------------------------------------
01376 //  CLASS : sc_fxnum_bitref
01377 //
01378 //  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
01379 // ----------------------------------------------------------------------------
01380 
01381 // constructor
01382 
01383 inline
01384 sc_fxnum_bitref::sc_fxnum_bitref( sc_fxnum& num_, int idx_ )
01385     : m_num( num_ ), m_idx( idx_ )
01386 {}
01387 
01388 
01389 // copy constructor
01390 
01391 inline
01392 sc_fxnum_bitref::sc_fxnum_bitref( const sc_fxnum_bitref& a )
01393     : m_num( a.m_num ), m_idx( a.m_idx )
01394 {}
01395 
01396 
01397 // assignment operators
01398 
01399 inline
01400 sc_fxnum_bitref&
01401 sc_fxnum_bitref::operator = ( const sc_fxnum_bitref& a )
01402 {
01403     if( &a != this )
01404     {
01405         SC_FXNUM_OBSERVER_READ_( a.m_num )
01406         set( a.get() );
01407         SC_FXNUM_OBSERVER_WRITE_( m_num )
01408     }
01409     return *this;
01410 }
01411 
01412 inline
01413 sc_fxnum_bitref&
01414 sc_fxnum_bitref::operator = ( const sc_fxnum_fast_bitref& a )
01415 {
01416     SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
01417     set( a.get() );
01418     SC_FXNUM_OBSERVER_WRITE_( m_num )
01419     return *this;
01420 }
01421 
01422 inline
01423 sc_fxnum_bitref&
01424 sc_fxnum_bitref::operator = ( const sc_bit& a )
01425 {
01426     set( static_cast<bool>( a ) );
01427     SC_FXNUM_OBSERVER_WRITE_( m_num )
01428     return *this;
01429 }
01430 
01431 inline
01432 sc_fxnum_bitref&
01433 sc_fxnum_bitref::operator = ( bool a )
01434 {
01435     set( a );
01436     SC_FXNUM_OBSERVER_WRITE_( m_num )
01437     return *this;
01438 }
01439 
01440 
01441 inline
01442 sc_fxnum_bitref&
01443 sc_fxnum_bitref::operator &= ( const sc_fxnum_bitref& b )
01444 {
01445     SC_FXNUM_OBSERVER_READ_( m_num )
01446     SC_FXNUM_OBSERVER_READ_( b.m_num )
01447     set( get() && b.get() );
01448     SC_FXNUM_OBSERVER_WRITE_( m_num )
01449     return *this;
01450 }
01451 
01452 inline
01453 sc_fxnum_bitref&
01454 sc_fxnum_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
01455 {
01456     SC_FXNUM_OBSERVER_READ_( m_num )
01457     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01458     set( get() && b.get() );
01459     SC_FXNUM_OBSERVER_WRITE_( m_num )
01460     return *this;
01461 }
01462 
01463 inline
01464 sc_fxnum_bitref&
01465 sc_fxnum_bitref::operator &= ( const sc_bit& b )
01466 {
01467     SC_FXNUM_OBSERVER_READ_( m_num )
01468     set( get() && static_cast<bool>( b ) );
01469     SC_FXNUM_OBSERVER_WRITE_( m_num )
01470     return *this;
01471 }
01472 
01473 inline
01474 sc_fxnum_bitref&
01475 sc_fxnum_bitref::operator &= ( bool b )
01476 {
01477     SC_FXNUM_OBSERVER_READ_( m_num )
01478     set( get() && b );
01479     SC_FXNUM_OBSERVER_WRITE_( m_num )
01480     return *this;
01481 }
01482 
01483 
01484 inline
01485 sc_fxnum_bitref&
01486 sc_fxnum_bitref::operator |= ( const sc_fxnum_bitref& b )
01487 {
01488     SC_FXNUM_OBSERVER_READ_( m_num )
01489     SC_FXNUM_OBSERVER_READ_( b.m_num )
01490     set( get() || b.get() );
01491     SC_FXNUM_OBSERVER_WRITE_( m_num )
01492     return *this;
01493 }
01494 
01495 inline
01496 sc_fxnum_bitref&
01497 sc_fxnum_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
01498 {
01499     SC_FXNUM_OBSERVER_READ_( m_num )
01500     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01501     set( get() || b.get() );
01502     SC_FXNUM_OBSERVER_WRITE_( m_num )
01503     return *this;
01504 }
01505 
01506 inline
01507 sc_fxnum_bitref&
01508 sc_fxnum_bitref::operator |= ( const sc_bit& b )
01509 {
01510     SC_FXNUM_OBSERVER_READ_( m_num )
01511     set( get() || static_cast<bool>( b ) );
01512     SC_FXNUM_OBSERVER_WRITE_( m_num )
01513     return *this;
01514 }
01515 
01516 inline
01517 sc_fxnum_bitref&
01518 sc_fxnum_bitref::operator |= ( bool b )
01519 {
01520     SC_FXNUM_OBSERVER_READ_( m_num )
01521     set( get() || b );
01522     SC_FXNUM_OBSERVER_WRITE_( m_num )
01523     return *this;
01524 }
01525 
01526 
01527 inline
01528 sc_fxnum_bitref&
01529 sc_fxnum_bitref::operator ^= ( const sc_fxnum_bitref& b )
01530 {
01531     SC_FXNUM_OBSERVER_READ_( m_num )
01532     SC_FXNUM_OBSERVER_READ_( b.m_num )
01533     set( get() != b.get() );
01534     SC_FXNUM_OBSERVER_WRITE_( m_num )
01535     return *this;
01536 }
01537 
01538 inline
01539 sc_fxnum_bitref&
01540 sc_fxnum_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
01541 {
01542     SC_FXNUM_OBSERVER_READ_( m_num )
01543     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01544     set( get() != b.get() );
01545     SC_FXNUM_OBSERVER_WRITE_( m_num )
01546     return *this;
01547 }
01548 
01549 inline
01550 sc_fxnum_bitref&
01551 sc_fxnum_bitref::operator ^= ( const sc_bit& b )
01552 {
01553     SC_FXNUM_OBSERVER_READ_( m_num )
01554     set( get() != static_cast<bool>( b ) );
01555     SC_FXNUM_OBSERVER_WRITE_( m_num )
01556     return *this;
01557 }
01558 
01559 inline
01560 sc_fxnum_bitref&
01561 sc_fxnum_bitref::operator ^= ( bool b )
01562 {
01563     SC_FXNUM_OBSERVER_READ_( m_num )
01564     set( get() != b );
01565     SC_FXNUM_OBSERVER_WRITE_( m_num )
01566     return *this;
01567 }
01568 
01569 
01570 // implicit conversion
01571 
01572 inline
01573 sc_fxnum_bitref::operator bool() const
01574 {
01575     SC_FXNUM_OBSERVER_READ_( m_num )
01576     return get();
01577 }
01578 
01579 
01580 inline
01581 ::std::ostream&
01582 operator << ( ::std::ostream& os, const sc_fxnum_bitref& a )
01583 {
01584     a.print( os );
01585     return os;
01586 }
01587 
01588 inline
01589 ::std::istream&
01590 operator >> ( ::std::istream& is, sc_fxnum_bitref& a )
01591 {
01592     a.scan( is );
01593     return is;
01594 }
01595 
01596 
01597 // ----------------------------------------------------------------------------
01598 //  CLASS : sc_fxnum_fast_bitref
01599 //
01600 //  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
01601 // ----------------------------------------------------------------------------
01602 
01603 // constructor
01604 
01605 inline
01606 sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( sc_fxnum_fast& num_, int idx_ )
01607     : m_num( num_ ), m_idx( idx_ )
01608 {}
01609 
01610 
01611 // copy constructor
01612 
01613 inline
01614 sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& a )
01615     : m_num( a.m_num ), m_idx( a.m_idx )
01616 {}
01617 
01618 
01619 // assignment operators
01620 
01621 inline
01622 sc_fxnum_fast_bitref&
01623 sc_fxnum_fast_bitref::operator = ( const sc_fxnum_bitref& a )
01624 {
01625     SC_FXNUM_OBSERVER_READ_( a.m_num )
01626     set( a.get() );
01627     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01628     return *this;
01629 }
01630 
01631 inline
01632 sc_fxnum_fast_bitref&
01633 sc_fxnum_fast_bitref::operator = ( const sc_fxnum_fast_bitref& a )
01634 {
01635     if( &a != this )
01636     {
01637         SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
01638         set( a.get() );
01639         SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01640     }
01641     return *this;
01642 }
01643 
01644 inline
01645 sc_fxnum_fast_bitref&
01646 sc_fxnum_fast_bitref::operator = ( const sc_bit& a )
01647 {
01648     set( static_cast<bool>( a ) );
01649     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01650     return *this;
01651 }
01652 
01653 inline
01654 sc_fxnum_fast_bitref&
01655 sc_fxnum_fast_bitref::operator = ( bool a )
01656 {
01657     set( a );
01658     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01659     return *this;
01660 }
01661 
01662 
01663 inline
01664 sc_fxnum_fast_bitref&
01665 sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_bitref& b )
01666 {
01667     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01668     SC_FXNUM_OBSERVER_READ_( b.m_num )
01669     set( get() && b.get() );
01670     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01671     return *this;
01672 }
01673 
01674 inline
01675 sc_fxnum_fast_bitref&
01676 sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
01677 {
01678     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01679     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01680     set( get() && b.get() );
01681     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01682     return *this;
01683 }
01684 
01685 inline
01686 sc_fxnum_fast_bitref&
01687 sc_fxnum_fast_bitref::operator &= ( const sc_bit& b )
01688 {
01689     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01690     set( get() && static_cast<bool>( b ) );
01691     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01692     return *this;
01693 }
01694 
01695 inline
01696 sc_fxnum_fast_bitref&
01697 sc_fxnum_fast_bitref::operator &= ( bool b )
01698 {
01699     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01700     set( get() && b );
01701     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01702     return *this;
01703 }
01704 
01705 
01706 inline
01707 sc_fxnum_fast_bitref&
01708 sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_bitref& b )
01709 {
01710     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01711     SC_FXNUM_OBSERVER_READ_( b.m_num )
01712     set( get() || b.get() );
01713     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01714     return *this;
01715 }
01716 
01717 inline
01718 sc_fxnum_fast_bitref&
01719 sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
01720 {
01721     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01722     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01723     set( get() || b.get() );
01724     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01725     return *this;
01726 }
01727 
01728 inline
01729 sc_fxnum_fast_bitref&
01730 sc_fxnum_fast_bitref::operator |= ( const sc_bit& b )
01731 {
01732     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01733     set( get() || static_cast<bool>( b ) );
01734     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01735     return *this;
01736 }
01737 
01738 inline
01739 sc_fxnum_fast_bitref&
01740 sc_fxnum_fast_bitref::operator |= ( bool b )
01741 {
01742     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01743     set( get() || b );
01744     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01745     return *this;
01746 }
01747 
01748 
01749 inline
01750 sc_fxnum_fast_bitref&
01751 sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_bitref& b )
01752 {
01753     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01754     SC_FXNUM_OBSERVER_READ_( b.m_num )
01755     set( get() != b.get() );
01756     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01757     return *this;
01758 }
01759 
01760 inline
01761 sc_fxnum_fast_bitref&
01762 sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
01763 {
01764     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01765     SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
01766     set( get() != b.get() );
01767     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01768     return *this;
01769 }
01770 
01771 inline
01772 sc_fxnum_fast_bitref&
01773 sc_fxnum_fast_bitref::operator ^= ( const sc_bit& b )
01774 {
01775     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01776     set( get() != static_cast<bool>( b ) );
01777     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01778     return *this;
01779 }
01780 
01781 inline
01782 sc_fxnum_fast_bitref&
01783 sc_fxnum_fast_bitref::operator ^= ( bool b )
01784 {
01785     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01786     set( get() != b );
01787     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
01788     return *this;
01789 }
01790 
01791 
01792 // implicit conversion
01793 
01794 inline
01795 sc_fxnum_fast_bitref::operator bool() const
01796 {
01797     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
01798     return get();
01799 }
01800 
01801 
01802 inline
01803 ::std::ostream&
01804 operator << ( ::std::ostream& os, const sc_fxnum_fast_bitref& a )
01805 {
01806     a.print( os );
01807     return os;
01808 }
01809 
01810 inline
01811 ::std::istream&
01812 operator >> ( ::std::istream& is, sc_fxnum_fast_bitref& a )
01813 {
01814     a.scan( is );
01815     return is;
01816 }
01817 
01818 
01819 // ----------------------------------------------------------------------------
01820 //  CLASS : sc_fxnum_subref
01821 //
01822 //  Proxy class for part-selection in class sc_fxnum,
01823 //  behaves like sc_bv_base.
01824 // ----------------------------------------------------------------------------
01825 
01826 // constructor
01827 
01828 inline
01829 sc_fxnum_subref::sc_fxnum_subref( sc_fxnum& num_, int from_, int to_ )
01830     : m_num( num_ ), m_from( from_ ), m_to( to_ ),
01831       m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
01832                              sc_min( m_from, m_to ) + 1 ) )
01833 {}
01834 
01835 
01836 // copy constructor
01837 
01838 inline
01839 sc_fxnum_subref::sc_fxnum_subref( const sc_fxnum_subref& a )
01840     : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
01841       m_bv( *new sc_bv_base( a.m_bv ) )
01842 {}
01843 
01844 
01845 // destructor
01846 
01847 inline
01848 sc_fxnum_subref::~sc_fxnum_subref()
01849 {
01850     delete &m_bv;
01851 }
01852 
01853 
01854 // assignment operators
01855 
01856 inline
01857 sc_fxnum_subref&
01858 sc_fxnum_subref::operator = ( const sc_fxnum_subref& a )
01859 {
01860     if( &a != this )
01861     {
01862         m_bv = static_cast<sc_bv_base>( a );
01863         set();
01864         SC_FXNUM_OBSERVER_WRITE_( m_num )
01865     }
01866     return *this;
01867 }
01868 
01869 inline
01870 sc_fxnum_subref&
01871 sc_fxnum_subref::operator = ( const sc_fxnum_fast_subref& a )
01872 {
01873     m_bv = static_cast<sc_bv_base>( a );
01874     set();
01875     SC_FXNUM_OBSERVER_WRITE_( m_num )
01876     return *this;
01877 }
01878 
01879 #define DEFN_ASN_OP_T(tp)                                                     \
01880 inline                                                                        \
01881 sc_fxnum_subref&                                                              \
01882 sc_fxnum_subref::operator = ( tp a )                                          \
01883 {                                                                             \
01884     m_bv = a;                                                                 \
01885     set();                                                                    \
01886     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01887     return *this;                                                             \
01888 }
01889 
01890 DEFN_ASN_OP_T(const sc_bv_base&)
01891 DEFN_ASN_OP_T(const sc_lv_base&)
01892 DEFN_ASN_OP_T(const char*)
01893 DEFN_ASN_OP_T(const bool*)
01894 DEFN_ASN_OP_T(const sc_signed&)
01895 DEFN_ASN_OP_T(const sc_unsigned&)
01896 DEFN_ASN_OP_T(const sc_int_base&)
01897 DEFN_ASN_OP_T(const sc_uint_base&)
01898 DEFN_ASN_OP_T(int64)
01899 DEFN_ASN_OP_T(uint64)
01900 DEFN_ASN_OP_T(int)
01901 DEFN_ASN_OP_T(unsigned int)
01902 DEFN_ASN_OP_T(long)
01903 DEFN_ASN_OP_T(unsigned long)
01904 DEFN_ASN_OP_T(char)
01905 
01906 #undef DEFN_ASN_OP_T
01907 
01908 
01909 #define DEFN_ASN_OP_T(op,tp)                                                  \
01910 inline                                                                        \
01911 sc_fxnum_subref&                                                              \
01912 sc_fxnum_subref::operator op ## = ( tp a )                                    \
01913 {                                                                             \
01914     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01915     get();                                                                    \
01916     m_bv = m_bv op a;                                                         \
01917     set();                                                                    \
01918     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01919     return *this;                                                             \
01920 }
01921 
01922 #define DEFN_ASN_OP(op)                                                       \
01923 inline                                                                        \
01924 sc_fxnum_subref&                                                              \
01925 sc_fxnum_subref::operator op ## = ( const sc_fxnum_subref& a )                \
01926 {                                                                             \
01927     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01928     get();                                                                    \
01929     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
01930     set();                                                                    \
01931     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01932     return *this;                                                             \
01933 }                                                                             \
01934                                                                               \
01935 inline                                                                        \
01936 sc_fxnum_subref&                                                              \
01937 sc_fxnum_subref::operator op ## = ( const sc_fxnum_fast_subref& a )           \
01938 {                                                                             \
01939     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
01940     get();                                                                    \
01941     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
01942     set();                                                                    \
01943     SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
01944     return *this;                                                             \
01945 }                                                                             \
01946                                                                               \
01947 DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
01948 DEFN_ASN_OP_T(op,const sc_lv_base&)
01949 
01950 DEFN_ASN_OP(&)
01951 DEFN_ASN_OP(|)
01952 DEFN_ASN_OP(^)
01953 
01954 #undef DEFN_ASN_OP_T
01955 #undef DEFN_ASN_OP
01956 
01957 
01958 // relational operators
01959 
01960 #define DEFN_REL_OP_T(op,tp)                                                  \
01961 inline                                                                        \
01962 bool                                                                          \
01963 operator op ( const sc_fxnum_subref& a, tp b )                                \
01964 {                                                                             \
01965     return ( static_cast<sc_bv_base>( a ) op b );                             \
01966 }                                                                             \
01967                                                                               \
01968 inline                                                                        \
01969 bool                                                                          \
01970 operator op ( tp a, const sc_fxnum_subref& b )                                \
01971 {                                                                             \
01972     return ( static_cast<sc_bv_base>( b ) op a );                             \
01973 }
01974 
01975 #define DEFN_REL_OP(op)                                                       \
01976 inline                                                                        \
01977 bool                                                                          \
01978 operator op ( const sc_fxnum_subref& a, const sc_fxnum_subref& b )            \
01979 {                                                                             \
01980     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
01981 }                                                                             \
01982                                                                               \
01983 inline                                                                        \
01984 bool                                                                          \
01985 operator op ( const sc_fxnum_subref& a, const sc_fxnum_fast_subref& b )       \
01986 {                                                                             \
01987     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
01988 }                                                                             \
01989                                                                               \
01990 DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
01991 DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
01992 DEFN_REL_OP_T(op,const char*)                                                 \
01993 DEFN_REL_OP_T(op,const bool*)                                                 \
01994 DEFN_REL_OP_T(op,const sc_signed&)                                            \
01995 DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
01996 DEFN_REL_OP_T(op,int)                                                         \
01997 DEFN_REL_OP_T(op,unsigned int)                                                \
01998 DEFN_REL_OP_T(op,long)                                                        \
01999 DEFN_REL_OP_T(op,unsigned long)
02000 
02001 DEFN_REL_OP(==)
02002 DEFN_REL_OP(!=)
02003 
02004 #undef DEFN_REL_OP_T
02005 #undef DEFN_REL_OP
02006 
02007 
02008 // reduce functions
02009 
02010 #define DEFN_RED_FNC(fnc)                                                     \
02011 inline                                                                        \
02012 bool                                                                          \
02013 sc_fxnum_subref::fnc() const                                                  \
02014 {                                                                             \
02015     SC_FXNUM_OBSERVER_READ_( m_num )                                          \
02016     get();                                                                    \
02017     return static_cast<bool>( m_bv.fnc() );                                   \
02018 }
02019 
02020 DEFN_RED_FNC(and_reduce)
02021 DEFN_RED_FNC(nand_reduce)
02022 DEFN_RED_FNC(or_reduce)
02023 DEFN_RED_FNC(nor_reduce)
02024 DEFN_RED_FNC(xor_reduce)
02025 DEFN_RED_FNC(xnor_reduce)
02026 
02027 #undef DEFN_RED_FNC
02028 
02029 
02030 // query parameter
02031 
02032 inline
02033 int
02034 sc_fxnum_subref::length() const
02035 {
02036     return m_bv.length();
02037 }
02038 
02039 
02040 // explicit conversions
02041 
02042 inline
02043 int
02044 sc_fxnum_subref::to_int() const
02045 {
02046     SC_FXNUM_OBSERVER_READ_( m_num )
02047     get();
02048     return m_bv.to_int();
02049 }
02050 
02051 inline
02052 int64
02053 sc_fxnum_subref::to_int64() const
02054 {
02055     SC_FXNUM_OBSERVER_READ_( m_num )
02056     get();
02057     return m_bv.to_int64();
02058 }
02059 
02060 inline
02061 unsigned int
02062 sc_fxnum_subref::to_uint() const
02063 {
02064     SC_FXNUM_OBSERVER_READ_( m_num )
02065     get();
02066     return m_bv.to_uint();
02067 }
02068 
02069 inline
02070 uint64
02071 sc_fxnum_subref::to_uint64() const
02072 {
02073     SC_FXNUM_OBSERVER_READ_( m_num )
02074     get();
02075     return m_bv.to_uint64();
02076 }
02077 
02078 inline
02079 long
02080 sc_fxnum_subref::to_long() const
02081 {
02082     SC_FXNUM_OBSERVER_READ_( m_num )
02083     get();
02084     return m_bv.to_long();
02085 }
02086 
02087 inline
02088 unsigned long
02089 sc_fxnum_subref::to_ulong() const
02090 {
02091     SC_FXNUM_OBSERVER_READ_( m_num )
02092     get();
02093     return m_bv.to_ulong();
02094 }
02095 
02096 
02097 #ifdef SC_DT_DEPRECATED
02098 
02099 inline
02100 int
02101 sc_fxnum_subref::to_signed() const
02102 {
02103     return to_int();
02104 }
02105 
02106 inline
02107 unsigned int
02108 sc_fxnum_subref::to_unsigned() const
02109 {
02110     return to_uint();
02111 }
02112 
02113 #endif
02114 
02115 
02116 inline
02117 const std::string
02118 sc_fxnum_subref::to_string() const
02119 {
02120     get();
02121     return m_bv.to_string();
02122 }
02123 
02124 inline
02125 const std::string
02126 sc_fxnum_subref::to_string( sc_numrep numrep ) const
02127 {
02128     get();
02129     return m_bv.to_string( numrep );
02130 }
02131 
02132 inline
02133 const std::string
02134 sc_fxnum_subref::to_string( sc_numrep numrep, bool w_prefix ) const
02135 {
02136     get();
02137     return m_bv.to_string( numrep, w_prefix );
02138 }
02139 
02140 
02141 // implicit conversion
02142 
02143 inline
02144 sc_fxnum_subref::operator sc_bv_base () const
02145 {
02146     SC_FXNUM_OBSERVER_READ_( m_num )
02147     get();
02148     return m_bv;
02149 }
02150 
02151 
02152 inline
02153 ::std::ostream&
02154 operator << ( ::std::ostream& os, const sc_fxnum_subref& a )
02155 {
02156     a.print( os );
02157     return os;
02158 }
02159 
02160 inline
02161 ::std::istream&
02162 operator >> ( ::std::istream& is, sc_fxnum_subref& a )
02163 {
02164     a.scan( is );
02165     return is;
02166 }
02167 
02168 
02169 // ----------------------------------------------------------------------------
02170 //  CLASS : sc_fxnum_fast_subref
02171 //
02172 //  Proxy class for part-selection in class sc_fxnum_fast,
02173 //  behaves like sc_bv_base.
02174 // ----------------------------------------------------------------------------
02175 
02176 // constructor
02177 
02178 inline
02179 sc_fxnum_fast_subref::sc_fxnum_fast_subref( sc_fxnum_fast& num_,
02180                                             int from_, int to_ )
02181     : m_num( num_ ), m_from( from_ ), m_to( to_ ),
02182       m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
02183                              sc_min( m_from, m_to ) + 1 ) )
02184 {}
02185 
02186 
02187 // copy constructor
02188 
02189 inline
02190 sc_fxnum_fast_subref::sc_fxnum_fast_subref( const sc_fxnum_fast_subref& a )
02191     : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
02192       m_bv( *new sc_bv_base( a.m_bv ) )
02193 {}
02194 
02195 
02196 // destructor
02197 
02198 inline
02199 sc_fxnum_fast_subref::~sc_fxnum_fast_subref()
02200 {
02201     delete &m_bv;
02202 }
02203 
02204 
02205 // assignment operators
02206 
02207 inline
02208 sc_fxnum_fast_subref&
02209 sc_fxnum_fast_subref::operator = ( const sc_fxnum_subref& a )
02210 {
02211     m_bv = static_cast<sc_bv_base>( a );
02212     set();
02213     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
02214     return *this;
02215 }
02216 
02217 inline
02218 sc_fxnum_fast_subref&
02219 sc_fxnum_fast_subref::operator = ( const sc_fxnum_fast_subref& a )
02220 {
02221     if( &a != this )
02222     {
02223         m_bv = static_cast<sc_bv_base>( a );
02224         set();
02225         SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
02226     }
02227     return *this;
02228 }
02229 
02230 #define DEFN_ASN_OP_T(tp)                                                     \
02231 inline                                                                        \
02232 sc_fxnum_fast_subref&                                                         \
02233 sc_fxnum_fast_subref::operator = ( tp a )                                     \
02234 {                                                                             \
02235     m_bv = a;                                                                 \
02236     set();                                                                    \
02237     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02238     return *this;                                                             \
02239 }
02240 
02241 DEFN_ASN_OP_T(const sc_bv_base&)
02242 DEFN_ASN_OP_T(const sc_lv_base&)
02243 DEFN_ASN_OP_T(const char*)
02244 DEFN_ASN_OP_T(const bool*)
02245 DEFN_ASN_OP_T(const sc_signed&)
02246 DEFN_ASN_OP_T(const sc_unsigned&)
02247 DEFN_ASN_OP_T(const sc_int_base&)
02248 DEFN_ASN_OP_T(const sc_uint_base&)
02249 DEFN_ASN_OP_T(int64)
02250 DEFN_ASN_OP_T(uint64)
02251 DEFN_ASN_OP_T(int)
02252 DEFN_ASN_OP_T(unsigned int)
02253 DEFN_ASN_OP_T(long)
02254 DEFN_ASN_OP_T(unsigned long)
02255 DEFN_ASN_OP_T(char)
02256 
02257 #undef DEFN_ASN_OP_T
02258 
02259 
02260 #define DEFN_ASN_OP_T(op,tp)                                                  \
02261 inline                                                                        \
02262 sc_fxnum_fast_subref&                                                         \
02263 sc_fxnum_fast_subref::operator op ## = ( tp a )                               \
02264 {                                                                             \
02265     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02266     get();                                                                    \
02267     m_bv = m_bv op a;                                                         \
02268     set();                                                                    \
02269     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02270     return *this;                                                             \
02271 }
02272 
02273 #define DEFN_ASN_OP(op)                                                       \
02274 inline                                                                        \
02275 sc_fxnum_fast_subref&                                                         \
02276 sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_subref& a )           \
02277 {                                                                             \
02278     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02279     get();                                                                    \
02280     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
02281     set();                                                                    \
02282     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02283     return *this;                                                             \
02284 }                                                                             \
02285                                                                               \
02286 inline                                                                        \
02287 sc_fxnum_fast_subref&                                                         \
02288 sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_fast_subref& a )      \
02289 {                                                                             \
02290     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02291     get();                                                                    \
02292     m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
02293     set();                                                                    \
02294     SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
02295     return *this;                                                             \
02296 }                                                                             \
02297                                                                               \
02298 DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
02299 DEFN_ASN_OP_T(op,const sc_lv_base&)
02300 
02301 DEFN_ASN_OP(&)
02302 DEFN_ASN_OP(|)
02303 DEFN_ASN_OP(^)
02304 
02305 #undef DEFN_ASN_OP_T
02306 #undef DEFN_ASN_OP
02307 
02308 
02309 // relational operators
02310 
02311 #define DEFN_REL_OP_T(op,tp)                                                  \
02312 inline                                                                        \
02313 bool                                                                          \
02314 operator op ( const sc_fxnum_fast_subref& a, tp b )                           \
02315 {                                                                             \
02316     return ( static_cast<sc_bv_base>( a ) op b );                             \
02317 }                                                                             \
02318                                                                               \
02319 inline                                                                        \
02320 bool                                                                          \
02321 operator op ( tp a, const sc_fxnum_fast_subref& b )                           \
02322 {                                                                             \
02323     return ( static_cast<sc_bv_base>( b ) op a );                             \
02324 }
02325 
02326 #define DEFN_REL_OP(op)                                                       \
02327 inline                                                                        \
02328 bool                                                                          \
02329 operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_fast_subref& b )  \
02330 {                                                                             \
02331     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
02332 }                                                                             \
02333                                                                               \
02334 inline                                                                        \
02335 bool                                                                          \
02336 operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_subref& b )       \
02337 {                                                                             \
02338     return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
02339 }                                                                             \
02340                                                                               \
02341 DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
02342 DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
02343 DEFN_REL_OP_T(op,const char*)                                                 \
02344 DEFN_REL_OP_T(op,const bool*)                                                 \
02345 DEFN_REL_OP_T(op,const sc_signed&)                                            \
02346 DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
02347 DEFN_REL_OP_T(op,int)                                                         \
02348 DEFN_REL_OP_T(op,unsigned int)                                                \
02349 DEFN_REL_OP_T(op,long)                                                        \
02350 DEFN_REL_OP_T(op,unsigned long)
02351 
02352 DEFN_REL_OP(==)
02353 DEFN_REL_OP(!=)
02354 
02355 #undef DEFN_REL_OP_T
02356 #undef DEFN_REL_OP
02357 
02358 
02359 // reduce functions
02360 
02361 #define DEFN_RED_FNC(fnc)                                                     \
02362 inline                                                                        \
02363 bool                                                                          \
02364 sc_fxnum_fast_subref::fnc() const                                             \
02365 {                                                                             \
02366     SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
02367     get();                                                                    \
02368     return static_cast<bool>( m_bv.fnc() );                                   \
02369 }
02370 
02371 DEFN_RED_FNC(and_reduce)
02372 DEFN_RED_FNC(nand_reduce)
02373 DEFN_RED_FNC(or_reduce)
02374 DEFN_RED_FNC(nor_reduce)
02375 DEFN_RED_FNC(xor_reduce)
02376 DEFN_RED_FNC(xnor_reduce)
02377 
02378 #undef DEFN_RED_FNC
02379 
02380 
02381 // query parameter
02382 
02383 inline
02384 int
02385 sc_fxnum_fast_subref::length() const
02386 {
02387     return m_bv.length();
02388 }
02389 
02390 
02391 // explicit conversions
02392 
02393 inline
02394 int
02395 sc_fxnum_fast_subref::to_int() const
02396 {
02397     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02398     get();
02399     return m_bv.to_int();
02400 }
02401 
02402 inline
02403 int64
02404 sc_fxnum_fast_subref::to_int64() const
02405 {
02406     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02407     get();
02408     return m_bv.to_int64();
02409 }
02410 
02411 inline
02412 unsigned int
02413 sc_fxnum_fast_subref::to_uint() const
02414 {
02415     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02416     get();
02417     return m_bv.to_uint();
02418 }
02419 
02420 inline
02421 uint64
02422 sc_fxnum_fast_subref::to_uint64() const
02423 {
02424     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02425     get();
02426     return m_bv.to_uint64();
02427 }
02428 
02429 inline
02430 long
02431 sc_fxnum_fast_subref::to_long() const
02432 {
02433     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02434     get();
02435     return m_bv.to_long();
02436 }
02437 
02438 inline
02439 unsigned long
02440 sc_fxnum_fast_subref::to_ulong() const
02441 {
02442     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02443     get();
02444     return m_bv.to_ulong();
02445 }
02446 
02447 
02448 #ifdef SC_DT_DEPRECATED
02449 
02450 inline
02451 int
02452 sc_fxnum_fast_subref::to_signed() const
02453 {
02454     return to_int();
02455 }
02456 
02457 inline
02458 unsigned int
02459 sc_fxnum_fast_subref::to_unsigned() const
02460 {
02461     return to_uint();
02462 }
02463 
02464 #endif
02465 
02466 
02467 inline
02468 const std::string
02469 sc_fxnum_fast_subref::to_string() const
02470 {
02471     get();
02472     return m_bv.to_string();
02473 }
02474 
02475 inline
02476 const std::string
02477 sc_fxnum_fast_subref::to_string( sc_numrep numrep ) const
02478 {
02479     get();
02480     return m_bv.to_string( numrep );
02481 }
02482 
02483 inline
02484 const std::string
02485 sc_fxnum_fast_subref::to_string( sc_numrep numrep, bool w_prefix ) const
02486 {
02487     get();
02488     return m_bv.to_string( numrep, w_prefix );
02489 }
02490 
02491 
02492 // implicit conversion
02493 
02494 inline
02495 sc_fxnum_fast_subref::operator sc_bv_base () const
02496 {
02497     SC_FXNUM_FAST_OBSERVER_READ_( m_num )
02498     get();
02499     return m_bv;
02500 }
02501 
02502 
02503 inline
02504 ::std::ostream&
02505 operator << ( ::std::ostream& os, const sc_fxnum_fast_subref& a )
02506 {
02507     a.print( os );
02508     return os;
02509 }
02510 
02511 inline
02512 ::std::istream&
02513 operator >> ( ::std::istream& is, sc_fxnum_fast_subref& a )
02514 {
02515     a.scan( is );
02516     return is;
02517 }
02518 
02519 
02520 // ----------------------------------------------------------------------------
02521 //  CLASS : sc_fxnum
02522 //
02523 //  Base class for the fixed-point types; arbitrary precision.
02524 // ----------------------------------------------------------------------------
02525 
02526 inline
02527 sc_fxnum_observer*
02528 sc_fxnum::observer() const
02529 {
02530     return m_observer;
02531 }
02532 
02533 
02534 inline
02535 void
02536 sc_fxnum::cast()
02537 {
02538     SC_ERROR_IF_( ! m_rep->is_normal(), sc_core::SC_ID_INVALID_FX_VALUE_ );
02539 
02540     if( m_params.cast_switch() == SC_ON )
02541         m_rep->cast( m_params, m_q_flag, m_o_flag );
02542 }
02543 
02544 
02545 // constructors
02546 
02547 inline
02548 sc_fxnum::sc_fxnum( const sc_fxtype_params& type_params_,
02549                     sc_enc enc_,
02550                     const sc_fxcast_switch& cast_sw,
02551                     sc_fxnum_observer* observer_ )
02552 : m_rep( new scfx_rep ),
02553   m_params( type_params_, enc_, cast_sw ),
02554   m_q_flag( false ),
02555   m_o_flag( false ),
02556   m_observer( observer_ )
02557 {
02558     SC_FXNUM_OBSERVER_DEFAULT_
02559     SC_FXNUM_OBSERVER_CONSTRUCT_( *this )
02560 }
02561 
02562 #define DEFN_CTOR_T(tp,arg)                                                   \
02563 inline                                                                        \
02564 sc_fxnum::sc_fxnum( tp a,                                                     \
02565                     const sc_fxtype_params& type_params_,                     \
02566                     sc_enc enc_,                                              \
02567                     const sc_fxcast_switch& cast_sw,                          \
02568                     sc_fxnum_observer* observer_ )                            \
02569 : m_rep( new scfx_rep( arg ) ),                                               \
02570   m_params( type_params_, enc_, cast_sw ),                                    \
02571   m_q_flag( false ),                                                          \
02572   m_o_flag( false ),                                                          \
02573   m_observer( observer_ )                                                     \
02574 {                                                                             \
02575     SC_FXNUM_OBSERVER_DEFAULT_                                                \
02576     cast();                                                                   \
02577     SC_FXNUM_OBSERVER_CONSTRUCT_( *this )                                     \
02578     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
02579 }
02580 
02581 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
02582 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,*a.m_rep)
02583 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
02584 #define DEFN_CTOR_T_D(tp) DEFN_CTOR_T(tp,a.value())
02585 
02586 DEFN_CTOR_T_A(int)
02587 DEFN_CTOR_T_A(unsigned int)
02588 DEFN_CTOR_T_A(long)
02589 DEFN_CTOR_T_A(unsigned long)
02590 DEFN_CTOR_T_A(double)
02591 DEFN_CTOR_T_A(const char*)
02592 DEFN_CTOR_T_B(const sc_fxval&)
02593 DEFN_CTOR_T_C(const sc_fxval_fast&)
02594 DEFN_CTOR_T_B(const sc_fxnum&)
02595 DEFN_CTOR_T_C(const sc_fxnum_fast&)
02596 #ifndef SC_FX_EXCLUDE_OTHER
02597 DEFN_CTOR_T_A(int64)
02598 DEFN_CTOR_T_A(uint64)
02599 DEFN_CTOR_T_D(const sc_int_base&)
02600 DEFN_CTOR_T_D(const sc_uint_base&)
02601 DEFN_CTOR_T_A(const sc_signed&)
02602 DEFN_CTOR_T_A(const sc_unsigned&)
02603 #endif
02604 
02605 #undef DEFN_CTOR_T
02606 #undef DEFN_CTOR_T_A
02607 #undef DEFN_CTOR_T_B
02608 #undef DEFN_CTOR_T_C
02609 #undef DEFN_CTOR_T_D
02610 
02611 
02612 inline
02613 sc_fxnum::~sc_fxnum()
02614 {
02615     SC_FXNUM_OBSERVER_DESTRUCT_( *this )
02616     delete m_rep;
02617 }
02618 
02619 
02620 // internal use only;
02621 inline
02622 const scfx_rep*
02623 sc_fxnum::get_rep() const
02624 {
02625     SC_FXNUM_OBSERVER_READ_( *this )
02626     return m_rep;
02627 }
02628 
02629 
02630 // unary operators
02631 
02632 inline
02633 const sc_fxval
02634 sc_fxnum::operator - () const
02635 {
02636     SC_FXNUM_OBSERVER_READ_( *this )
02637     return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
02638 }
02639 
02640 inline
02641 const sc_fxval
02642 sc_fxnum::operator + () const
02643 {
02644     SC_FXNUM_OBSERVER_READ_( *this )
02645     return sc_fxval( new scfx_rep( *m_rep ) );
02646 }
02647 
02648 
02649 // unary functions
02650 
02651 inline
02652 void
02653 neg( sc_fxval& c, const sc_fxnum& a )
02654 {
02655     SC_FXNUM_OBSERVER_READ_( a )
02656     c.set_rep( sc_dt::neg_scfx_rep( *a.m_rep ) );
02657 }
02658 
02659 inline
02660 void
02661 neg( sc_fxnum& c, const sc_fxnum& a )
02662 {
02663     SC_FXNUM_OBSERVER_READ_( a )
02664     delete c.m_rep;
02665     c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
02666     c.cast();
02667     SC_FXNUM_OBSERVER_WRITE_( c )
02668 }
02669 
02670 
02671 // binary operators
02672 
02673 #define DEFN_BIN_OP_T(op,fnc,tp)                                              \
02674 inline                                                                        \
02675 const sc_fxval                                                                \
02676 operator op ( const sc_fxnum& a, tp b )                                       \
02677 {                                                                             \
02678     SC_FXNUM_OBSERVER_READ_( a )                                              \
02679     sc_fxval tmp( b );                                                        \
02680     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );  \
02681 }                                                                             \
02682                                                                               \
02683 inline                                                                        \
02684 const sc_fxval                                                                \
02685 operator op ( tp a, const sc_fxnum& b )                                       \
02686 {                                                                             \
02687     SC_FXNUM_OBSERVER_READ_( b )                                              \
02688     sc_fxval tmp( a );                                                        \
02689     return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );  \
02690 }
02691 
02692 #ifndef SC_FX_EXCLUDE_OTHER
02693 #define DEFN_BIN_OP_OTHER(op,fnc)                                             \
02694 DEFN_BIN_OP_T(op,fnc,int64)                                                   \
02695 DEFN_BIN_OP_T(op,fnc,uint64)                                                  \
02696 DEFN_BIN_OP_T(op,fnc,const sc_int_base&)                                      \
02697 DEFN_BIN_OP_T(op,fnc,const sc_uint_base&)                                     \
02698 DEFN_BIN_OP_T(op,fnc,const sc_signed&)                                        \
02699 DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
02700 #else
02701 #define DEFN_BIN_OP_OTHER(op,fnc)
02702 #endif
02703 
02704 #define DEFN_BIN_OP(op,fnc)                                                   \
02705 inline                                                                        \
02706 const sc_fxval                                                                \
02707 operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
02708 {                                                                             \
02709     SC_FXNUM_OBSERVER_READ_( a )                                              \
02710     SC_FXNUM_OBSERVER_READ_( b )                                              \
02711     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );        \
02712 }                                                                             \
02713                                                                               \
02714 inline                                                                        \
02715 const sc_fxval                                                                \
02716 operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
02717 {                                                                             \
02718     SC_FXNUM_OBSERVER_READ_( a )                                              \
02719     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );    \
02720 }                                                                             \
02721                                                                               \
02722 inline                                                                        \
02723 const sc_fxval                                                                \
02724 operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
02725 {                                                                             \
02726     SC_FXNUM_OBSERVER_READ_( b )                                              \
02727     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );    \
02728 }                                                                             \
02729                                                                               \
02730 DEFN_BIN_OP_T(op,fnc,int)                                                     \
02731 DEFN_BIN_OP_T(op,fnc,unsigned int)                                            \
02732 DEFN_BIN_OP_T(op,fnc,long)                                                    \
02733 DEFN_BIN_OP_T(op,fnc,unsigned long)                                           \
02734 DEFN_BIN_OP_T(op,fnc,double)                                                  \
02735 DEFN_BIN_OP_T(op,fnc,const char*)                                             \
02736 DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
02737 DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
02738 DEFN_BIN_OP_OTHER(op,fnc)
02739 
02740 DEFN_BIN_OP(*,mult)
02741 DEFN_BIN_OP(+,add)
02742 DEFN_BIN_OP(-,sub)
02743 // don't use macros
02744 //DEFN_BIN_OP(/,div)
02745 inline
02746 const sc_fxval
02747 operator / ( const sc_fxnum& a, const sc_fxnum& b )
02748 {
02749     SC_FXNUM_OBSERVER_READ_( a )
02750     SC_FXNUM_OBSERVER_READ_( b )
02751     return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
02752 }
02753 
02754 inline
02755 const sc_fxval
02756 operator / ( const sc_fxnum& a, const sc_fxval& b )
02757 {
02758     SC_FXNUM_OBSERVER_READ_( a )
02759     return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.get_rep() ) );
02760 }
02761 
02762 inline
02763 const sc_fxval
02764 operator / ( const sc_fxval& a, const sc_fxnum& b )
02765 {
02766     SC_FXNUM_OBSERVER_READ_( b )
02767     return sc_fxval( sc_dt::div_scfx_rep( *a.get_rep(), *b.m_rep ) );
02768 }
02769 
02770 DEFN_BIN_OP_T(/,div,int)
02771 DEFN_BIN_OP_T(/,div,unsigned int)
02772 DEFN_BIN_OP_T(/,div,long)
02773 DEFN_BIN_OP_T(/,div,unsigned long)
02774 DEFN_BIN_OP_T(/,div,double)
02775 DEFN_BIN_OP_T(/,div,const char*)
02776 DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
02777 DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
02778 //DEFN_BIN_OP_OTHER(/,div)
02779 #ifndef SC_FX_EXCLUDE_OTHER
02780 DEFN_BIN_OP_T(/,div,int64)
02781 DEFN_BIN_OP_T(/,div,uint64)
02782 DEFN_BIN_OP_T(/,div,const sc_int_base&)
02783 DEFN_BIN_OP_T(/,div,const sc_uint_base&)
02784 DEFN_BIN_OP_T(/,div,const sc_signed&)
02785 DEFN_BIN_OP_T(/,div,const sc_unsigned&)
02786 #endif
02787 
02788 #undef DEFN_BIN_OP_T
02789 #undef DEFN_BIN_OP_OTHER
02790 #undef DEFN_BIN_OP
02791 
02792 
02793 inline
02794 const sc_fxval
02795 operator << ( const sc_fxnum& a, int b )
02796 {
02797     SC_FXNUM_OBSERVER_READ_( a )
02798     return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
02799 }
02800 
02801 inline
02802 const sc_fxval
02803 operator >> ( const sc_fxnum& a, int b )
02804 {
02805     SC_FXNUM_OBSERVER_READ_( a )
02806     return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
02807 }
02808 
02809 
02810 // binary functions
02811 
02812 #define DEFN_BIN_FNC_T(fnc,tp)                                                \
02813 inline                                                                        \
02814 void                                                                          \
02815 fnc ( sc_fxval& c, const sc_fxnum& a, tp b )                                  \
02816 {                                                                             \
02817     SC_FXNUM_OBSERVER_READ_( a )                                              \
02818     sc_fxval tmp( b );                                                        \
02819     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );        \
02820 }                                                                             \
02821                                                                               \
02822 inline                                                                        \
02823 void                                                                          \
02824 fnc ( sc_fxval& c, tp a, const sc_fxnum& b )                                  \
02825 {                                                                             \
02826     SC_FXNUM_OBSERVER_READ_( b )                                              \
02827     sc_fxval tmp( a );                                                        \
02828     c.set_rep( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );        \
02829 }                                                                             \
02830                                                                               \
02831 inline                                                                        \
02832 void                                                                          \
02833 fnc ( sc_fxnum& c, const sc_fxnum& a, tp b )                                  \
02834 {                                                                             \
02835     SC_FXNUM_OBSERVER_READ_( a )                                              \
02836     sc_fxval tmp( b );                                                        \
02837     delete c.m_rep;                                                           \
02838     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() );           \
02839     c.cast();                                                                 \
02840     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02841 }                                                                             \
02842                                                                               \
02843 inline                                                                        \
02844 void                                                                          \
02845 fnc ( sc_fxnum& c, tp a, const sc_fxnum& b )                                  \
02846 {                                                                             \
02847     SC_FXNUM_OBSERVER_READ_( b )                                              \
02848     sc_fxval tmp( a );                                                        \
02849     delete c.m_rep;                                                           \
02850     c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep );           \
02851     c.cast();                                                                 \
02852     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02853 }
02854 
02855 #ifndef SC_FX_EXCLUDE_OTHER
02856 #define DEFN_BIN_FNC_OTHER(fnc)                                               \
02857 DEFN_BIN_FNC_T(fnc,int64)                                                     \
02858 DEFN_BIN_FNC_T(fnc,uint64)                                                    \
02859 DEFN_BIN_FNC_T(fnc,const sc_int_base&)                                        \
02860 DEFN_BIN_FNC_T(fnc,const sc_uint_base&)                                       \
02861 DEFN_BIN_FNC_T(fnc,const sc_signed&)                                          \
02862 DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
02863 #else
02864 #define DEFN_BIN_FNC_OTHER(fnc)
02865 #endif
02866 
02867 #define DEFN_BIN_FNC(fnc)                                                     \
02868 inline                                                                        \
02869 void                                                                          \
02870 fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxnum& b )                     \
02871 {                                                                             \
02872     SC_FXNUM_OBSERVER_READ_( a )                                              \
02873     SC_FXNUM_OBSERVER_READ_( b )                                              \
02874     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );              \
02875 }                                                                             \
02876                                                                               \
02877 inline                                                                        \
02878 void                                                                          \
02879 fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxnum& b )                     \
02880 {                                                                             \
02881     SC_FXNUM_OBSERVER_READ_( a )                                              \
02882     SC_FXNUM_OBSERVER_READ_( b )                                              \
02883     delete c.m_rep;                                                           \
02884     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep );                 \
02885     c.cast();                                                                 \
02886     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02887 }                                                                             \
02888                                                                               \
02889 inline                                                                        \
02890 void                                                                          \
02891 fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxval& b )                     \
02892 {                                                                             \
02893     SC_FXNUM_OBSERVER_READ_( a )                                              \
02894     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );          \
02895 }                                                                             \
02896                                                                               \
02897 inline                                                                        \
02898 void                                                                          \
02899 fnc ( sc_fxval& c, const sc_fxval& a, const sc_fxnum& b )                     \
02900 {                                                                             \
02901     SC_FXNUM_OBSERVER_READ_( b )                                              \
02902     c.set_rep( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );          \
02903 }                                                                             \
02904                                                                               \
02905 inline                                                                        \
02906 void                                                                          \
02907 fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxval& b )                     \
02908 {                                                                             \
02909     SC_FXNUM_OBSERVER_READ_( a )                                              \
02910     delete c.m_rep;                                                           \
02911     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() );             \
02912     c.cast();                                                                 \
02913     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02914 }                                                                             \
02915                                                                               \
02916 inline                                                                        \
02917 void                                                                          \
02918 fnc ( sc_fxnum& c, const sc_fxval& a, const sc_fxnum& b )                     \
02919 {                                                                             \
02920     SC_FXNUM_OBSERVER_READ_( b )                                              \
02921     delete c.m_rep;                                                           \
02922     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep );             \
02923     c.cast();                                                                 \
02924     SC_FXNUM_OBSERVER_WRITE_( c )                                             \
02925 }                                                                             \
02926                                                                               \
02927 DEFN_BIN_FNC_T(fnc,int)                                                       \
02928 DEFN_BIN_FNC_T(fnc,unsigned int)                                              \
02929 DEFN_BIN_FNC_T(fnc,long)                                                      \
02930 DEFN_BIN_FNC_T(fnc,unsigned long)                                             \
02931 DEFN_BIN_FNC_T(fnc,double)                                                    \
02932 DEFN_BIN_FNC_T(fnc,const char*)                                               \
02933 DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&)                                      \
02934 DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                      \
02935 DEFN_BIN_FNC_OTHER(fnc)
02936 
02937 DEFN_BIN_FNC(mult)
02938 DEFN_BIN_FNC(div)
02939 DEFN_BIN_FNC(add)
02940 DEFN_BIN_FNC(sub)
02941 
02942 #undef DEFN_BIN_FNC_T
02943 #undef DEFN_BIN_FNC_OTHER
02944 #undef DEFN_BIN_FNC
02945 
02946 
02947 inline
02948 void
02949 lshift( sc_fxval& c, const sc_fxnum& a, int b )
02950 {
02951     SC_FXNUM_OBSERVER_READ_( a )
02952     c.set_rep( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
02953 }
02954 
02955 inline
02956 void
02957 rshift( sc_fxval& c, const sc_fxnum& a, int b )
02958 {
02959     SC_FXNUM_OBSERVER_READ_( a )
02960     c.set_rep( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
02961 }
02962 
02963 inline
02964 void
02965 lshift( sc_fxnum& c, const sc_fxnum& a, int b )
02966 {
02967     SC_FXNUM_OBSERVER_READ_( a )
02968     delete c.m_rep;
02969     c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
02970     c.cast();
02971     SC_FXNUM_OBSERVER_WRITE_( c )
02972 }
02973 
02974 inline
02975 void
02976 rshift( sc_fxnum& c, const sc_fxnum& a, int b )
02977 {
02978     SC_FXNUM_OBSERVER_READ_( a )
02979     delete c.m_rep;
02980     c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
02981     c.cast();
02982     SC_FXNUM_OBSERVER_WRITE_( c )
02983 }
02984 
02985 
02986 // relational (including equality) operators
02987 
02988 #define DEFN_REL_OP_T(op,ret,tp)                                              \
02989 inline                                                                        \
02990 bool                                                                          \
02991 operator op ( const sc_fxnum& a, tp b )                                       \
02992 {                                                                             \
02993     SC_FXNUM_OBSERVER_READ_( a )                                              \
02994     sc_fxval tmp( b );                                                        \
02995     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.get_rep() );            \
02996     return ( ret );                                                           \
02997 }                                                                             \
02998                                                                               \
02999 inline                                                                        \
03000 bool                                                                          \
03001 operator op ( tp a, const sc_fxnum& b )                                       \
03002 {                                                                             \
03003     SC_FXNUM_OBSERVER_READ_( b )                                              \
03004     sc_fxval tmp( a );                                                        \
03005     int result = sc_dt::cmp_scfx_rep( *tmp.get_rep(), *b.m_rep );            \
03006     return ( ret );                                                           \
03007 }
03008 
03009 #ifndef SC_FX_EXCLUDE_OTHER
03010 #define DEFN_REL_OP_OTHER(op,ret)                                             \
03011 DEFN_REL_OP_T(op,ret,int64)                                                   \
03012 DEFN_REL_OP_T(op,ret,uint64)                                                  \
03013 DEFN_REL_OP_T(op,ret,const sc_int_base&)                                      \
03014 DEFN_REL_OP_T(op,ret,const sc_uint_base&)                                     \
03015 DEFN_REL_OP_T(op,ret,const sc_signed&)                                        \
03016 DEFN_REL_OP_T(op,ret,const sc_unsigned&)
03017 #else
03018 #define DEFN_REL_OP_OTHER(op,ret)
03019 #endif
03020 
03021 #define DEFN_REL_OP(op,ret)                                                   \
03022 inline                                                                        \
03023 bool                                                                          \
03024 operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
03025 {                                                                             \
03026     SC_FXNUM_OBSERVER_READ_( a )                                              \
03027     SC_FXNUM_OBSERVER_READ_( b )                                              \
03028     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep );                  \
03029     return ( ret );                                                           \
03030 }                                                                             \
03031                                                                               \
03032 inline                                                                        \
03033 bool                                                                          \
03034 operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
03035 {                                                                             \
03036     SC_FXNUM_OBSERVER_READ_( a )                                              \
03037     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.get_rep() );              \
03038     return ( ret );                                                           \
03039 }                                                                             \
03040                                                                               \
03041 inline                                                                        \
03042 bool                                                                          \
03043 operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
03044 {                                                                             \
03045     SC_FXNUM_OBSERVER_READ_( b )                                              \
03046     int result = sc_dt::cmp_scfx_rep( *a.get_rep(), *b.m_rep );              \
03047     return ( ret );                                                           \
03048 }                                                                             \
03049                                                                               \
03050 DEFN_REL_OP_T(op,ret,int)                                                     \
03051 DEFN_REL_OP_T(op,ret,unsigned int)                                            \
03052 DEFN_REL_OP_T(op,ret,long)                                                    \
03053 DEFN_REL_OP_T(op,ret,unsigned long)                                           \
03054 DEFN_REL_OP_T(op,ret,double)                                                  \
03055 DEFN_REL_OP_T(op,ret,const char*)                                             \
03056 DEFN_REL_OP_T(op,ret,const sc_fxval_fast&)                                    \
03057 DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)                                    \
03058 DEFN_REL_OP_OTHER(op,ret)
03059 
03060 DEFN_REL_OP(<,result < 0)
03061 DEFN_REL_OP(<=,result <= 0)
03062 DEFN_REL_OP(>,result > 0 && result != 2)
03063 DEFN_REL_OP(>=,result >= 0 && result != 2)
03064 DEFN_REL_OP(==,result == 0)
03065 DEFN_REL_OP(!=,result != 0)
03066 
03067 #undef DEFN_REL_OP_T
03068 #undef DEFN_REL_OP_OTHER
03069 #undef DEFN_REL_OP
03070 
03071 
03072 // assignment operators
03073 
03074 inline
03075 sc_fxnum&
03076 sc_fxnum::operator = ( const sc_fxnum& a )
03077 {
03078     if( &a != this )
03079     {
03080         SC_FXNUM_OBSERVER_READ_( a )
03081         *m_rep = *a.m_rep;
03082         cast();
03083         SC_FXNUM_OBSERVER_WRITE_( *this )
03084     }
03085     return *this;
03086 }
03087 
03088 inline
03089 sc_fxnum&
03090 sc_fxnum::operator = ( const sc_fxval& a )
03091 {
03092     *m_rep = *a.get_rep();
03093     cast();
03094     SC_FXNUM_OBSERVER_WRITE_( *this )
03095     return *this;
03096 }
03097 
03098 #define DEFN_ASN_OP_T(tp)                                                     \
03099 inline                                                                        \
03100 sc_fxnum&                                                                     \
03101 sc_fxnum::operator = ( tp a )                                                 \
03102 {                                                                             \
03103     sc_fxval tmp( a );                                                        \
03104     *m_rep = *tmp.get_rep();                                                  \
03105     cast();                                                                   \
03106     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03107     return *this;                                                             \
03108 }
03109 
03110 DEFN_ASN_OP_T(int)
03111 DEFN_ASN_OP_T(unsigned int)
03112 DEFN_ASN_OP_T(long)
03113 DEFN_ASN_OP_T(unsigned long)
03114 DEFN_ASN_OP_T(double)
03115 DEFN_ASN_OP_T(const char*)
03116 DEFN_ASN_OP_T(const sc_fxval_fast&)
03117 DEFN_ASN_OP_T(const sc_fxnum_fast&)
03118 #ifndef SC_FX_EXCLUDE_OTHER
03119 DEFN_ASN_OP_T(int64)
03120 DEFN_ASN_OP_T(uint64)
03121 DEFN_ASN_OP_T(const sc_int_base&)
03122 DEFN_ASN_OP_T(const sc_uint_base&)
03123 DEFN_ASN_OP_T(const sc_signed&)
03124 DEFN_ASN_OP_T(const sc_unsigned&)
03125 #endif
03126 
03127 #undef DEFN_ASN_OP_T
03128 
03129 
03130 #define DEFN_ASN_OP_T(op,fnc,tp)                                              \
03131 inline                                                                        \
03132 sc_fxnum&                                                                     \
03133 sc_fxnum::operator op ( tp b )                                                \
03134 {                                                                             \
03135     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03136     sc_fxval tmp( b );                                                        \
03137     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.get_rep() );   \
03138     delete m_rep;                                                             \
03139     m_rep = new_rep;                                                          \
03140     cast();                                                                   \
03141     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03142     return *this;                                                             \
03143 }
03144 
03145 #ifndef SC_FX_EXCLUDE_OTHER
03146 #define DEFN_ASN_OP_OTHER(op,fnc)                                             \
03147 DEFN_ASN_OP_T(op,fnc,int64)                                                   \
03148 DEFN_ASN_OP_T(op,fnc,uint64)                                                  \
03149 DEFN_ASN_OP_T(op,fnc,const sc_int_base&)                                      \
03150 DEFN_ASN_OP_T(op,fnc,const sc_uint_base&)                                     \
03151 DEFN_ASN_OP_T(op,fnc,const sc_signed&)                                        \
03152 DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
03153 #else
03154 #define DEFN_ASN_OP_OTHER(op,fnc)
03155 #endif
03156 
03157 #define DEFN_ASN_OP(op,fnc)                                                   \
03158 inline                                                                        \
03159 sc_fxnum&                                                                     \
03160 sc_fxnum::operator op ( const sc_fxnum& b )                                   \
03161 {                                                                             \
03162     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03163     SC_FXNUM_OBSERVER_READ_( b )                                              \
03164     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep );         \
03165     delete m_rep;                                                             \
03166     m_rep = new_rep;                                                          \
03167     cast();                                                                   \
03168     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03169     return *this;                                                             \
03170 }                                                                             \
03171                                                                               \
03172 inline                                                                        \
03173 sc_fxnum&                                                                     \
03174 sc_fxnum::operator op ( const sc_fxval& b )                                   \
03175 {                                                                             \
03176     SC_FXNUM_OBSERVER_READ_( *this )                                          \
03177     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
03178     delete m_rep;                                                             \
03179     m_rep = new_rep;                                                          \
03180     cast();                                                                   \
03181     SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
03182     return *this;                                                             \
03183 }                                                                             \
03184                                                                               \
03185 DEFN_ASN_OP_T(op,fnc,int)                                                     \
03186 DEFN_ASN_OP_T(op,fnc,unsigned int)                                            \
03187 DEFN_ASN_OP_T(op,fnc,long)                                                    \
03188 DEFN_ASN_OP_T(op,fnc,unsigned long)                                           \
03189 DEFN_ASN_OP_T(op,fnc,double)                                                  \
03190 DEFN_ASN_OP_T(op,fnc,const char*)                                             \
03191 DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
03192 DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
03193 DEFN_ASN_OP_OTHER(op,fnc)
03194 
03195 DEFN_ASN_OP(*=,mult)
03196 DEFN_ASN_OP(/=,div)
03197 DEFN_ASN_OP(+=,add)
03198 DEFN_ASN_OP(-=,sub)
03199 
03200 #undef DEFN_ASN_OP_T
03201 #undef DEFN_ASN_OP_OTHER
03202 #undef DEFN_ASN_OP
03203 
03204 
03205 inline
03206 sc_fxnum&
03207 sc_fxnum::operator <<= ( int b )
03208 {
03209     SC_FXNUM_OBSERVER_READ_( *this )
03210     m_rep->lshift( b );
03211     cast();
03212     SC_FXNUM_OBSERVER_WRITE_( *this )
03213     return *this;
03214 }
03215 
03216 inline
03217 sc_fxnum&
03218 sc_fxnum::operator >>= ( int b )
03219 {
03220     SC_FXNUM_OBSERVER_READ_( *this )
03221     m_rep->rshift( b );
03222     cast();
03223     SC_FXNUM_OBSERVER_WRITE_( *this )
03224     return *this;
03225 }
03226 
03227 
03228 // auto-increment and auto-decrement
03229 
03230 inline
03231 const sc_fxval
03232 sc_fxnum::operator ++ ( int )
03233 {
03234     sc_fxval c( *this );
03235     (*this) += 1;
03236     return c;
03237 }
03238 
03239 inline
03240 const sc_fxval
03241 sc_fxnum::operator -- ( int )
03242 {
03243     sc_fxval c( *this );
03244     (*this) -= 1;
03245     return c;
03246 }
03247 
03248 inline
03249 sc_fxnum&
03250 sc_fxnum::operator ++ ()
03251 {
03252     (*this) += 1;
03253     return *this;
03254 }
03255 
03256 inline
03257 sc_fxnum&
03258 sc_fxnum::operator -- ()
03259 {
03260     (*this) -= 1;
03261     return *this;
03262 }
03263 
03264 
03265 // bit selection
03266 
03267 inline
03268 const sc_fxnum_bitref
03269 sc_fxnum::operator [] ( int i ) const
03270 {
03271     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03272     return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
03273                             i - m_params.fwl() );
03274 }
03275 
03276 inline
03277 sc_fxnum_bitref
03278 sc_fxnum::operator [] ( int i )
03279 {
03280     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03281     return sc_fxnum_bitref( *this, i - m_params.fwl() );
03282 }
03283 
03284 inline
03285 const sc_fxnum_bitref
03286 sc_fxnum::bit( int i ) const
03287 {
03288     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03289     return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
03290                             i - m_params.fwl() );
03291 }
03292 
03293 inline
03294 sc_fxnum_bitref
03295 sc_fxnum::bit( int i )
03296 {
03297     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03298     return sc_fxnum_bitref( *this, i - m_params.fwl() );
03299 }
03300 
03301 
03302 // part selection
03303 
03304 inline
03305 const sc_fxnum_subref
03306 sc_fxnum::operator () ( int i, int j ) const
03307 {
03308     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03309     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03310 
03311     return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
03312                             i - m_params.fwl(), j - m_params.fwl() );
03313 }
03314 
03315 inline
03316 sc_fxnum_subref
03317 sc_fxnum::operator () ( int i, int j )
03318 {
03319     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03320     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03321 
03322     return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
03323 }
03324 
03325 inline
03326 const sc_fxnum_subref
03327 sc_fxnum::range( int i, int j ) const
03328 {
03329     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03330     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03331 
03332     return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
03333                             i - m_params.fwl(), j - m_params.fwl() );
03334 }
03335 
03336 inline
03337 sc_fxnum_subref
03338 sc_fxnum::range( int i, int j )
03339 {
03340     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03341     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
03342 
03343     return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
03344 }
03345 
03346 
03347 inline
03348 const sc_fxnum_subref
03349 sc_fxnum::operator () () const
03350 {
03351     return this->operator () ( m_params.wl() - 1, 0 );
03352 }
03353 
03354 inline
03355 sc_fxnum_subref
03356 sc_fxnum::operator () ()
03357 {
03358     return this->operator () ( m_params.wl() - 1, 0 );
03359 }
03360 
03361 inline
03362 const sc_fxnum_subref
03363 sc_fxnum::range() const
03364 {
03365     return this->range( m_params.wl() - 1, 0 );
03366 }
03367 
03368 inline
03369 sc_fxnum_subref
03370 sc_fxnum::range()
03371 {
03372     return this->range( m_params.wl() - 1, 0 );
03373 }
03374 
03375 
03376 // implicit conversion
03377 
03378 inline
03379 sc_fxnum::operator double() const
03380 {
03381     SC_FXNUM_OBSERVER_READ_( *this )
03382     return m_rep->to_double();
03383 }
03384 
03385 
03386 // explicit conversion to primitive types
03387 
03388 inline
03389 short
03390 sc_fxnum::to_short() const
03391 {
03392     SC_FXNUM_OBSERVER_READ_( *this )
03393     return static_cast<short>( m_rep->to_double() );
03394 }
03395 
03396 inline
03397 unsigned short
03398 sc_fxnum::to_ushort() const
03399 {
03400     SC_FXNUM_OBSERVER_READ_( *this )
03401     return static_cast<unsigned short>( m_rep->to_double() );
03402 }
03403 
03404 inline
03405 int
03406 sc_fxnum::to_int() const
03407 {
03408     SC_FXNUM_OBSERVER_READ_( *this )
03409     return static_cast<int>( m_rep->to_double() );
03410 }
03411 
03412 inline
03413 int64
03414 sc_fxnum::to_int64() const
03415 {
03416     SC_FXNUM_OBSERVER_READ_( *this )
03417     return static_cast<int64>( m_rep->to_double() );
03418 }
03419 
03420 inline
03421 unsigned int
03422 sc_fxnum::to_uint() const
03423 {
03424     SC_FXNUM_OBSERVER_READ_( *this )
03425     return static_cast<unsigned int>( m_rep->to_double() );
03426 }
03427 
03428 inline
03429 uint64
03430 sc_fxnum::to_uint64() const
03431 {
03432     SC_FXNUM_OBSERVER_READ_( *this )
03433     return static_cast<uint64>( m_rep->to_double() );
03434 }
03435 
03436 inline
03437 long
03438 sc_fxnum::to_long() const
03439 {
03440     SC_FXNUM_OBSERVER_READ_( *this )
03441     return static_cast<long>( m_rep->to_double() );
03442 }
03443 
03444 inline
03445 unsigned long
03446 sc_fxnum::to_ulong() const
03447 {
03448     SC_FXNUM_OBSERVER_READ_( *this )
03449     return static_cast<unsigned long>( m_rep->to_double() );
03450 }
03451 
03452 inline
03453 float
03454 sc_fxnum::to_float() const
03455 {
03456     SC_FXNUM_OBSERVER_READ_( *this )
03457     return static_cast<float>( m_rep->to_double() );
03458 }
03459 
03460 inline
03461 double
03462 sc_fxnum::to_double() const
03463 {
03464     SC_FXNUM_OBSERVER_READ_( *this )
03465     return m_rep->to_double();
03466 }
03467 
03468 
03469 // query value
03470 
03471 inline
03472 bool
03473 sc_fxnum::is_neg() const
03474 {
03475     SC_FXNUM_OBSERVER_READ_( *this )
03476     return m_rep->is_neg();
03477 }
03478 
03479 inline
03480 bool
03481 sc_fxnum::is_zero() const
03482 {
03483     SC_FXNUM_OBSERVER_READ_( *this )
03484     return m_rep->is_zero();
03485 }
03486 
03487 // internal use only;
03488 inline
03489 bool
03490 sc_fxnum::is_normal() const
03491 {
03492     SC_FXNUM_OBSERVER_READ_( *this )
03493     return m_rep->is_normal();
03494 }
03495 
03496 inline
03497 bool
03498 sc_fxnum::quantization_flag() const
03499 {
03500     return m_q_flag;
03501 }
03502 
03503 inline
03504 bool
03505 sc_fxnum::overflow_flag() const
03506 {
03507     return m_o_flag;
03508 }
03509 
03510 
03511 inline
03512 const sc_fxval
03513 sc_fxnum::value() const
03514 {
03515     SC_FXNUM_OBSERVER_READ_( *this )
03516     return sc_fxval( new scfx_rep( *m_rep ) );
03517 }
03518 
03519 
03520 // query parameters
03521 
03522 inline
03523 int
03524 sc_fxnum::wl() const
03525 {
03526     return m_params.wl();
03527 }
03528 
03529 inline
03530 int
03531 sc_fxnum::iwl() const
03532 {
03533     return m_params.iwl();
03534 }
03535 
03536 inline
03537 sc_q_mode
03538 sc_fxnum::q_mode() const
03539 {
03540     return m_params.q_mode();
03541 }
03542 
03543 inline
03544 sc_o_mode
03545 sc_fxnum::o_mode() const
03546 {
03547     return m_params.o_mode();
03548 }
03549 
03550 inline
03551 int
03552 sc_fxnum::n_bits() const
03553 {
03554     return m_params.n_bits();
03555 }
03556 
03557 
03558 inline
03559 const sc_fxtype_params&
03560 sc_fxnum::type_params() const
03561 {
03562     return m_params.type_params();
03563 }
03564 
03565 
03566 inline
03567 const sc_fxcast_switch&
03568 sc_fxnum::cast_switch() const
03569 {
03570     return m_params.cast_switch();
03571 }
03572 
03573 
03574 // internal use only;
03575 inline
03576 void
03577 sc_fxnum::observer_read() const
03578 {
03579     SC_FXNUM_OBSERVER_READ_( *this );
03580 }
03581 
03582 
03583 // internal use only;
03584 inline
03585 bool
03586 sc_fxnum::get_bit( int i ) const
03587 {
03588     return m_rep->get_bit( i );
03589 }
03590 
03591 
03592 // protected methods and friend functions
03593 
03594 inline
03595 bool
03596 sc_fxnum::set_bit( int i, bool high )
03597 {
03598     if( high )
03599         return m_rep->set( i, m_params );
03600     else
03601         return m_rep->clear( i, m_params );
03602 }
03603 
03604 
03605 inline
03606 bool
03607 sc_fxnum::get_slice( int i, int j, sc_bv_base& bv ) const
03608 {
03609     return m_rep->get_slice( i, j, m_params, bv );
03610 }
03611 
03612 inline
03613 bool
03614 sc_fxnum::set_slice( int i, int j, const sc_bv_base& bv )
03615 {
03616     return m_rep->set_slice( i, j, m_params, bv );
03617 }
03618 
03619 
03620 inline
03621 ::std::ostream&
03622 operator << ( ::std::ostream& os, const sc_fxnum& a )
03623 {
03624     a.print( os );
03625     return os;
03626 }
03627 
03628 inline
03629 ::std::istream&
03630 operator >> ( ::std::istream& is, sc_fxnum& a )
03631 {
03632     a.scan( is );
03633     return is;
03634 }
03635 
03636 
03637 // ----------------------------------------------------------------------------
03638 //  CLASS : sc_fxnum_fast
03639 //
03640 //  Base class for the fixed-point types; limited precision.
03641 // ----------------------------------------------------------------------------
03642 
03643 inline
03644 sc_fxnum_fast_observer*
03645 sc_fxnum_fast::observer() const
03646 {
03647     return m_observer;
03648 }
03649 
03650 
03651 // constructors
03652 
03653 inline
03654 sc_fxnum_fast::sc_fxnum_fast( const sc_fxtype_params& type_params_,
03655                               sc_enc enc_,
03656                               const sc_fxcast_switch& cast_sw,
03657                               sc_fxnum_fast_observer* observer_ )
03658 : m_val( 0.0 ),
03659   m_params( type_params_, enc_, cast_sw ),
03660   m_q_flag( false ),
03661   m_o_flag( false ),
03662   m_observer( observer_ )
03663 {
03664     SC_FXNUM_FAST_OBSERVER_DEFAULT_
03665     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)
03666 }
03667 
03668 inline
03669 sc_fxnum_fast::sc_fxnum_fast( const sc_fxnum_fast& a,
03670                               const sc_fxtype_params& type_params_,
03671                               sc_enc enc_,
03672                               const sc_fxcast_switch& cast_sw,
03673                               sc_fxnum_fast_observer* observer_ )
03674 : m_val( a.m_val ),
03675   m_params( type_params_, enc_, cast_sw ),
03676   m_q_flag( false ),
03677   m_o_flag( false ),
03678   m_observer( observer_ )
03679 {
03680     SC_FXNUM_FAST_OBSERVER_DEFAULT_
03681     SC_FXNUM_FAST_OBSERVER_READ_( a )
03682     cast();
03683     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_( *this )
03684     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
03685 }
03686 
03687 #define DEFN_CTOR_T(tp,arg)                                                   \
03688 inline                                                                        \
03689 sc_fxnum_fast::sc_fxnum_fast( tp a,                                           \
03690                               const sc_fxtype_params& type_params_,           \
03691                               sc_enc enc_,                                    \
03692                               const sc_fxcast_switch& cast_sw,                \
03693                               sc_fxnum_fast_observer* observer_ )             \
03694 : m_val( arg ),                                                               \
03695   m_params( type_params_, enc_, cast_sw ),                                    \
03696   m_q_flag( false ),                                                          \
03697   m_o_flag( false ),                                                          \
03698   m_observer( observer_ )                                                     \
03699 {                                                                             \
03700     SC_FXNUM_FAST_OBSERVER_DEFAULT_                                           \
03701     cast();                                                                   \
03702     SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)                                  \
03703     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
03704 }
03705 
03706 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
03707 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,sc_fxval_fast::from_string( a ))
03708 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
03709 
03710 DEFN_CTOR_T_A(int)
03711 DEFN_CTOR_T_A(unsigned int)
03712 DEFN_CTOR_T_A(long)
03713 DEFN_CTOR_T_A(unsigned long)
03714 DEFN_CTOR_T_A(double)
03715 DEFN_CTOR_T_B(const char*)
03716 DEFN_CTOR_T_C(const sc_fxval&)
03717 DEFN_CTOR_T_C(const sc_fxval_fast&)
03718 DEFN_CTOR_T_C(const sc_fxnum&)
03719 #ifndef SC_FX_EXCLUDE_OTHER
03720 DEFN_CTOR_T_A(int64)
03721 DEFN_CTOR_T_A(uint64)
03722 DEFN_CTOR_T_C(const sc_int_base&)
03723 DEFN_CTOR_T_C(const sc_uint_base&)
03724 DEFN_CTOR_T_C(const sc_signed&)
03725 DEFN_CTOR_T_C(const sc_unsigned&)
03726 #endif
03727 
03728 #undef DEFN_CTOR_T
03729 #undef DEFN_CTOR_T_A
03730 #undef DEFN_CTOR_T_B
03731 #undef DEFN_CTOR_T_C
03732 #undef DEFN_CTOR_T_D
03733 #undef DEFN_CTOR_T_E
03734 
03735 
03736 inline
03737 sc_fxnum_fast::~sc_fxnum_fast()
03738 {
03739     SC_FXNUM_FAST_OBSERVER_DESTRUCT_( *this )
03740 }
03741 
03742 
03743 // internal use only;
03744 inline
03745 double
03746 sc_fxnum_fast::get_val() const
03747 {
03748     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03749     return m_val;
03750 }
03751 
03752 
03753 // unary operators
03754 
03755 inline
03756 const sc_fxval_fast
03757 sc_fxnum_fast::operator - () const
03758 {
03759     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03760     return sc_fxval_fast( - m_val );
03761 }
03762 
03763 inline
03764 const sc_fxval_fast
03765 sc_fxnum_fast::operator + () const
03766 {
03767     SC_FXNUM_FAST_OBSERVER_READ_( *this )
03768     return sc_fxval_fast( m_val );
03769 }
03770 
03771 
03772 // unary functions
03773 
03774 inline
03775 void
03776 neg( sc_fxval_fast& c, const sc_fxnum_fast& a )
03777 {
03778     SC_FXNUM_FAST_OBSERVER_READ_( a )
03779     c.set_val( - a.m_val );
03780 }
03781 
03782 inline
03783 void
03784 neg( sc_fxnum_fast& c, const sc_fxnum_fast& a )
03785 {
03786     SC_FXNUM_FAST_OBSERVER_READ_( a )
03787     c.m_val = - a.m_val;
03788     c.cast();
03789     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
03790 }
03791 
03792 
03793 // binary operators
03794 
03795 #define DEFN_BIN_OP_T(op,tp)                                                  \
03796 inline                                                                        \
03797 const sc_fxval_fast                                                           \
03798 operator op ( const sc_fxnum_fast& a, tp b )                                  \
03799 {                                                                             \
03800     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03801     sc_fxval_fast tmp( b );                                                   \
03802     return sc_fxval_fast( a.m_val op tmp.get_val() );                         \
03803 }                                                                             \
03804                                                                               \
03805 inline                                                                        \
03806 const sc_fxval_fast                                                           \
03807 operator op ( tp a, const sc_fxnum_fast& b )                                  \
03808 {                                                                             \
03809     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03810     sc_fxval_fast tmp( a );                                                   \
03811     return sc_fxval_fast( tmp.get_val() op b.m_val );                         \
03812 }
03813 
03814 #ifndef SC_FX_EXCLUDE_OTHER
03815 #define DEFN_BIN_OP_OTHER(op)                                                 \
03816 DEFN_BIN_OP_T(op,int64)                                                       \
03817 DEFN_BIN_OP_T(op,uint64)                                                      \
03818 DEFN_BIN_OP_T(op,const sc_int_base&)                                          \
03819 DEFN_BIN_OP_T(op,const sc_uint_base&)                                         \
03820 DEFN_BIN_OP_T(op,const sc_signed&)                                            \
03821 DEFN_BIN_OP_T(op,const sc_unsigned&)
03822 #else
03823 #define DEFN_BIN_OP_OTHER(op)
03824 #endif
03825 
03826 #define DEFN_BIN_OP(op,dummy)                                                 \
03827 inline                                                                        \
03828 const sc_fxval_fast                                                           \
03829 operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
03830 {                                                                             \
03831     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03832     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03833     return sc_fxval_fast( a.m_val op b.m_val );                               \
03834 }                                                                             \
03835                                                                               \
03836 inline                                                                        \
03837 const sc_fxval_fast                                                           \
03838 operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
03839 {                                                                             \
03840     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03841     return sc_fxval_fast( a.m_val op b.get_val() );                           \
03842 }                                                                             \
03843                                                                               \
03844 inline                                                                        \
03845 const sc_fxval_fast                                                           \
03846 operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
03847 {                                                                             \
03848     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03849     return sc_fxval_fast( a.get_val() op b.m_val );                           \
03850 }                                                                             \
03851                                                                               \
03852 DEFN_BIN_OP_T(op,int)                                                         \
03853 DEFN_BIN_OP_T(op,unsigned int)                                                \
03854 DEFN_BIN_OP_T(op,long)                                                        \
03855 DEFN_BIN_OP_T(op,unsigned long)                                               \
03856 DEFN_BIN_OP_T(op,double)                                                      \
03857 DEFN_BIN_OP_T(op,const char*)                                                 \
03858 DEFN_BIN_OP_OTHER(op)
03859 
03860 DEFN_BIN_OP(*,mult)
03861 DEFN_BIN_OP(+,add)
03862 DEFN_BIN_OP(-,sub)
03863 //DEFN_BIN_OP(/,div)
03864 inline
03865 const sc_fxval_fast
03866 operator / ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )
03867 {
03868     SC_FXNUM_FAST_OBSERVER_READ_( a )
03869     SC_FXNUM_FAST_OBSERVER_READ_( b )
03870     return sc_fxval_fast( a.m_val / b.m_val );
03871 }
03872 
03873 inline
03874 const sc_fxval_fast
03875 operator / ( const sc_fxnum_fast& a, const sc_fxval_fast& b )
03876 {
03877     SC_FXNUM_FAST_OBSERVER_READ_( a )
03878     return sc_fxval_fast( a.m_val / b.get_val() );
03879 }
03880 
03881 inline
03882 const sc_fxval_fast
03883 operator / ( const sc_fxval_fast& a, const sc_fxnum_fast& b )
03884 {
03885     SC_FXNUM_FAST_OBSERVER_READ_( b )
03886     return sc_fxval_fast( a.get_val() / b.m_val );
03887 }
03888 
03889 DEFN_BIN_OP_T(/,int)
03890 DEFN_BIN_OP_T(/,unsigned int)
03891 DEFN_BIN_OP_T(/,long)
03892 DEFN_BIN_OP_T(/,unsigned long)
03893 DEFN_BIN_OP_T(/,double)
03894 DEFN_BIN_OP_T(/,const char*)
03895 //DEFN_BIN_OP_OTHER(/)
03896 #ifndef SC_FX_EXCLUDE_OTHER
03897 DEFN_BIN_OP_T(/,int64)
03898 DEFN_BIN_OP_T(/,uint64)
03899 DEFN_BIN_OP_T(/,const sc_int_base&)
03900 DEFN_BIN_OP_T(/,const sc_uint_base&)
03901 DEFN_BIN_OP_T(/,const sc_signed&)
03902 DEFN_BIN_OP_T(/,const sc_unsigned&)
03903 #endif
03904 
03905 #undef DEFN_BIN_OP_T
03906 #undef DEFN_BIN_OP_OTHER
03907 #undef DEFN_BIN_OP
03908 
03909 
03910 inline
03911 const sc_fxval_fast
03912 operator << ( const sc_fxnum_fast& a, int b )
03913 {
03914     SC_FXNUM_FAST_OBSERVER_READ_( a )
03915     return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
03916 }
03917 
03918 inline
03919 const sc_fxval_fast
03920 operator >> ( const sc_fxnum_fast& a, int b )
03921 {
03922     SC_FXNUM_FAST_OBSERVER_READ_( a )
03923     return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
03924 }
03925 
03926 
03927 // binary functions
03928 
03929 #define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
03930 inline                                                                        \
03931 void                                                                          \
03932 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, tp b )                        \
03933 {                                                                             \
03934     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03935     sc_fxval_fast tmp( b );                                                   \
03936     c.set_val( a.m_val op tmp.get_val() );                                    \
03937 }                                                                             \
03938                                                                               \
03939 inline                                                                        \
03940 void                                                                          \
03941 fnc ( sc_fxval_fast& c, tp a, const sc_fxnum_fast& b )                        \
03942 {                                                                             \
03943     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03944     sc_fxval_fast tmp( a );                                                   \
03945     c.set_val( tmp.get_val() op b.m_val );                                    \
03946 }                                                                             \
03947                                                                               \
03948 inline                                                                        \
03949 void                                                                          \
03950 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, tp b )                        \
03951 {                                                                             \
03952     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03953     sc_fxval_fast tmp( b );                                                   \
03954     c.m_val = a.m_val op tmp.get_val();                                       \
03955     c.cast();                                                                 \
03956     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
03957 }                                                                             \
03958                                                                               \
03959 inline                                                                        \
03960 void                                                                          \
03961 fnc ( sc_fxnum_fast& c, tp a, const sc_fxnum_fast& b )                        \
03962 {                                                                             \
03963     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03964     sc_fxval_fast tmp( a );                                                   \
03965     c.m_val = tmp.get_val() op b.m_val;                                       \
03966     c.cast();                                                                 \
03967     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
03968 }
03969 
03970 #ifndef SC_FX_EXCLUDE_OTHER
03971 #define DEFN_BIN_FNC_OTHER(fnc,op)                                            \
03972 DEFN_BIN_FNC_T(fnc,op,int64)                                                  \
03973 DEFN_BIN_FNC_T(fnc,op,uint64)                                                 \
03974 DEFN_BIN_FNC_T(fnc,op,const sc_int_base&)                                     \
03975 DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&)                                    \
03976 DEFN_BIN_FNC_T(fnc,op,const sc_signed&)                                       \
03977 DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
03978 #else
03979 #define DEFN_BIN_FNC_OTHER(fnc,op)
03980 #endif
03981 
03982 #define DEFN_BIN_FNC(fnc,op)                                                  \
03983 inline                                                                        \
03984 void                                                                          \
03985 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
03986 {                                                                             \
03987     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03988     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03989     c.set_val( a.m_val op b.m_val );                                          \
03990 }                                                                             \
03991                                                                               \
03992 inline                                                                        \
03993 void                                                                          \
03994 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
03995 {                                                                             \
03996     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
03997     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
03998     c.m_val = a.m_val op b.m_val;                                             \
03999     c.cast();                                                                 \
04000     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04001 }                                                                             \
04002                                                                               \
04003 inline                                                                        \
04004 void                                                                          \
04005 fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
04006 {                                                                             \
04007     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04008     c.set_val( a.m_val op b.get_val() );                                      \
04009 }                                                                             \
04010                                                                               \
04011 inline                                                                        \
04012 void                                                                          \
04013 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
04014 {                                                                             \
04015     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04016     c.set_val( a.get_val() op b.m_val );                                      \
04017 }                                                                             \
04018                                                                               \
04019 inline                                                                        \
04020 void                                                                          \
04021 fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
04022 {                                                                             \
04023     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04024     c.m_val = a.m_val op b.get_val();                                         \
04025     c.cast();                                                                 \
04026     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04027 }                                                                             \
04028                                                                               \
04029 inline                                                                        \
04030 void                                                                          \
04031 fnc ( sc_fxnum_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
04032 {                                                                             \
04033     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04034     c.m_val = a.get_val() op b.m_val;                                         \
04035     c.cast();                                                                 \
04036     SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
04037 }                                                                             \
04038                                                                               \
04039 DEFN_BIN_FNC_T(fnc,op,int)                                                    \
04040 DEFN_BIN_FNC_T(fnc,op,unsigned int)                                           \
04041 DEFN_BIN_FNC_T(fnc,op,long)                                                   \
04042 DEFN_BIN_FNC_T(fnc,op,unsigned long)                                          \
04043 DEFN_BIN_FNC_T(fnc,op,double)                                                 \
04044 DEFN_BIN_FNC_T(fnc,op,const char*)                                            \
04045 DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
04046 DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)                                        \
04047 DEFN_BIN_FNC_OTHER(fnc,op)
04048 
04049 DEFN_BIN_FNC(mult,*)
04050 DEFN_BIN_FNC(div,/)
04051 DEFN_BIN_FNC(add,+)
04052 DEFN_BIN_FNC(sub,-)
04053 
04054 #undef DEFN_BIN_FNC_T
04055 #undef DEFN_BIN_FNC_OTHER
04056 #undef DEFN_BIN_FNC
04057 
04058 
04059 inline
04060 void
04061 lshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
04062 {
04063     SC_FXNUM_FAST_OBSERVER_READ_( a )
04064     c.set_val( a.m_val * scfx_pow2( b ) );
04065 }
04066 
04067 inline
04068 void
04069 rshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
04070 {
04071     SC_FXNUM_FAST_OBSERVER_READ_( a )
04072     c.set_val( a.m_val * scfx_pow2( -b ) );
04073 }
04074 
04075 inline
04076 void
04077 lshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
04078 {
04079     SC_FXNUM_FAST_OBSERVER_READ_( a )
04080     c.m_val = a.m_val * scfx_pow2( b );
04081     c.cast();
04082     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
04083 }
04084 
04085 inline
04086 void
04087 rshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
04088 {
04089     SC_FXNUM_FAST_OBSERVER_READ_( a )
04090     c.m_val = a.m_val * scfx_pow2( -b );
04091     c.cast();
04092     SC_FXNUM_FAST_OBSERVER_WRITE_( c )
04093 }
04094 
04095 
04096 // relational (including equality) operators
04097 
04098 #define DEFN_REL_OP_T(op,tp)                                                  \
04099 inline                                                                        \
04100 bool                                                                          \
04101 operator op ( const sc_fxnum_fast& a, tp b )                                  \
04102 {                                                                             \
04103     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04104     sc_fxval_fast tmp( b );                                                   \
04105     return ( a.m_val op tmp.get_val() );                                      \
04106 }                                                                             \
04107                                                                               \
04108 inline                                                                        \
04109 bool                                                                          \
04110 operator op ( tp a, const sc_fxnum_fast& b )                                  \
04111 {                                                                             \
04112     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04113     sc_fxval_fast tmp( a );                                                   \
04114     return ( tmp.get_val() op b.m_val );                                      \
04115 }
04116 
04117 #ifndef SC_FX_EXCLUDE_OTHER
04118 #define DEFN_REL_OP_OTHER(op)                                                 \
04119 DEFN_REL_OP_T(op,int64)                                                       \
04120 DEFN_REL_OP_T(op,uint64)                                                      \
04121 DEFN_REL_OP_T(op,const sc_int_base&)                                          \
04122 DEFN_REL_OP_T(op,const sc_uint_base&)                                         \
04123 DEFN_REL_OP_T(op,const sc_signed&)                                            \
04124 DEFN_REL_OP_T(op,const sc_unsigned&)
04125 #else
04126 #define DEFN_REL_OP_OTHER(op)
04127 #endif
04128 
04129 #define DEFN_REL_OP(op)                                                       \
04130 inline                                                                        \
04131 bool                                                                          \
04132 operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
04133 {                                                                             \
04134     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04135     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04136     return ( a.m_val op b.m_val );                                            \
04137 }                                                                             \
04138                                                                               \
04139 inline                                                                        \
04140 bool                                                                          \
04141 operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
04142 {                                                                             \
04143     SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
04144     return ( a.m_val op b.get_val() );                                        \
04145 }                                                                             \
04146                                                                               \
04147 inline                                                                        \
04148 bool                                                                          \
04149 operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
04150 {                                                                             \
04151     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04152     return ( a.get_val() op b.m_val );                                        \
04153 }                                                                             \
04154                                                                               \
04155 DEFN_REL_OP_T(op,int)                                                         \
04156 DEFN_REL_OP_T(op,unsigned int)                                                \
04157 DEFN_REL_OP_T(op,long)                                                        \
04158 DEFN_REL_OP_T(op,unsigned long)                                               \
04159 DEFN_REL_OP_T(op,double)                                                      \
04160 DEFN_REL_OP_T(op,const char*)                                                 \
04161 DEFN_REL_OP_OTHER(op)
04162 
04163 DEFN_REL_OP(<)
04164 DEFN_REL_OP(<=)
04165 DEFN_REL_OP(>)
04166 DEFN_REL_OP(>=)
04167 DEFN_REL_OP(==)
04168 DEFN_REL_OP(!=)
04169 
04170 #undef DEFN_REL_OP_T
04171 #undef DEFN_REL_OP_OTHER
04172 #undef DEFN_REL_OP
04173 
04174 
04175 // assignment operators
04176 
04177 inline
04178 sc_fxnum_fast&
04179 sc_fxnum_fast::operator = ( const sc_fxnum_fast& a )
04180 {
04181     if( &a != this )
04182     {
04183         SC_FXNUM_FAST_OBSERVER_READ_( a )
04184         m_val = a.m_val;
04185         cast();
04186         SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04187     }
04188     return *this;
04189 }
04190 
04191 inline
04192 sc_fxnum_fast&
04193 sc_fxnum_fast::operator = ( const sc_fxval_fast& a )
04194 {
04195     m_val = a.get_val();
04196     cast();
04197     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04198     return *this;
04199 }
04200 
04201 #define DEFN_ASN_OP_T(tp)                                                     \
04202 inline                                                                        \
04203 sc_fxnum_fast&                                                                \
04204 sc_fxnum_fast::operator = ( tp a )                                            \
04205 {                                                                             \
04206     sc_fxval_fast tmp( a );                                                   \
04207     m_val = tmp.get_val();                                                    \
04208     cast();                                                                   \
04209     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04210     return *this;                                                             \
04211 }
04212 
04213 DEFN_ASN_OP_T(int)
04214 DEFN_ASN_OP_T(unsigned int)
04215 DEFN_ASN_OP_T(long)
04216 DEFN_ASN_OP_T(unsigned long)
04217 DEFN_ASN_OP_T(double)
04218 DEFN_ASN_OP_T(const char*)
04219 DEFN_ASN_OP_T(const sc_fxval&)
04220 DEFN_ASN_OP_T(const sc_fxnum&)
04221 #ifndef SC_FX_EXCLUDE_OTHER
04222 DEFN_ASN_OP_T(int64)
04223 DEFN_ASN_OP_T(uint64)
04224 DEFN_ASN_OP_T(const sc_int_base&)
04225 DEFN_ASN_OP_T(const sc_uint_base&)
04226 DEFN_ASN_OP_T(const sc_signed&)
04227 DEFN_ASN_OP_T(const sc_unsigned&)
04228 #endif
04229 
04230 #undef DEFN_ASN_OP_T
04231 
04232 
04233 #define DEFN_ASN_OP_T(op,tp)                                                  \
04234 inline                                                                        \
04235 sc_fxnum_fast&                                                                \
04236 sc_fxnum_fast::operator op ( tp b )                                           \
04237 {                                                                             \
04238     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04239     sc_fxval_fast tmp( b );                                                   \
04240     m_val op tmp.get_val();                                                   \
04241     cast();                                                                   \
04242     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04243     return *this;                                                             \
04244 }
04245 
04246 #ifndef SC_FX_EXCLUDE_OTHER
04247 #define DEFN_ASN_OP_OTHER(op)                                                 \
04248 DEFN_ASN_OP_T(op,int64)                                                       \
04249 DEFN_ASN_OP_T(op,uint64)                                                      \
04250 DEFN_ASN_OP_T(op,const sc_int_base&)                                          \
04251 DEFN_ASN_OP_T(op,const sc_uint_base&)                                         \
04252 DEFN_ASN_OP_T(op,const sc_signed&)                                            \
04253 DEFN_ASN_OP_T(op,const sc_unsigned&)
04254 #else
04255 #define DEFN_ASN_OP_OTHER(op)
04256 #endif
04257 
04258 #define DEFN_ASN_OP(op)                                                       \
04259 inline                                                                        \
04260 sc_fxnum_fast&                                                                \
04261 sc_fxnum_fast::operator op ( const sc_fxnum_fast& b )                         \
04262 {                                                                             \
04263     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04264     SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
04265     m_val op b.m_val;                                                         \
04266     cast();                                                                   \
04267     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04268     return *this;                                                             \
04269 }                                                                             \
04270                                                                               \
04271 inline                                                                        \
04272 sc_fxnum_fast&                                                                \
04273 sc_fxnum_fast::operator op ( const sc_fxval_fast& b )                         \
04274 {                                                                             \
04275     SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
04276     m_val op b.get_val();                                                     \
04277     cast();                                                                   \
04278     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
04279     return *this;                                                             \
04280 }                                                                             \
04281                                                                               \
04282 DEFN_ASN_OP_T(op,int)                                                         \
04283 DEFN_ASN_OP_T(op,unsigned int)                                                \
04284 DEFN_ASN_OP_T(op,long)                                                        \
04285 DEFN_ASN_OP_T(op,unsigned long)                                               \
04286 DEFN_ASN_OP_T(op,double)                                                      \
04287 DEFN_ASN_OP_T(op,const char*)                                                 \
04288 DEFN_ASN_OP_T(op,const sc_fxval&)                                             \
04289 DEFN_ASN_OP_T(op,const sc_fxnum&)                                             \
04290 DEFN_ASN_OP_OTHER(op)
04291 
04292 DEFN_ASN_OP(*=)
04293 DEFN_ASN_OP(/=)
04294 DEFN_ASN_OP(+=)
04295 DEFN_ASN_OP(-=)
04296 
04297 #undef DEFN_ASN_OP_T
04298 #undef DEFN_ASN_OP_OTHER
04299 #undef DEFN_ASN_OP
04300 
04301 
04302 inline
04303 sc_fxnum_fast&
04304 sc_fxnum_fast::operator <<= ( int b )
04305 {
04306     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04307     m_val *= scfx_pow2( b );
04308     cast();
04309     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04310     return *this;
04311 }
04312 
04313 inline
04314 sc_fxnum_fast&
04315 sc_fxnum_fast::operator >>= ( int b )
04316 {
04317     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04318     m_val *= scfx_pow2( -b );
04319     cast();
04320     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04321     return *this;
04322 }
04323 
04324 
04325 // auto-increment and auto-decrement
04326 
04327 inline
04328 const sc_fxval_fast
04329 sc_fxnum_fast::operator ++ ( int )
04330 {
04331     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04332     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04333     double c = m_val;
04334     m_val = m_val + 1;
04335     cast();
04336     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04337     return sc_fxval_fast( c );
04338 }
04339 
04340 inline
04341 const sc_fxval_fast
04342 sc_fxnum_fast::operator -- ( int )
04343 {
04344     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04345     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04346     double c = m_val;
04347     m_val = m_val - 1;
04348     cast();
04349     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04350     return sc_fxval_fast( c );
04351 }
04352 
04353 inline
04354 sc_fxnum_fast&
04355 sc_fxnum_fast::operator ++ ()
04356 {
04357     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04358     m_val = m_val + 1;
04359     cast();
04360     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04361     return *this;
04362 }
04363 
04364 inline
04365 sc_fxnum_fast&
04366 sc_fxnum_fast::operator -- ()
04367 {
04368     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04369     m_val = m_val - 1;
04370     cast();
04371     SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
04372     return *this;
04373 }
04374 
04375 
04376 // bit selection
04377 
04378 inline
04379 const sc_fxnum_fast_bitref
04380 sc_fxnum_fast::operator [] ( int i ) const
04381 {
04382     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04383     return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
04384                                  i - m_params.fwl() );
04385 }
04386 
04387 inline
04388 sc_fxnum_fast_bitref
04389 sc_fxnum_fast::operator [] ( int i )
04390 {
04391     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04392     return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
04393 }
04394 
04395 inline
04396 const sc_fxnum_fast_bitref
04397 sc_fxnum_fast::bit( int i ) const
04398 {
04399     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04400     return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
04401                                  i - m_params.fwl() );
04402 }
04403 
04404 inline
04405 sc_fxnum_fast_bitref
04406 sc_fxnum_fast::bit( int i )
04407 {
04408     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04409     return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
04410 }
04411 
04412 
04413 // part selection
04414 
04415 inline
04416 const sc_fxnum_fast_subref
04417 sc_fxnum_fast::operator () ( int i, int j ) const
04418 {
04419     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04420     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04421 
04422     return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
04423                                  i - m_params.fwl(), j - m_params.fwl() );
04424 }
04425 
04426 inline
04427 sc_fxnum_fast_subref
04428 sc_fxnum_fast::operator () ( int i, int j )
04429 {
04430     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04431     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04432 
04433     return sc_fxnum_fast_subref( *this,
04434                                  i - m_params.fwl(), j - m_params.fwl() );
04435 }
04436 
04437 inline
04438 const sc_fxnum_fast_subref
04439 sc_fxnum_fast::range( int i, int j ) const
04440 {
04441     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04442     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04443 
04444     return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
04445                                  i - m_params.fwl(), j - m_params.fwl() );
04446 }
04447 
04448 inline
04449 sc_fxnum_fast_subref
04450 sc_fxnum_fast::range( int i, int j )
04451 {
04452     SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04453     SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
04454 
04455     return sc_fxnum_fast_subref( *this,
04456                                  i - m_params.fwl(), j - m_params.fwl() );
04457 }
04458 
04459 inline
04460 const sc_fxnum_fast_subref
04461 sc_fxnum_fast::operator () () const
04462 {
04463     return this->operator () ( m_params.wl() - 1, 0 );
04464 }
04465 
04466 inline
04467 sc_fxnum_fast_subref
04468 sc_fxnum_fast::operator () ()
04469 {
04470     return this->operator () ( m_params.wl() - 1, 0 );
04471 }
04472 
04473 inline
04474 const sc_fxnum_fast_subref
04475 sc_fxnum_fast::range() const
04476 {
04477     return this->range( m_params.wl() - 1, 0 );
04478 }
04479 
04480 inline
04481 sc_fxnum_fast_subref
04482 sc_fxnum_fast::range()
04483 {
04484     return this->range( m_params.wl() - 1, 0 );
04485 }
04486 
04487 
04488 // implicit conversion
04489 
04490 inline
04491 sc_fxnum_fast::operator double() const
04492 {
04493     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04494     return m_val;
04495 }
04496 
04497 
04498 // explicit conversion to primitive types
04499 
04500 inline
04501 short
04502 sc_fxnum_fast::to_short() const
04503 {
04504     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04505     return static_cast<short>( m_val );
04506 }
04507 
04508 inline
04509 unsigned short
04510 sc_fxnum_fast::to_ushort() const
04511 {
04512     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04513     return static_cast<unsigned short>( m_val );
04514 }
04515 
04516 inline
04517 int
04518 sc_fxnum_fast::to_int() const
04519 {
04520     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04521     return static_cast<int>( m_val );
04522 }
04523 
04524 inline
04525 int64
04526 sc_fxnum_fast::to_int64() const
04527 {
04528     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04529     return static_cast<int64>( m_val );
04530 }
04531 
04532 inline
04533 unsigned int
04534 sc_fxnum_fast::to_uint() const
04535 {
04536     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04537     return static_cast<unsigned int>( m_val );
04538 }
04539 
04540 inline
04541 uint64
04542 sc_fxnum_fast::to_uint64() const
04543 {
04544     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04545     return static_cast<uint64>( m_val );
04546 }
04547 
04548 inline
04549 long
04550 sc_fxnum_fast::to_long() const
04551 {
04552     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04553     return static_cast<long>( m_val );
04554 }
04555 
04556 inline
04557 unsigned long
04558 sc_fxnum_fast::to_ulong() const
04559 {
04560     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04561     return static_cast<unsigned long>( m_val );
04562 }
04563 
04564 inline
04565 float
04566 sc_fxnum_fast::to_float() const
04567 {
04568     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04569     return static_cast<float>( m_val );
04570 }
04571 
04572 inline
04573 double
04574 sc_fxnum_fast::to_double() const
04575 {
04576     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04577     return m_val;
04578 }
04579 
04580 
04581 // query value
04582 
04583 inline
04584 bool
04585 sc_fxnum_fast::is_neg() const
04586 {
04587     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04588     scfx_ieee_double id( m_val );
04589     return ( id.negative() != 0 );
04590 }
04591 
04592 inline
04593 bool
04594 sc_fxnum_fast::is_zero() const
04595 {
04596     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04597     scfx_ieee_double id( m_val );
04598     return id.is_zero();
04599 }
04600 
04601 // internal use only;
04602 inline
04603 bool
04604 sc_fxnum_fast::is_normal() const
04605 {
04606     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04607     scfx_ieee_double id( m_val );
04608     return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
04609 }
04610 
04611 
04612 inline
04613 bool
04614 sc_fxnum_fast::quantization_flag() const
04615 {
04616     return m_q_flag;
04617 }
04618 
04619 inline
04620 bool
04621 sc_fxnum_fast::overflow_flag() const
04622 {
04623     return m_o_flag;
04624 }
04625 
04626 
04627 inline
04628 const sc_fxval_fast
04629 sc_fxnum_fast::value() const
04630 {
04631     SC_FXNUM_FAST_OBSERVER_READ_( *this )
04632     return sc_fxval_fast( m_val );
04633 }
04634 
04635 
04636 // query parameters
04637 
04638 inline
04639 int
04640 sc_fxnum_fast::wl() const
04641 {
04642     return m_params.wl();
04643 }
04644 
04645 inline
04646 int
04647 sc_fxnum_fast::iwl() const
04648 {
04649     return m_params.iwl();
04650 }
04651 
04652 inline
04653 sc_q_mode
04654 sc_fxnum_fast::q_mode() const
04655 {
04656     return m_params.q_mode();
04657 }
04658 
04659 inline
04660 sc_o_mode
04661 sc_fxnum_fast::o_mode() const
04662 {
04663     return m_params.o_mode();
04664 }
04665 
04666 inline
04667 int
04668 sc_fxnum_fast::n_bits() const
04669 {
04670     return m_params.n_bits();
04671 }
04672 
04673 
04674 inline
04675 const sc_fxtype_params&
04676 sc_fxnum_fast::type_params() const
04677 {
04678     return m_params.type_params();
04679 }
04680 
04681 
04682 inline
04683 const sc_fxcast_switch&
04684 sc_fxnum_fast::cast_switch() const
04685 {
04686     return m_params.cast_switch();
04687 }
04688 
04689 
04690 // internal use only;
04691 inline
04692 void
04693 sc_fxnum_fast::observer_read() const
04694 {
04695     SC_FXNUM_OBSERVER_READ_( *this );
04696 }
04697 
04698 
04699 inline
04700 ::std::ostream&
04701 operator << ( ::std::ostream& os, const sc_fxnum_fast& a )
04702 {
04703     a.print( os );
04704     return os;
04705 }
04706 
04707 inline
04708 ::std::istream&
04709 operator >> ( ::std::istream& is, sc_fxnum_fast& a )
04710 {
04711     a.scan( is );
04712     return is;
04713 }
04714 
04715 
04716 // ----------------------------------------------------------------------------
04717 //  CLASS : sc_fxval
04718 //
04719 //  Fixed-point value type; arbitrary precision.
04720 // ----------------------------------------------------------------------------
04721 
04722 // public constructors
04723 
04724 inline
04725 sc_fxval::sc_fxval( const sc_fxnum& a,
04726                     sc_fxval_observer* observer_ )
04727 : m_rep( new scfx_rep( *a.get_rep() ) ),
04728   m_observer( observer_ )
04729 {
04730     SC_FXVAL_OBSERVER_DEFAULT_
04731     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
04732     SC_FXVAL_OBSERVER_WRITE_( *this )
04733 }
04734 
04735 inline
04736 sc_fxval::sc_fxval( const sc_fxnum_fast& a,
04737                     sc_fxval_observer* observer_ )
04738 : m_rep( new scfx_rep( a.to_double() ) ),
04739   m_observer( observer_ )
04740 {
04741     SC_FXVAL_OBSERVER_DEFAULT_
04742     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
04743     SC_FXVAL_OBSERVER_WRITE_( *this )
04744 }
04745 
04746 
04747 // binary operators
04748 
04749 #define DEFN_BIN_OP_T(op,fnc,tp)                                              \
04750 inline                                                                        \
04751 const sc_fxval                                                                \
04752 operator op ( const sc_fxval& a, tp b )                                       \
04753 {                                                                             \
04754     SC_FXVAL_OBSERVER_READ_( a )                                              \
04755     sc_fxval tmp( b );                                                        \
04756     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) );      \
04757 }                                                                             \
04758                                                                               \
04759 inline                                                                        \
04760 const sc_fxval                                                                \
04761 operator op ( tp a, const sc_fxval& b )                                       \
04762 {                                                                             \
04763     SC_FXVAL_OBSERVER_READ_( b )                                              \
04764     sc_fxval tmp( a );                                                        \
04765     return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) );      \
04766 }
04767 
04768 #define DEFN_BIN_OP(op,fnc)                                                   \
04769 DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)
04770 
04771 DEFN_BIN_OP(*,mult)
04772 DEFN_BIN_OP(+,add)
04773 DEFN_BIN_OP(-,sub)
04774 //DEFN_BIN_OP(/,div)
04775 DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
04776 
04777 #undef DEFN_BIN_OP_T
04778 #undef DEFN_BIN_OP
04779 
04780 
04781 // binary functions
04782 
04783 #define DEFN_BIN_FNC_T(fnc,tp)                                                \
04784 inline                                                                        \
04785 void                                                                          \
04786 fnc ( sc_fxval& c, const sc_fxval& a, tp b )                                  \
04787 {                                                                             \
04788     SC_FXVAL_OBSERVER_READ_( a )                                              \
04789     sc_fxval tmp( b );                                                        \
04790     delete c.m_rep;                                                           \
04791     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep );               \
04792     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
04793 }                                                                             \
04794                                                                               \
04795 inline                                                                        \
04796 void                                                                          \
04797 fnc ( sc_fxval& c, tp a, const sc_fxval& b )                                  \
04798 {                                                                             \
04799     SC_FXVAL_OBSERVER_READ_( b )                                              \
04800     sc_fxval tmp( a );                                                        \
04801     delete c.m_rep;                                                           \
04802     c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep );               \
04803     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
04804 }
04805 
04806 #define DEFN_BIN_FNC(fnc)                                                     \
04807 DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)
04808 
04809 DEFN_BIN_FNC(mult)
04810 DEFN_BIN_FNC(div)
04811 DEFN_BIN_FNC(add)
04812 DEFN_BIN_FNC(sub)
04813 
04814 #undef DEFN_BIN_FNC_T
04815 #undef DEFN_BIN_FNC
04816 
04817 
04818 // relational (including equality) operators
04819 
04820 #define DEFN_REL_OP_T(op,ret,tp)                                              \
04821 inline                                                                        \
04822 bool                                                                          \
04823 operator op ( const sc_fxval& a, tp b )                                       \
04824 {                                                                             \
04825     SC_FXVAL_OBSERVER_READ_( a )                                              \
04826     sc_fxval tmp( b );                                                        \
04827     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep );                \
04828     return ( ret );                                                           \
04829 }                                                                             \
04830                                                                               \
04831 inline                                                                        \
04832 bool                                                                          \
04833 operator op ( tp a, const sc_fxval& b )                                       \
04834 {                                                                             \
04835     SC_FXVAL_OBSERVER_READ_( b )                                              \
04836     sc_fxval tmp( a );                                                        \
04837     int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep );                \
04838     return ( ret );                                                           \
04839 }
04840 
04841 
04842 #define DEFN_REL_OP(op,ret)                                                   \
04843 DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)
04844 
04845 DEFN_REL_OP(<,result < 0)
04846 DEFN_REL_OP(<=,result <= 0)
04847 DEFN_REL_OP(>,result > 0 && result != 2)
04848 DEFN_REL_OP(>=,result >= 0 && result != 2)
04849 DEFN_REL_OP(==,result == 0)
04850 DEFN_REL_OP(!=,result != 0)
04851 
04852 #undef DEFN_REL_OP_T
04853 #undef DEFN_REL_OP
04854 
04855 
04856 // assignment operators
04857 
04858 inline
04859 sc_fxval&
04860 sc_fxval::operator = ( const sc_fxnum& a )
04861 {
04862     *m_rep = *a.get_rep();
04863     SC_FXVAL_OBSERVER_WRITE_( *this )
04864     return *this;
04865 }
04866 
04867 #define DEFN_ASN_OP_T(tp)                                                     \
04868 inline                                                                        \
04869 sc_fxval&                                                                     \
04870 sc_fxval::operator = ( tp b )                                                 \
04871 {                                                                             \
04872     sc_fxval tmp( b );                                                        \
04873     *m_rep = *tmp.m_rep;                                                      \
04874     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04875     return *this;                                                             \
04876 }
04877 
04878 DEFN_ASN_OP_T(const sc_fxnum_fast&)
04879 
04880 #undef DEFN_ASN_OP_T
04881 
04882 
04883 #define DEFN_ASN_OP_T(op,fnc,tp)                                              \
04884 inline                                                                        \
04885 sc_fxval&                                                                     \
04886 sc_fxval::operator op ( tp b )                                                \
04887 {                                                                             \
04888     SC_FXVAL_OBSERVER_READ_( *this )                                          \
04889     sc_fxval tmp( b );                                                        \
04890     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep );       \
04891     delete m_rep;                                                             \
04892     m_rep = new_rep;                                                          \
04893     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04894     return *this;                                                             \
04895 }
04896 
04897 #define DEFN_ASN_OP(op,fnc)                                                   \
04898 inline                                                                        \
04899 sc_fxval&                                                                     \
04900 sc_fxval::operator op ( const sc_fxnum& b )                                   \
04901 {                                                                             \
04902     SC_FXVAL_OBSERVER_READ_( *this )                                          \
04903     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
04904     delete m_rep;                                                             \
04905     m_rep = new_rep;                                                          \
04906     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
04907     return *this;                                                             \
04908 }                                                                             \
04909                                                                               \
04910 DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)
04911 
04912 DEFN_ASN_OP(*=,mult)
04913 DEFN_ASN_OP(/=,div)
04914 DEFN_ASN_OP(+=,add)
04915 DEFN_ASN_OP(-=,sub)
04916 
04917 #undef DEFN_ASN_OP_T
04918 #undef DEFN_ASN_OP
04919 
04920 
04921 // ----------------------------------------------------------------------------
04922 //  CLASS : sc_fxval_fast
04923 //
04924 //  Fixed-point value types; limited precision.
04925 // ----------------------------------------------------------------------------
04926 
04927 // public constructors
04928 
04929 inline
04930 sc_fxval_fast::sc_fxval_fast( const sc_fxnum& a,
04931                               sc_fxval_fast_observer* observer_ )
04932 : m_val( a.to_double() ),
04933   m_observer( observer_ )
04934 {
04935     SC_FXVAL_FAST_OBSERVER_DEFAULT_
04936     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
04937     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
04938 }
04939 
04940 inline
04941 sc_fxval_fast::sc_fxval_fast( const sc_fxnum_fast& a,
04942                               sc_fxval_fast_observer* observer_ )
04943 : m_val( a.get_val() ),
04944   m_observer( observer_ )
04945 {
04946     SC_FXVAL_FAST_OBSERVER_DEFAULT_
04947     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
04948     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
04949 }
04950 
04951 
04952 // binary functions
04953 
04954 #define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
04955 inline                                                                        \
04956 void                                                                          \
04957 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b )                        \
04958 {                                                                             \
04959     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
04960     sc_fxval_fast tmp( b );                                                   \
04961     c.m_val = a.m_val op tmp.m_val;                                           \
04962     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
04963 }                                                                             \
04964                                                                               \
04965 inline                                                                        \
04966 void                                                                          \
04967 fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b )                        \
04968 {                                                                             \
04969     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
04970     sc_fxval_fast tmp( a );                                                   \
04971     c.m_val = tmp.m_val op b.m_val;                                           \
04972     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
04973 }
04974 
04975 #define DEFN_BIN_FNC(fnc,op)                                                  \
04976 DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
04977 DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)
04978 
04979 DEFN_BIN_FNC(mult,*)
04980 DEFN_BIN_FNC(div,/)
04981 DEFN_BIN_FNC(add,+)
04982 DEFN_BIN_FNC(sub,-)
04983 
04984 #undef DEFN_BIN_FNC_T
04985 #undef DEFN_BIN_FNC
04986 
04987 
04988 // assignment operators
04989 
04990 inline
04991 sc_fxval_fast&
04992 sc_fxval_fast::operator = ( const sc_fxnum_fast& a )
04993 {
04994     m_val = a.get_val();
04995     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
04996     return *this;
04997 }
04998 
04999 #define DEFN_ASN_OP_T(tp)                                                     \
05000 inline                                                                        \
05001 sc_fxval_fast&                                                                \
05002 sc_fxval_fast::operator = ( tp a )                                            \
05003 {                                                                             \
05004     sc_fxval_fast tmp( a );                                                   \
05005     m_val = tmp.m_val;                                                        \
05006     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05007     return *this;                                                             \
05008 }
05009 
05010 DEFN_ASN_OP_T(const sc_fxnum&)
05011 
05012 #undef DEFN_ASN_OP_T
05013 
05014 
05015 #define DEFN_ASN_OP_T(op,tp)                                                  \
05016 inline                                                                        \
05017 sc_fxval_fast&                                                                \
05018 sc_fxval_fast::operator op ( tp b )                                           \
05019 {                                                                             \
05020     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
05021     sc_fxval_fast tmp( b );                                                   \
05022     m_val op tmp.m_val;                                                       \
05023     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05024     return *this;                                                             \
05025 }
05026 
05027 #define DEFN_ASN_OP(op)                                                       \
05028 inline                                                                        \
05029 sc_fxval_fast&                                                                \
05030 sc_fxval_fast::operator op ( const sc_fxnum_fast& b )                         \
05031 {                                                                             \
05032     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
05033     m_val op b.get_val();                                                     \
05034     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
05035     return *this;                                                             \
05036 }                                                                             \
05037                                                                               \
05038 DEFN_ASN_OP_T(op,const sc_fxnum&)
05039 
05040 DEFN_ASN_OP(*=)
05041 DEFN_ASN_OP(/=)
05042 DEFN_ASN_OP(+=)
05043 DEFN_ASN_OP(-=)
05044 
05045 #undef DEFN_ASN_OP_T
05046 #undef DEFN_ASN_OP
05047 
05048 } // namespace sc_dt
05049 
05050 
05051 #endif
05052 
05053 // Taf!

Generated on Wed Apr 25 13:53:26 2007 for SystemC by  doxygen 1.5.1