sc_fxval.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-2006 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_fxval.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 // $Log: sc_fxval.h,v $
00037 // Revision 1.1.1.1  2006/12/15 20:31:36  acg
00038 // SystemC 2.2
00039 //
00040 // Revision 1.3  2006/01/13 18:53:58  acg
00041 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
00042 // the source.
00043 //
00044 
00045 #ifndef SC_FXVAL_H
00046 #define SC_FXVAL_H
00047 
00048 
00049 #include "sysc/datatypes/fx/scfx_rep.h"
00050 #ifndef SC_FX_EXCLUDE_OTHER
00051 #include "sysc/datatypes/int/sc_int_base.h"
00052 #include "sysc/datatypes/int/sc_uint_base.h"
00053 #include "sysc/datatypes/int/sc_signed.h"
00054 #include "sysc/datatypes/int/sc_unsigned.h"
00055 #endif
00056 #include "sysc/datatypes/fx/sc_fxval_observer.h"
00057 
00058 
00059 namespace sc_dt
00060 {
00061 
00062 // classes defined in this module
00063 class sc_fxval;
00064 class sc_fxval_fast;
00065 
00066 // forward class declarations
00067 class sc_fxnum;
00068 class sc_fxnum_fast;
00069 
00070 
00071 // ----------------------------------------------------------------------------
00072 //  CLASS : sc_fxval
00073 //
00074 //  Fixed-point value type; arbitrary precision.
00075 // ----------------------------------------------------------------------------
00076 
00077 class sc_fxval
00078 {
00079 
00080     friend class sc_fxnum;
00081 
00082 protected:
00083 
00084     sc_fxval_observer* observer() const;
00085 
00086 public:
00087 
00088     // internal use only;
00089     sc_fxval( scfx_rep* );
00090 
00091 
00092     explicit sc_fxval( sc_fxval_observer* = 0 );
00093              sc_fxval( int,
00094                sc_fxval_observer* = 0 );
00095              sc_fxval( unsigned int,
00096                sc_fxval_observer* = 0 );
00097              sc_fxval( long,
00098                sc_fxval_observer* = 0 );
00099              sc_fxval( unsigned long,
00100                sc_fxval_observer* = 0 );
00101              sc_fxval( double,
00102                sc_fxval_observer* = 0 );
00103              sc_fxval( const char*,
00104                sc_fxval_observer* = 0 );
00105              sc_fxval( const sc_fxval&,
00106                sc_fxval_observer* = 0 );
00107              sc_fxval( const sc_fxval_fast&,
00108                sc_fxval_observer* = 0 );
00109              sc_fxval( const sc_fxnum&,
00110                sc_fxval_observer* = 0 );
00111              sc_fxval( const sc_fxnum_fast&,
00112                sc_fxval_observer* = 0 );
00113 #ifndef SC_FX_EXCLUDE_OTHER
00114     explicit sc_fxval( int64,
00115                sc_fxval_observer* = 0 );
00116     explicit sc_fxval( uint64,
00117                sc_fxval_observer* = 0 );
00118     explicit sc_fxval( const sc_int_base&,
00119                sc_fxval_observer* = 0 );
00120     explicit sc_fxval( const sc_uint_base&,
00121                sc_fxval_observer* = 0 );
00122     explicit sc_fxval( const sc_signed&,
00123                sc_fxval_observer* = 0 );
00124     explicit sc_fxval( const sc_unsigned&,
00125                sc_fxval_observer* = 0 );
00126 #endif
00127 
00128     ~sc_fxval();
00129 
00130 
00131     // internal use only;
00132     const scfx_rep* get_rep() const;
00133     void            set_rep( scfx_rep* );
00134 
00135 
00136     // unary operators
00137 
00138     const sc_fxval  operator - () const;
00139     const sc_fxval& operator + () const;
00140 
00141 
00142     // unary functions
00143 
00144     friend void neg( sc_fxval&, const sc_fxval& );
00145 
00146 
00147     // binary operators
00148 
00149 #define DECL_BIN_OP_T(op,tp)                                                  \
00150     friend const sc_fxval operator op ( const sc_fxval&, tp );                \
00151     friend const sc_fxval operator op ( tp, const sc_fxval& );
00152 
00153 #ifndef SC_FX_EXCLUDE_OTHER
00154 #define DECL_BIN_OP_OTHER(op)                                                 \
00155     DECL_BIN_OP_T(op,int64)                                                   \
00156     DECL_BIN_OP_T(op,uint64)                                                  \
00157     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
00158     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
00159     DECL_BIN_OP_T(op,const sc_signed&)                                        \
00160     DECL_BIN_OP_T(op,const sc_unsigned&)
00161 #else
00162 #define DECL_BIN_OP_OTHER(op)
00163 #endif
00164 
00165 #define DECL_BIN_OP(op,dummy)                                                 \
00166     friend const sc_fxval operator op ( const sc_fxval&, const sc_fxval& );   \
00167     DECL_BIN_OP_T(op,int)                                                     \
00168     DECL_BIN_OP_T(op,unsigned int)                                            \
00169     DECL_BIN_OP_T(op,long)                                                    \
00170     DECL_BIN_OP_T(op,unsigned long)                                           \
00171     DECL_BIN_OP_T(op,double)                                                  \
00172     DECL_BIN_OP_T(op,const char*)                                             \
00173     DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
00174     DECL_BIN_OP_T(op,const sc_fxnum_fast&)                                    \
00175     DECL_BIN_OP_OTHER(op)
00176 
00177     DECL_BIN_OP(*,mult)
00178     DECL_BIN_OP(+,add)
00179     DECL_BIN_OP(-,sub)
00180 // declaration below doesn't compile with BCB5 (E2206)
00181 //    DECL_BIN_OP(/,div)
00182 // previous macro expanded
00183     friend const sc_fxval operator / ( const sc_fxval&, const sc_fxval& );
00184     DECL_BIN_OP_T(/,int)
00185     DECL_BIN_OP_T(/,unsigned int)
00186     DECL_BIN_OP_T(/,long)
00187     DECL_BIN_OP_T(/,unsigned long)
00188     DECL_BIN_OP_T(/,double)
00189     DECL_BIN_OP_T(/,const char*)
00190     DECL_BIN_OP_T(/,const sc_fxval_fast&)
00191     DECL_BIN_OP_T(/,const sc_fxnum_fast&)
00192 //    DECL_BIN_OP_OTHER(/)
00193 #ifndef SC_FX_EXCLUDE_OTHER
00194     DECL_BIN_OP_T(/,int64)                                                   \
00195     DECL_BIN_OP_T(/,uint64)                                                  \
00196     DECL_BIN_OP_T(/,const sc_int_base&)                                      \
00197     DECL_BIN_OP_T(/,const sc_uint_base&)                                     \
00198     DECL_BIN_OP_T(/,const sc_signed&)                                        \
00199     DECL_BIN_OP_T(/,const sc_unsigned&)
00200 #endif
00201 
00202 
00203 #undef DECL_BIN_OP_T
00204 #undef DECL_BIN_OP_OTHER
00205 #undef DECL_BIN_OP
00206 
00207     friend const sc_fxval operator << ( const sc_fxval&, int );
00208     friend const sc_fxval operator >> ( const sc_fxval&, int );
00209 
00210 
00211     // binary functions
00212 
00213 #define DECL_BIN_FNC_T(fnc,tp)                                                \
00214     friend void fnc ( sc_fxval&, const sc_fxval&, tp );                       \
00215     friend void fnc ( sc_fxval&, tp, const sc_fxval& );
00216 
00217 #ifndef SC_FX_EXCLUDE_OTHER
00218 #define DECL_BIN_FNC_OTHER(fnc)                                               \
00219     DECL_BIN_FNC_T(fnc,int64)                                                 \
00220     DECL_BIN_FNC_T(fnc,uint64)                                                \
00221     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
00222     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
00223     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
00224     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
00225 #else
00226 #define DECL_BIN_FNC_OTHER(fnc)
00227 #endif
00228 
00229 #define DECL_BIN_FNC(fnc)                                                     \
00230     friend void fnc ( sc_fxval&, const sc_fxval&, const sc_fxval& );          \
00231     DECL_BIN_FNC_T(fnc,int)                                                   \
00232     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
00233     DECL_BIN_FNC_T(fnc,long)                                                  \
00234     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
00235     DECL_BIN_FNC_T(fnc,double)                                                \
00236     DECL_BIN_FNC_T(fnc,const char*)                                           \
00237     DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
00238     DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                  \
00239     DECL_BIN_FNC_OTHER(fnc)
00240 
00241     DECL_BIN_FNC(mult)
00242     DECL_BIN_FNC(div)
00243     DECL_BIN_FNC(add)
00244     DECL_BIN_FNC(sub)
00245 
00246 #undef DECL_BIN_FNC_T
00247 #undef DECL_BIN_FNC_OTHER
00248 #undef DECL_BIN_FNC
00249 
00250     friend void lshift( sc_fxval&, const sc_fxval&, int );
00251     friend void rshift( sc_fxval&, const sc_fxval&, int );
00252 
00253 
00254     // relational (including equality) operators
00255 
00256 #define DECL_REL_OP_T(op,tp)                                                  \
00257     friend bool operator op ( const sc_fxval&, tp );                          \
00258     friend bool operator op ( tp, const sc_fxval& );
00259 
00260 #ifndef SC_FX_EXCLUDE_OTHER
00261 #define DECL_REL_OP_OTHER(op)                                                 \
00262     DECL_REL_OP_T(op,int64)                                                   \
00263     DECL_REL_OP_T(op,uint64)                                                  \
00264     DECL_REL_OP_T(op,const sc_int_base&)                                      \
00265     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
00266     DECL_REL_OP_T(op,const sc_signed&)                                        \
00267     DECL_REL_OP_T(op,const sc_unsigned&)
00268 #else
00269 #define DECL_REL_OP_OTHER(op)
00270 #endif
00271 
00272 #define DECL_REL_OP(op)                                                       \
00273     friend bool operator op ( const sc_fxval&, const sc_fxval& );             \
00274     DECL_REL_OP_T(op,int)                                                     \
00275     DECL_REL_OP_T(op,unsigned int)                                            \
00276     DECL_REL_OP_T(op,long)                                                    \
00277     DECL_REL_OP_T(op,unsigned long)                                           \
00278     DECL_REL_OP_T(op,double)                                                  \
00279     DECL_REL_OP_T(op,const char*)                                             \
00280     DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
00281     DECL_REL_OP_T(op,const sc_fxnum_fast&)                                    \
00282     DECL_REL_OP_OTHER(op)
00283 
00284     DECL_REL_OP(<)
00285     DECL_REL_OP(<=)
00286     DECL_REL_OP(>)
00287     DECL_REL_OP(>=)
00288     DECL_REL_OP(==)
00289     DECL_REL_OP(!=)
00290 
00291 #undef DECL_REL_OP_T
00292 #undef DECL_REL_OP_OTHER
00293 #undef DECL_REL_OP
00294 
00295 
00296     // assignment operators
00297 
00298 #define DECL_ASN_OP_T(op,tp)                                                  \
00299     sc_fxval& operator op( tp );
00300 
00301 #ifndef SC_FX_EXCLUDE_OTHER
00302 #define DECL_ASN_OP_OTHER(op)                                                 \
00303     DECL_ASN_OP_T(op,int64)                                                   \
00304     DECL_ASN_OP_T(op,uint64)                                                  \
00305     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
00306     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
00307     DECL_ASN_OP_T(op,const sc_signed&)                                        \
00308     DECL_ASN_OP_T(op,const sc_unsigned&)
00309 #else
00310 #define DECL_ASN_OP_OTHER(op)
00311 #endif
00312 
00313 #define DECL_ASN_OP(op)                                                       \
00314     DECL_ASN_OP_T(op,int)                                                     \
00315     DECL_ASN_OP_T(op,unsigned int)                                            \
00316     DECL_ASN_OP_T(op,long)                                                    \
00317     DECL_ASN_OP_T(op,unsigned long)                                           \
00318     DECL_ASN_OP_T(op,double)                                                  \
00319     DECL_ASN_OP_T(op,const char*)                                             \
00320     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
00321     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
00322     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
00323     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
00324     DECL_ASN_OP_OTHER(op)
00325 
00326     DECL_ASN_OP(=)
00327 
00328     DECL_ASN_OP(*=)
00329     DECL_ASN_OP(/=)
00330     DECL_ASN_OP(+=)
00331     DECL_ASN_OP(-=)
00332 
00333     DECL_ASN_OP_T(<<=,int)
00334     DECL_ASN_OP_T(>>=,int)
00335 
00336 #undef DECL_ASN_OP_T
00337 #undef DECL_ASN_OP_OTHER
00338 #undef DECL_ASN_OP
00339 
00340 
00341     // auto-increment and auto-decrement
00342 
00343     const sc_fxval operator ++ ( int );
00344     const sc_fxval operator -- ( int );
00345 
00346     sc_fxval& operator ++ ();
00347     sc_fxval& operator -- ();
00348 
00349 
00350     // implicit conversion
00351 
00352     operator double() const;            // necessary evil!
00353 
00354 
00355     // explicit conversion to primitive types
00356 
00357     short          to_short() const;
00358     unsigned short to_ushort() const;
00359     int            to_int() const;
00360     unsigned int   to_uint() const;
00361     long           to_long() const;
00362     unsigned long  to_ulong() const;
00363     int64          to_int64() const;
00364     uint64         to_uint64() const;
00365     float          to_float() const;
00366     double         to_double() const;
00367 
00368 
00369     // explicit conversion to character string
00370 
00371     const std::string to_string() const;
00372     const std::string to_string( sc_numrep ) const;
00373     const std::string to_string( sc_numrep, bool ) const;
00374     const std::string to_string( sc_fmt ) const;
00375     const std::string to_string( sc_numrep, sc_fmt ) const;
00376     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
00377 
00378     const std::string to_dec() const;
00379     const std::string to_bin() const;
00380     const std::string to_oct() const;
00381     const std::string to_hex() const;
00382 
00383 
00384     // query value
00385 
00386     bool is_neg() const;
00387     bool is_zero() const;
00388     bool is_nan() const;
00389     bool is_inf() const;
00390     bool is_normal() const;
00391     
00392     bool rounding_flag() const;
00393 
00394 
00395     // print or dump content
00396 
00397     void print( ::std::ostream& = ::std::cout ) const;
00398     void scan( ::std::istream& = ::std::cin );
00399     void dump( ::std::ostream& = ::std::cout ) const;
00400 
00401 
00402     // internal use only;
00403     bool get_bit( int ) const;
00404 
00405 protected:
00406 
00407     sc_fxval_observer* lock_observer() const;
00408     void unlock_observer( sc_fxval_observer* ) const;
00409 
00410 
00411     void get_type( int&, int&, sc_enc& ) const;
00412 
00413     const sc_fxval quantization( const scfx_params&, bool& ) const;
00414     const sc_fxval     overflow( const scfx_params&, bool& ) const;
00415 
00416 private:
00417 
00418     scfx_rep*                  m_rep;
00419 
00420     mutable sc_fxval_observer* m_observer;
00421 
00422 };
00423 
00424 
00425 // ----------------------------------------------------------------------------
00426 //  CLASS : sc_fxval_fast
00427 //
00428 //  Fixed-point value type; limited precision.
00429 // ----------------------------------------------------------------------------
00430 
00431 class sc_fxval_fast
00432 {
00433 
00434     friend class sc_fxnum_fast;
00435 
00436 protected:
00437 
00438     sc_fxval_fast_observer* observer() const;
00439 
00440 public:
00441 
00442     explicit sc_fxval_fast( sc_fxval_fast_observer* = 0 );
00443              sc_fxval_fast( int,
00444                 sc_fxval_fast_observer* = 0 );
00445              sc_fxval_fast( unsigned int,
00446                 sc_fxval_fast_observer* = 0 );
00447              sc_fxval_fast( long,
00448                 sc_fxval_fast_observer* = 0 );
00449              sc_fxval_fast( unsigned long,
00450                 sc_fxval_fast_observer* = 0 );
00451              sc_fxval_fast( double,
00452                 sc_fxval_fast_observer* = 0 );
00453              sc_fxval_fast( const char*,
00454                 sc_fxval_fast_observer* = 0 );
00455              sc_fxval_fast( const sc_fxval&,
00456                 sc_fxval_fast_observer* = 0 );
00457              sc_fxval_fast( const sc_fxval_fast&,
00458                 sc_fxval_fast_observer* = 0 );
00459              sc_fxval_fast( const sc_fxnum&,
00460                 sc_fxval_fast_observer* = 0 );
00461              sc_fxval_fast( const sc_fxnum_fast&,
00462                 sc_fxval_fast_observer* = 0 );
00463 #ifndef SC_FX_EXCLUDE_OTHER
00464     explicit sc_fxval_fast( int64,
00465                 sc_fxval_fast_observer* = 0 );
00466     explicit sc_fxval_fast( uint64,
00467                 sc_fxval_fast_observer* = 0 );
00468     explicit sc_fxval_fast( const sc_int_base&,
00469                 sc_fxval_fast_observer* = 0 );
00470     explicit sc_fxval_fast( const sc_uint_base&,
00471                 sc_fxval_fast_observer* = 0 );
00472     explicit sc_fxval_fast( const sc_signed&,
00473                 sc_fxval_fast_observer* = 0 );
00474     explicit sc_fxval_fast( const sc_unsigned&,
00475                 sc_fxval_fast_observer* = 0 );
00476 #endif
00477 
00478     ~sc_fxval_fast();
00479 
00480     // internal use only;
00481     double get_val() const;
00482     void set_val( double );
00483 
00484 
00485     // unary operators
00486 
00487     const sc_fxval_fast  operator - () const;
00488     const sc_fxval_fast& operator + () const;
00489 
00490 
00491     // unary functions
00492 
00493     friend void neg( sc_fxval_fast&, const sc_fxval_fast& );
00494 
00495 
00496     // binary operators
00497 
00498 #define DECL_BIN_OP_T(op,tp)                                                  \
00499     friend const sc_fxval_fast operator op ( const sc_fxval_fast&, tp );      \
00500     friend const sc_fxval_fast operator op ( tp, const sc_fxval_fast& );
00501 
00502 #ifndef SC_FX_EXCLUDE_OTHER
00503 #define DECL_BIN_OP_OTHER(op)                                                 \
00504     DECL_BIN_OP_T(op,int64)                                                   \
00505     DECL_BIN_OP_T(op,uint64)                                                  \
00506     DECL_BIN_OP_T(op,const sc_int_base&)                                      \
00507     DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
00508     DECL_BIN_OP_T(op,const sc_signed&)                                        \
00509     DECL_BIN_OP_T(op,const sc_unsigned&)
00510 #else
00511 #define DECL_BIN_OP_OTHER(op)
00512 #endif
00513 
00514 #define DECL_BIN_OP(op,dummy)                                                 \
00515     friend const sc_fxval_fast operator op ( const sc_fxval_fast&,            \
00516                          const sc_fxval_fast& );          \
00517     DECL_BIN_OP_T(op,int)                                                     \
00518     DECL_BIN_OP_T(op,unsigned int)                                            \
00519     DECL_BIN_OP_T(op,long)                                                    \
00520     DECL_BIN_OP_T(op,unsigned long)                                           \
00521     DECL_BIN_OP_T(op,double)                                                  \
00522     DECL_BIN_OP_T(op,const char*)                                             \
00523     DECL_BIN_OP_OTHER(op)
00524 
00525     DECL_BIN_OP(*,mult)
00526     DECL_BIN_OP(+,add)
00527     DECL_BIN_OP(-,sub)
00528 // don't use macro
00529 //    DECL_BIN_OP(/,div)
00530     friend const sc_fxval_fast operator / ( const sc_fxval_fast&,
00531                          const sc_fxval_fast& );
00532     DECL_BIN_OP_T(/,int)
00533     DECL_BIN_OP_T(/,unsigned int)
00534     DECL_BIN_OP_T(/,long)
00535     DECL_BIN_OP_T(/,unsigned long)
00536     DECL_BIN_OP_T(/,double)
00537     DECL_BIN_OP_T(/,const char*)
00538 //    DECL_BIN_OP_OTHER(/)
00539 #ifndef SC_FX_EXCLUDE_OTHER
00540     DECL_BIN_OP_T(/,int64)                                                   \
00541     DECL_BIN_OP_T(/,uint64)                                                  \
00542     DECL_BIN_OP_T(/,const sc_int_base&)                                      \
00543     DECL_BIN_OP_T(/,const sc_uint_base&)                                     \
00544     DECL_BIN_OP_T(/,const sc_signed&)                                        \
00545     DECL_BIN_OP_T(/,const sc_unsigned&)
00546 #endif
00547 
00548 #undef DECL_BIN_OP_T
00549 #undef DECL_BIN_OP_OTHER
00550 #undef DECL_BIN_OP
00551 
00552     friend const sc_fxval_fast operator << ( const sc_fxval_fast&, int );
00553     friend const sc_fxval_fast operator >> ( const sc_fxval_fast&, int );
00554 
00555 
00556     // binary functions
00557 
00558 #define DECL_BIN_FNC_T(fnc,tp)                                                \
00559     friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&, tp );             \
00560     friend void fnc ( sc_fxval_fast&, tp, const sc_fxval_fast& );
00561 
00562 #ifndef SC_FX_EXCLUDE_OTHER
00563 #define DECL_BIN_FNC_OTHER(fnc)                                               \
00564     DECL_BIN_FNC_T(fnc,int64)                                                 \
00565     DECL_BIN_FNC_T(fnc,uint64)                                                \
00566     DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
00567     DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
00568     DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
00569     DECL_BIN_FNC_T(fnc,const sc_unsigned&)
00570 #else
00571 #define DECL_BIN_FNC_OTHER(fnc)
00572 #endif
00573 
00574 #define DECL_BIN_FNC(fnc)                                                     \
00575     friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&,                   \
00576                       const sc_fxval_fast& );                                 \
00577     DECL_BIN_FNC_T(fnc,int)                                                   \
00578     DECL_BIN_FNC_T(fnc,unsigned int)                                          \
00579     DECL_BIN_FNC_T(fnc,long)                                                  \
00580     DECL_BIN_FNC_T(fnc,unsigned long)                                         \
00581     DECL_BIN_FNC_T(fnc,double)                                                \
00582     DECL_BIN_FNC_T(fnc,const char*)                                           \
00583     DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
00584     DECL_BIN_FNC_T(fnc,const sc_fxnum&)                                       \
00585     DECL_BIN_FNC_OTHER(fnc)
00586 
00587     DECL_BIN_FNC(mult)
00588     DECL_BIN_FNC(div)
00589     DECL_BIN_FNC(add)
00590     DECL_BIN_FNC(sub)
00591 
00592 #undef DECL_BIN_FNC_T
00593 #undef DECL_BIN_FNC_OTHER
00594 #undef DECL_BIN_FNC
00595 
00596     friend void lshift( sc_fxval_fast&, const sc_fxval_fast&, int );
00597     friend void rshift( sc_fxval_fast&, const sc_fxval_fast&, int );
00598 
00599 
00600     // relational (including equality) operators
00601 
00602 #define DECL_REL_OP_T(op,tp)                                                  \
00603     friend bool operator op ( const sc_fxval_fast&, tp );                     \
00604     friend bool operator op ( tp, const sc_fxval_fast& );
00605 
00606 #ifndef SC_FX_EXCLUDE_OTHER
00607 #define DECL_REL_OP_OTHER(op)                                                 \
00608     DECL_REL_OP_T(op,int64)                                                   \
00609     DECL_REL_OP_T(op,uint64)                                                  \
00610     DECL_REL_OP_T(op,const sc_int_base&)                                      \
00611     DECL_REL_OP_T(op,const sc_uint_base&)                                     \
00612     DECL_REL_OP_T(op,const sc_signed&)                                        \
00613     DECL_REL_OP_T(op,const sc_unsigned&)
00614 #else
00615 #define DECL_REL_OP_OTHER(op)
00616 #endif
00617 
00618 #define DECL_REL_OP(op)                                                       \
00619     friend bool operator op ( const sc_fxval_fast&, const sc_fxval_fast& );   \
00620     DECL_REL_OP_T(op,int)                                                     \
00621     DECL_REL_OP_T(op,unsigned int)                                            \
00622     DECL_REL_OP_T(op,long)                                                    \
00623     DECL_REL_OP_T(op,unsigned long)                                           \
00624     DECL_REL_OP_T(op,double)                                                  \
00625     DECL_REL_OP_T(op,const char*)                                             \
00626     DECL_REL_OP_OTHER(op)
00627 
00628     DECL_REL_OP(<)
00629     DECL_REL_OP(<=)
00630     DECL_REL_OP(>)
00631     DECL_REL_OP(>=)
00632     DECL_REL_OP(==)
00633     DECL_REL_OP(!=)
00634 
00635 #undef DECL_REL_OP_T
00636 #undef DECL_REL_OP_OTHER
00637 #undef DECL_REL_OP
00638 
00639 
00640     // assignment operators
00641 
00642 #define DECL_ASN_OP_T(op,tp)                                                  \
00643     sc_fxval_fast& operator op( tp );
00644 
00645 #ifndef SC_FX_EXCLUDE_OTHER
00646 #define DECL_ASN_OP_OTHER(op)                                                 \
00647     DECL_ASN_OP_T(op,int64)                                                   \
00648     DECL_ASN_OP_T(op,uint64)                                                  \
00649     DECL_ASN_OP_T(op,const sc_int_base&)                                      \
00650     DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
00651     DECL_ASN_OP_T(op,const sc_signed&)                                        \
00652     DECL_ASN_OP_T(op,const sc_unsigned&)
00653 #else
00654 #define DECL_ASN_OP_OTHER(op)
00655 #endif
00656 
00657 #define DECL_ASN_OP(op)                                                       \
00658     DECL_ASN_OP_T(op,int)                                                     \
00659     DECL_ASN_OP_T(op,unsigned int)                                            \
00660     DECL_ASN_OP_T(op,long)                                                    \
00661     DECL_ASN_OP_T(op,unsigned long)                                           \
00662     DECL_ASN_OP_T(op,double)                                                  \
00663     DECL_ASN_OP_T(op,const char*)                                             \
00664     DECL_ASN_OP_T(op,const sc_fxval&)                                         \
00665     DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
00666     DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
00667     DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
00668     DECL_ASN_OP_OTHER(op)
00669 
00670     DECL_ASN_OP(=)
00671 
00672     DECL_ASN_OP(*=)
00673     DECL_ASN_OP(/=)
00674     DECL_ASN_OP(+=)
00675     DECL_ASN_OP(-=)
00676 
00677     DECL_ASN_OP_T(<<=,int)
00678     DECL_ASN_OP_T(>>=,int)
00679 
00680 #undef DECL_ASN_OP_T
00681 #undef DECL_ASN_OP_OTHER
00682 #undef DECL_ASN_OP
00683 
00684 
00685     // auto-increment and auto-decrement
00686 
00687     const sc_fxval_fast operator ++ ( int );
00688     const sc_fxval_fast operator -- ( int );
00689 
00690     sc_fxval_fast& operator ++ ();
00691     sc_fxval_fast& operator -- ();
00692 
00693 
00694     // implicit conversion
00695 
00696     operator double() const;            // necessary evil!
00697 
00698 
00699     // explicit conversion to primitive types
00700 
00701     short          to_short() const;
00702     unsigned short to_ushort() const;
00703     int            to_int() const;
00704     unsigned int   to_uint() const;
00705     long           to_long() const;
00706     unsigned long  to_ulong() const;
00707     int64          to_int64() const;
00708     uint64         to_uint64() const;
00709     float          to_float() const;
00710     double         to_double() const;
00711 
00712 
00713     // explicit conversion to character string
00714 
00715     const std::string to_string() const;
00716     const std::string to_string( sc_numrep ) const;
00717     const std::string to_string( sc_numrep, bool ) const;
00718     const std::string to_string( sc_fmt ) const;
00719     const std::string to_string( sc_numrep, sc_fmt ) const;
00720     const std::string to_string( sc_numrep, bool, sc_fmt ) const;
00721 
00722     const std::string to_dec() const;
00723     const std::string to_bin() const;
00724     const std::string to_oct() const;
00725     const std::string to_hex() const;
00726 
00727 
00728     // query value
00729 
00730     bool is_neg() const;
00731     bool is_zero() const;
00732     bool is_nan() const;
00733     bool is_inf() const;
00734     bool is_normal() const;
00735 
00736     bool rounding_flag() const;
00737 
00738 
00739     // print or dump content
00740 
00741     void print( ::std::ostream& = ::std::cout ) const;
00742     void scan( ::std::istream& = ::std::cin );
00743     void dump( ::std::ostream& = ::std::cout ) const;
00744 
00745 
00746     // internal use only;
00747     bool get_bit( int ) const;
00748 
00749 protected:
00750 
00751     sc_fxval_fast_observer* lock_observer() const;
00752     void unlock_observer( sc_fxval_fast_observer* ) const;
00753 
00754 
00755     static double from_string( const char* );
00756 
00757 private:
00758 
00759     double                          m_val;
00760 
00761     mutable sc_fxval_fast_observer* m_observer;
00762 
00763 };
00764 
00765 
00766 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00767 
00768 // ----------------------------------------------------------------------------
00769 //  CLASS : sc_fxval
00770 //
00771 //  Fixed-point value type; arbitrary precision.
00772 // ----------------------------------------------------------------------------
00773 
00774 // protected method
00775 
00776 inline
00777 sc_fxval_observer*
00778 sc_fxval::observer() const
00779 {
00780     return m_observer;
00781 }
00782 
00783 
00784 // internal use only;
00785 inline
00786 sc_fxval::sc_fxval( scfx_rep* a )
00787 : m_rep( a ),
00788   m_observer( 0 )
00789 {}
00790 
00791 
00792 // public constructors
00793 
00794 inline
00795 sc_fxval::sc_fxval( sc_fxval_observer* observer_ )
00796 : m_rep( new scfx_rep ),
00797   m_observer( observer_ )
00798 {
00799     SC_FXVAL_OBSERVER_DEFAULT_
00800     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
00801 }
00802 
00803 inline
00804 sc_fxval::sc_fxval( const sc_fxval& a,
00805             sc_fxval_observer* observer_ )
00806 : m_rep( new scfx_rep( *a.m_rep ) ),
00807   m_observer( observer_ )
00808 {
00809     SC_FXVAL_OBSERVER_DEFAULT_
00810     SC_FXVAL_OBSERVER_READ_( a )
00811     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
00812     SC_FXVAL_OBSERVER_WRITE_( *this )
00813 }
00814 
00815 #define DEFN_CTOR_T(tp,arg)                                                   \
00816 inline                                                                        \
00817 sc_fxval::sc_fxval( tp a,                                                     \
00818                     sc_fxval_observer* observer_ )                            \
00819 : m_rep( new scfx_rep( arg ) ),                                               \
00820   m_observer( observer_ )                                                     \
00821 {                                                                             \
00822     SC_FXVAL_OBSERVER_DEFAULT_                                                \
00823     SC_FXVAL_OBSERVER_CONSTRUCT_( *this )                                     \
00824     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
00825 }
00826 
00827 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
00828 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,a.to_double())
00829 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.value())
00830 
00831 DEFN_CTOR_T_A(int)
00832 DEFN_CTOR_T_A(unsigned int)
00833 DEFN_CTOR_T_A(long)
00834 DEFN_CTOR_T_A(unsigned long)
00835 DEFN_CTOR_T_A(double)
00836 DEFN_CTOR_T_A(const char*)
00837 DEFN_CTOR_T_B(const sc_fxval_fast&)
00838 #ifndef SC_FX_EXCLUDE_OTHER
00839 DEFN_CTOR_T_A(int64)
00840 DEFN_CTOR_T_A(uint64)
00841 DEFN_CTOR_T_C(const sc_int_base&)
00842 DEFN_CTOR_T_C(const sc_uint_base&)
00843 DEFN_CTOR_T_A(const sc_signed&)
00844 DEFN_CTOR_T_A(const sc_unsigned&)
00845 #endif
00846 
00847 #undef DEFN_CTOR_T
00848 #undef DEFN_CTOR_T_A
00849 #undef DEFN_CTOR_T_B
00850 #undef DEFN_CTOR_T_C
00851 
00852 
00853 inline
00854 sc_fxval::~sc_fxval()
00855 {
00856     SC_FXVAL_OBSERVER_DESTRUCT_( *this )
00857     delete m_rep;
00858 }
00859 
00860 
00861 // internal use only;
00862 inline
00863 const scfx_rep*
00864 sc_fxval::get_rep() const
00865 {
00866     SC_FXVAL_OBSERVER_READ_( *this )
00867     return m_rep;
00868 }
00869 
00870 // internal use only;
00871 inline
00872 void
00873 sc_fxval::set_rep( scfx_rep* rep_ )
00874 {
00875     delete m_rep;
00876     m_rep = rep_;
00877     SC_FXVAL_OBSERVER_WRITE_( *this )
00878 }
00879 
00880 
00881 // unary operators
00882 
00883 inline
00884 const sc_fxval
00885 sc_fxval::operator - () const
00886 {
00887     SC_FXVAL_OBSERVER_READ_( *this )
00888     return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
00889 }
00890 
00891 inline
00892 const sc_fxval&
00893 sc_fxval::operator + () const
00894 {
00895     // SC_FXVAL_OBSERVER_READ_( *this )
00896     return *this;
00897 }
00898 
00899 
00900 // unary functions
00901 
00902 inline
00903 void
00904 neg( sc_fxval& c, const sc_fxval& a )
00905 {
00906     SC_FXVAL_OBSERVER_READ_( a )
00907     delete c.m_rep;
00908     c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
00909     SC_FXVAL_OBSERVER_WRITE_( c )
00910 }
00911 
00912 
00913 // binary operators
00914 
00915 #define DEFN_BIN_OP_T(op,fnc,tp)                                              \
00916 inline                                                                        \
00917 const sc_fxval                                                                \
00918 operator op ( const sc_fxval& a, tp b )                                       \
00919 {                                                                             \
00920     SC_FXVAL_OBSERVER_READ_( a )                                              \
00921     sc_fxval tmp( b );                                                        \
00922     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) );      \
00923 }                                                                             \
00924                                                                               \
00925 inline                                                                        \
00926 const sc_fxval                                                                \
00927 operator op ( tp a, const sc_fxval& b )                                       \
00928 {                                                                             \
00929     SC_FXVAL_OBSERVER_READ_( b )                                              \
00930     sc_fxval tmp( a );                                                        \
00931     return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) );      \
00932 }
00933 
00934 #ifndef SC_FX_EXCLUDE_OTHER
00935 #define DEFN_BIN_OP_OTHER(op,fnc)                                             \
00936 DEFN_BIN_OP_T(op,fnc,int64)                                                   \
00937 DEFN_BIN_OP_T(op,fnc,uint64)                                                  \
00938 DEFN_BIN_OP_T(op,fnc,const sc_int_base&)                                      \
00939 DEFN_BIN_OP_T(op,fnc,const sc_uint_base&)                                     \
00940 DEFN_BIN_OP_T(op,fnc,const sc_signed&)                                        \
00941 DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
00942 #else
00943 #define DEFN_BIN_OP_OTHER(op,fnc)
00944 #endif
00945 
00946 #define DEFN_BIN_OP(op,fnc)                                                   \
00947 inline                                                                        \
00948 const sc_fxval                                                                \
00949 operator op ( const sc_fxval& a, const sc_fxval& b )                          \
00950 {                                                                             \
00951     SC_FXVAL_OBSERVER_READ_( a )                                              \
00952     SC_FXVAL_OBSERVER_READ_( b )                                              \
00953     return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );        \
00954 }                                                                             \
00955                                                                               \
00956 DEFN_BIN_OP_T(op,fnc,int)                                                     \
00957 DEFN_BIN_OP_T(op,fnc,unsigned int)                                            \
00958 DEFN_BIN_OP_T(op,fnc,long)                                                    \
00959 DEFN_BIN_OP_T(op,fnc,unsigned long)                                           \
00960 DEFN_BIN_OP_T(op,fnc,double)                                                  \
00961 DEFN_BIN_OP_T(op,fnc,const char*)                                             \
00962 DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
00963 DEFN_BIN_OP_OTHER(op,fnc)
00964 
00965 DEFN_BIN_OP(*,mult)
00966 DEFN_BIN_OP(+,add)
00967 DEFN_BIN_OP(-,sub)
00968 // don't use macro
00969 //DEFN_BIN_OP(/,div)
00970 inline
00971 const sc_fxval
00972 operator / ( const sc_fxval& a, const sc_fxval& b )
00973 {
00974     SC_FXVAL_OBSERVER_READ_( a )
00975     SC_FXVAL_OBSERVER_READ_( b )
00976     return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
00977 }
00978 
00979 DEFN_BIN_OP_T(/,div,int)
00980 DEFN_BIN_OP_T(/,div,unsigned int)
00981 DEFN_BIN_OP_T(/,div,long)
00982 DEFN_BIN_OP_T(/,div,unsigned long)
00983 DEFN_BIN_OP_T(/,div,double)
00984 DEFN_BIN_OP_T(/,div,const char*)
00985 DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
00986 //DEFN_BIN_OP_OTHER(/,div)
00987 #ifndef SC_FX_EXCLUDE_OTHER
00988 DEFN_BIN_OP_T(/,div,int64)                                                   \
00989 DEFN_BIN_OP_T(/,div,uint64)                                                  \
00990 DEFN_BIN_OP_T(/,div,const sc_int_base&)                                      \
00991 DEFN_BIN_OP_T(/,div,const sc_uint_base&)                                     \
00992 DEFN_BIN_OP_T(/,div,const sc_signed&)                                        \
00993 DEFN_BIN_OP_T(/,div,const sc_unsigned&)
00994 #endif
00995 
00996 #undef DEFN_BIN_OP_T
00997 #undef DEFN_BIN_OP_OTHER
00998 #undef DEFN_BIN_OP
00999 
01000 
01001 inline
01002 const sc_fxval
01003 operator << ( const sc_fxval& a, int b )
01004 {
01005     SC_FXVAL_OBSERVER_READ_( a )
01006     return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
01007 }
01008 
01009 inline
01010 const sc_fxval
01011 operator >> ( const sc_fxval& a, int b )
01012 {
01013     SC_FXVAL_OBSERVER_READ_( a )
01014     return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
01015 }
01016 
01017 
01018 // binary functions
01019 
01020 #define DEFN_BIN_FNC_T(fnc,tp)                                                \
01021 inline                                                                        \
01022 void                                                                          \
01023 fnc ( sc_fxval& c, const sc_fxval& a, tp b )                                  \
01024 {                                                                             \
01025     SC_FXVAL_OBSERVER_READ_( a )                                              \
01026     sc_fxval tmp( b );                                                        \
01027     delete c.m_rep;                                                           \
01028     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep );               \
01029     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
01030 }                                                                             \
01031                                                                               \
01032 inline                                                                        \
01033 void                                                                          \
01034 fnc ( sc_fxval& c, tp a, const sc_fxval& b )                                  \
01035 {                                                                             \
01036     SC_FXVAL_OBSERVER_READ_( b )                                              \
01037     sc_fxval tmp( a );                                                        \
01038     delete c.m_rep;                                                           \
01039     c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep );               \
01040     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
01041 }
01042 
01043 #ifndef SC_FX_EXCLUDE_OTHER
01044 #define DEFN_BIN_FNC_OTHER(fnc)                                               \
01045 DEFN_BIN_FNC_T(fnc,int64)                                                     \
01046 DEFN_BIN_FNC_T(fnc,uint64)                                                    \
01047 DEFN_BIN_FNC_T(fnc,const sc_int_base&)                                        \
01048 DEFN_BIN_FNC_T(fnc,const sc_uint_base&)                                       \
01049 DEFN_BIN_FNC_T(fnc,const sc_signed&)                                          \
01050 DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
01051 #else
01052 #define DEFN_BIN_FNC_OTHER(fnc)
01053 #endif
01054 
01055 #define DEFN_BIN_FNC(fnc)                                                     \
01056 inline                                                                        \
01057 void                                                                          \
01058 fnc( sc_fxval& c, const sc_fxval& a, const sc_fxval& b )                      \
01059 {                                                                             \
01060     SC_FXVAL_OBSERVER_READ_( a )                                              \
01061     SC_FXVAL_OBSERVER_READ_( b )                                              \
01062     delete c.m_rep;                                                           \
01063     c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep );                 \
01064     SC_FXVAL_OBSERVER_WRITE_( c )                                             \
01065 }                                                                             \
01066                                                                               \
01067 DEFN_BIN_FNC_T(fnc,int)                                                       \
01068 DEFN_BIN_FNC_T(fnc,unsigned int)                                              \
01069 DEFN_BIN_FNC_T(fnc,long)                                                      \
01070 DEFN_BIN_FNC_T(fnc,unsigned long)                                             \
01071 DEFN_BIN_FNC_T(fnc,double)                                                    \
01072 DEFN_BIN_FNC_T(fnc,const char*)                                               \
01073 DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&)                                      \
01074 DEFN_BIN_FNC_OTHER(fnc)
01075 
01076 DEFN_BIN_FNC(mult)
01077 DEFN_BIN_FNC(div)
01078 DEFN_BIN_FNC(add)
01079 DEFN_BIN_FNC(sub)
01080 
01081 #undef DEFN_BIN_FNC_T
01082 #undef DEFN_BIN_FNC_OTHER
01083 #undef DEFN_BIN_FNC
01084 
01085 
01086 inline
01087 void
01088 lshift( sc_fxval& c, const sc_fxval& a, int b )
01089 {
01090     SC_FXVAL_OBSERVER_READ_( a )
01091     delete c.m_rep;
01092     c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
01093     SC_FXVAL_OBSERVER_WRITE_( c )
01094 }
01095 
01096 inline
01097 void
01098 rshift( sc_fxval& c, const sc_fxval& a, int b )
01099 {
01100     SC_FXVAL_OBSERVER_READ_( a )
01101     delete c.m_rep;
01102     c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
01103     SC_FXVAL_OBSERVER_WRITE_( c )
01104 }
01105 
01106 
01107 // relational (including equality) operators
01108 
01109 #define DEFN_REL_OP_T(op,ret,tp)                                              \
01110 inline                                                                        \
01111 bool                                                                          \
01112 operator op ( const sc_fxval& a, tp b )                                       \
01113 {                                                                             \
01114     SC_FXVAL_OBSERVER_READ_( a )                                              \
01115     sc_fxval tmp( b );                                                        \
01116     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep );                \
01117     return ( ret );                                                           \
01118 }                                                                             \
01119                                                                               \
01120 inline                                                                        \
01121 bool                                                                          \
01122 operator op ( tp a, const sc_fxval& b )                                       \
01123 {                                                                             \
01124     SC_FXVAL_OBSERVER_READ_( b )                                              \
01125     sc_fxval tmp( a );                                                        \
01126     int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep );                \
01127     return ( ret );                                                           \
01128 }
01129 
01130 #ifndef SC_FX_EXCLUDE_OTHER
01131 #define DEFN_REL_OP_OTHER(op,ret)                                             \
01132 DEFN_REL_OP_T(op,ret,int64)                                                   \
01133 DEFN_REL_OP_T(op,ret,uint64)                                                  \
01134 DEFN_REL_OP_T(op,ret,const sc_int_base&)                                      \
01135 DEFN_REL_OP_T(op,ret,const sc_uint_base&)                                     \
01136 DEFN_REL_OP_T(op,ret,const sc_signed&)                                        \
01137 DEFN_REL_OP_T(op,ret,const sc_unsigned&)
01138 #else
01139 #define DEFN_REL_OP_OTHER(op,ret)
01140 #endif
01141 
01142 #define DEFN_REL_OP(op,ret)                                                   \
01143 inline                                                                        \
01144 bool                                                                          \
01145 operator op ( const sc_fxval& a, const sc_fxval& b)                           \
01146 {                                                                             \
01147     SC_FXVAL_OBSERVER_READ_( a )                                              \
01148     SC_FXVAL_OBSERVER_READ_( b )                                              \
01149     int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep );                  \
01150     return ( ret );                                                           \
01151 }                                                                             \
01152                                                                               \
01153 DEFN_REL_OP_T(op,ret,int)                                                     \
01154 DEFN_REL_OP_T(op,ret,unsigned int)                                            \
01155 DEFN_REL_OP_T(op,ret,long)                                                    \
01156 DEFN_REL_OP_T(op,ret,unsigned long)                                           \
01157 DEFN_REL_OP_T(op,ret,double)                                                  \
01158 DEFN_REL_OP_T(op,ret,const char*)                                             \
01159 DEFN_REL_OP_T(op,ret,const sc_fxval_fast&)                                    \
01160 DEFN_REL_OP_OTHER(op,ret)
01161 
01162 DEFN_REL_OP(<,result < 0)
01163 DEFN_REL_OP(<=,result <= 0)
01164 DEFN_REL_OP(>,result > 0 && result != 2)
01165 DEFN_REL_OP(>=,result >= 0 && result != 2)
01166 DEFN_REL_OP(==,result == 0)
01167 DEFN_REL_OP(!=,result != 0)
01168 
01169 #undef DEFN_REL_OP_T
01170 #undef DEFN_REL_OP_OTHER
01171 #undef DEFN_REL_OP
01172 
01173 
01174 // assignment operators
01175 
01176 inline
01177 sc_fxval&
01178 sc_fxval::operator = ( const sc_fxval& a )
01179 {
01180     if( &a != this )
01181     {
01182     SC_FXVAL_OBSERVER_READ_( a )
01183     *m_rep = *a.m_rep;
01184     SC_FXVAL_OBSERVER_WRITE_( *this )
01185     }
01186     return *this;
01187 }
01188 
01189 #define DEFN_ASN_OP_T(tp)                                                     \
01190 inline                                                                        \
01191 sc_fxval&                                                                     \
01192 sc_fxval::operator = ( tp b )                                                 \
01193 {                                                                             \
01194     sc_fxval tmp( b );                                                        \
01195     *m_rep = *tmp.m_rep;                                                      \
01196     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
01197     return *this;                                                             \
01198 }
01199 
01200 DEFN_ASN_OP_T(int)
01201 DEFN_ASN_OP_T(unsigned int)
01202 DEFN_ASN_OP_T(long)
01203 DEFN_ASN_OP_T(unsigned long)
01204 DEFN_ASN_OP_T(double)
01205 DEFN_ASN_OP_T(const char*)
01206 DEFN_ASN_OP_T(const sc_fxval_fast&)
01207 #ifndef SC_FX_EXCLUDE_OTHER
01208 DEFN_ASN_OP_T(int64)
01209 DEFN_ASN_OP_T(uint64)
01210 DEFN_ASN_OP_T(const sc_int_base&)
01211 DEFN_ASN_OP_T(const sc_uint_base&)
01212 DEFN_ASN_OP_T(const sc_signed&)
01213 DEFN_ASN_OP_T(const sc_unsigned&)
01214 #endif
01215 
01216 #undef DEFN_ASN_OP_T
01217 
01218 
01219 #define DEFN_ASN_OP_T(op,fnc,tp)                                              \
01220 inline                                                                        \
01221 sc_fxval&                                                                     \
01222 sc_fxval::operator op ( tp b )                                                \
01223 {                                                                             \
01224     SC_FXVAL_OBSERVER_READ_( *this )                                          \
01225     sc_fxval tmp( b );                                                        \
01226     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep );       \
01227     delete m_rep;                                                             \
01228     m_rep = new_rep;                                                          \
01229     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
01230     return *this;                                                             \
01231 }
01232 
01233 #ifndef SC_FX_EXCLUDE_OTHER
01234 #define DEFN_ASN_OP_OTHER(op,fnc)                                             \
01235 DEFN_ASN_OP_T(op,fnc,int64)                                                   \
01236 DEFN_ASN_OP_T(op,fnc,uint64)                                                  \
01237 DEFN_ASN_OP_T(op,fnc,const sc_int_base&)                                      \
01238 DEFN_ASN_OP_T(op,fnc,const sc_uint_base&)                                     \
01239 DEFN_ASN_OP_T(op,fnc,const sc_signed&)                                        \
01240 DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
01241 #else
01242 #define DEFN_ASN_OP_OTHER(op,fnc)
01243 #endif
01244 
01245 #define DEFN_ASN_OP(op,fnc)                                                   \
01246 inline                                                                        \
01247 sc_fxval&                                                                     \
01248 sc_fxval::operator op ( const sc_fxval& b )                                   \
01249 {                                                                             \
01250     SC_FXVAL_OBSERVER_READ_( *this )                                          \
01251     SC_FXVAL_OBSERVER_READ_( b )                                              \
01252     scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep );         \
01253     delete m_rep;                                                             \
01254     m_rep = new_rep;                                                          \
01255     SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
01256     return *this;                                                             \
01257 }                                                                             \
01258                                                                               \
01259 DEFN_ASN_OP_T(op,fnc,int)                                                     \
01260 DEFN_ASN_OP_T(op,fnc,unsigned int)                                            \
01261 DEFN_ASN_OP_T(op,fnc,long)                                                    \
01262 DEFN_ASN_OP_T(op,fnc,unsigned long)                                           \
01263 DEFN_ASN_OP_T(op,fnc,double)                                                  \
01264 DEFN_ASN_OP_T(op,fnc,const char*)                                             \
01265 DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
01266 DEFN_ASN_OP_OTHER(op,fnc)
01267 
01268 DEFN_ASN_OP(*=,mult)
01269 DEFN_ASN_OP(/=,div)
01270 DEFN_ASN_OP(+=,add)
01271 DEFN_ASN_OP(-=,sub)
01272 
01273 #undef DEFN_ASN_OP_T
01274 #undef DEFN_ASN_OP_OTHER
01275 #undef DEFN_ASN_OP
01276 
01277 
01278 inline
01279 sc_fxval&
01280 sc_fxval::operator <<= ( int b )
01281 {
01282     SC_FXVAL_OBSERVER_READ_( *this )
01283     m_rep->lshift( b );
01284     SC_FXVAL_OBSERVER_WRITE_( *this )
01285     return *this;
01286 }
01287 
01288 inline
01289 sc_fxval&
01290 sc_fxval::operator >>= ( int b )
01291 {
01292     SC_FXVAL_OBSERVER_READ_( *this )
01293     m_rep->rshift( b );
01294     SC_FXVAL_OBSERVER_WRITE_( *this )
01295     return *this;
01296 }
01297 
01298 
01299 // auto-increment and auto-decrement
01300 
01301 inline
01302 const sc_fxval
01303 sc_fxval::operator ++ ( int )
01304 {
01305     sc_fxval c = *this;
01306     (*this) += 1;
01307     return c;
01308 }
01309 
01310 inline
01311 const sc_fxval
01312 sc_fxval::operator -- ( int )
01313 {
01314     sc_fxval c = *this;
01315     (*this) -= 1;
01316     return c;
01317 }
01318 
01319 inline
01320 sc_fxval&
01321 sc_fxval::operator ++ ()
01322 {
01323     (*this) += 1;
01324     return *this;
01325 }
01326 
01327 inline
01328 sc_fxval&
01329 sc_fxval::operator -- ()
01330 {
01331     (*this) -= 1;
01332     return *this;
01333 }
01334 
01335 
01336 // implicit conversion
01337 
01338 inline
01339 sc_fxval::operator double() const
01340 {
01341     SC_FXVAL_OBSERVER_READ_( *this )
01342     return m_rep->to_double();
01343 }
01344 
01345 
01346 // explicit conversion to primitive types
01347 
01348 inline
01349 short
01350 sc_fxval::to_short() const
01351 {
01352     SC_FXVAL_OBSERVER_READ_( *this )
01353     return static_cast<short>( m_rep->to_double() );
01354 }
01355 
01356 inline
01357 unsigned short
01358 sc_fxval::to_ushort() const
01359 {
01360     SC_FXVAL_OBSERVER_READ_( *this )
01361     return static_cast<unsigned short>( m_rep->to_double() );
01362 }
01363 
01364 inline
01365 int
01366 sc_fxval::to_int() const
01367 {
01368     SC_FXVAL_OBSERVER_READ_( *this )
01369     return static_cast<int>( m_rep->to_double() );
01370 }
01371 
01372 inline
01373 int64
01374 sc_fxval::to_int64() const
01375 {
01376     SC_FXVAL_OBSERVER_READ_( *this )
01377     return static_cast<int64>( m_rep->to_double() );
01378 }
01379 
01380 inline
01381 uint64
01382 sc_fxval::to_uint64() const
01383 {
01384     SC_FXVAL_OBSERVER_READ_( *this )
01385     return static_cast<uint64>( m_rep->to_double() );
01386 }
01387 
01388 inline
01389 long
01390 sc_fxval::to_long() const
01391 {
01392     SC_FXVAL_OBSERVER_READ_( *this )
01393     return static_cast<long>( m_rep->to_double() );
01394 }
01395 
01396 inline
01397 unsigned int
01398 sc_fxval::to_uint() const
01399 {
01400     SC_FXVAL_OBSERVER_READ_( *this )
01401     return static_cast<unsigned int>( m_rep->to_double() );
01402 }
01403 
01404 inline
01405 unsigned long
01406 sc_fxval::to_ulong() const
01407 {
01408     SC_FXVAL_OBSERVER_READ_( *this )
01409     return static_cast<unsigned long>( m_rep->to_double() );
01410 }
01411 
01412 inline
01413 float
01414 sc_fxval::to_float() const
01415 {
01416     SC_FXVAL_OBSERVER_READ_( *this )
01417     return static_cast<float>( m_rep->to_double() );
01418 }
01419 
01420 inline
01421 double
01422 sc_fxval::to_double() const
01423 {
01424     SC_FXVAL_OBSERVER_READ_( *this )
01425     return m_rep->to_double();
01426 }
01427 
01428 
01429 // query value
01430 
01431 inline
01432 bool
01433 sc_fxval::is_neg() const
01434 {
01435     SC_FXVAL_OBSERVER_READ_( *this )
01436     return m_rep->is_neg();
01437 }
01438 
01439 inline
01440 bool
01441 sc_fxval::is_zero() const
01442 {
01443     SC_FXVAL_OBSERVER_READ_( *this )
01444     return m_rep->is_zero();
01445 }
01446 
01447 inline
01448 bool
01449 sc_fxval::is_nan() const
01450 {
01451     SC_FXVAL_OBSERVER_READ_( *this )
01452     return m_rep->is_nan();
01453 }
01454 
01455 inline
01456 bool
01457 sc_fxval::is_inf() const
01458 {
01459     SC_FXVAL_OBSERVER_READ_( *this )
01460     return m_rep->is_inf();
01461 }
01462 
01463 inline
01464 bool
01465 sc_fxval::is_normal() const
01466 {
01467     SC_FXVAL_OBSERVER_READ_( *this )
01468     return m_rep->is_normal();
01469 }
01470 
01471 
01472 inline
01473 bool
01474 sc_fxval::rounding_flag() const
01475 {
01476     return m_rep->rounding_flag();
01477 }
01478 
01479 
01480 // internal use only;
01481 inline
01482 bool
01483 sc_fxval::get_bit( int i ) const
01484 {
01485     return m_rep->get_bit( i );
01486 }
01487 
01488 
01489 // protected methods and friend functions
01490 
01491 inline
01492 void
01493 sc_fxval::get_type( int& wl, int& iwl, sc_enc& enc ) const
01494 {
01495     m_rep->get_type( wl, iwl, enc );
01496 }
01497 
01498 
01499 inline
01500 const sc_fxval
01501 sc_fxval::quantization( const scfx_params& params, bool& q_flag ) const
01502 {
01503     return sc_fxval( sc_dt::quantization_scfx_rep( *m_rep, params, q_flag ) );
01504 }
01505 
01506 inline
01507 const sc_fxval
01508 sc_fxval::overflow( const scfx_params& params, bool& o_flag ) const
01509 {
01510     return sc_fxval( sc_dt::overflow_scfx_rep( *m_rep, params, o_flag ) );
01511 }
01512 
01513 
01514 inline
01515 ::std::ostream&
01516 operator << ( ::std::ostream& os, const sc_fxval& a )
01517 {
01518     a.print( os );
01519     return os;
01520 }
01521 
01522 inline
01523 ::std::istream&
01524 operator >> ( ::std::istream& is, sc_fxval& a )
01525 {
01526     a.scan( is );
01527     return is;
01528 }
01529 
01530 
01531 // ----------------------------------------------------------------------------
01532 //  CLASS : sc_fxval_fast
01533 //
01534 //  Fixed-point value type; limited precision.
01535 // ----------------------------------------------------------------------------
01536 
01537 // protected method
01538 
01539 inline
01540 sc_fxval_fast_observer*
01541 sc_fxval_fast::observer() const
01542 {
01543     return m_observer;
01544 }
01545 
01546 
01547 // public constructors
01548 
01549 inline
01550 sc_fxval_fast::sc_fxval_fast( sc_fxval_fast_observer* observer_ )
01551 : m_val( 0.0 ),
01552   m_observer( observer_ )
01553 {
01554     SC_FXVAL_FAST_OBSERVER_DEFAULT_
01555     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
01556 }
01557 
01558 inline
01559 sc_fxval_fast::sc_fxval_fast( const sc_fxval_fast& a,
01560                   sc_fxval_fast_observer* observer_ )
01561 : m_val( a.m_val ),
01562   m_observer( observer_ )
01563 {
01564     SC_FXVAL_FAST_OBSERVER_DEFAULT_
01565     SC_FXVAL_FAST_OBSERVER_READ_( a )
01566     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
01567     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
01568 }
01569 
01570 #define DEFN_CTOR_T(tp,arg)                                                   \
01571 inline                                                                        \
01572 sc_fxval_fast::sc_fxval_fast( tp a,                                           \
01573                               sc_fxval_fast_observer* observer_ )             \
01574 : m_val( arg ),                                                               \
01575   m_observer( observer_ )                                                     \
01576 {                                                                             \
01577     SC_FXVAL_FAST_OBSERVER_DEFAULT_                                           \
01578     SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )                                \
01579     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
01580 }
01581 
01582 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
01583 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,from_string( a ))
01584 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
01585 
01586 DEFN_CTOR_T_A(int)
01587 DEFN_CTOR_T_A(unsigned int)
01588 DEFN_CTOR_T_A(long)
01589 DEFN_CTOR_T_A(unsigned long)
01590 DEFN_CTOR_T_A(double)
01591 DEFN_CTOR_T_B(const char*)
01592 DEFN_CTOR_T_C(const sc_fxval&)
01593 #ifndef SC_FX_EXCLUDE_OTHER
01594 DEFN_CTOR_T_A(int64)
01595 DEFN_CTOR_T_A(uint64)
01596 DEFN_CTOR_T_C(const sc_int_base&)
01597 DEFN_CTOR_T_C(const sc_uint_base&)
01598 DEFN_CTOR_T_C(const sc_signed&)
01599 DEFN_CTOR_T_C(const sc_unsigned&)
01600 #endif
01601 
01602 #undef DEFN_CTOR_T
01603 #undef DEFN_CTOR_T_A
01604 #undef DEFN_CTOR_T_B
01605 #undef DEFN_CTOR_T_C
01606 #undef DEFN_CTOR_T_D
01607 #undef DEFN_CTOR_T_E
01608 
01609 
01610 inline
01611 sc_fxval_fast::~sc_fxval_fast()
01612 {
01613     SC_FXVAL_FAST_OBSERVER_DESTRUCT_( *this )
01614 }
01615 
01616 
01617 // internal use only;
01618 inline
01619 double
01620 sc_fxval_fast::get_val() const
01621 {
01622     SC_FXVAL_FAST_OBSERVER_READ_( *this )
01623     return m_val;
01624 }
01625 
01626 // internal use only;
01627 inline
01628 void
01629 sc_fxval_fast::set_val( double val_ )
01630 {
01631     m_val = val_;
01632     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
01633 }
01634 
01635 
01636 // unary operators
01637 
01638 inline
01639 const sc_fxval_fast
01640 sc_fxval_fast::operator - () const
01641 {
01642     SC_FXVAL_FAST_OBSERVER_READ_( *this )
01643     return sc_fxval_fast( - m_val );
01644 }
01645 
01646 inline
01647 const sc_fxval_fast&
01648 sc_fxval_fast::operator + () const
01649 {
01650     // SC_FXVAL_FAST_OBSERVER_READ_( *this )
01651     return *this;
01652 }
01653 
01654 
01655 // unary functions
01656 
01657 inline
01658 void
01659 neg( sc_fxval_fast& c, const sc_fxval_fast& a )
01660 {
01661     SC_FXVAL_FAST_OBSERVER_READ_( a )
01662     c.m_val = - a.m_val;
01663     SC_FXVAL_FAST_OBSERVER_WRITE_( c )
01664 }
01665 
01666 
01667 // binary operators
01668 
01669 #define DEFN_BIN_OP_T(op,tp)                                                  \
01670 inline                                                                        \
01671 const sc_fxval_fast                                                           \
01672 operator op ( const sc_fxval_fast& a, tp b )                                  \
01673 {                                                                             \
01674     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01675     sc_fxval_fast tmp( b );                                                   \
01676     return sc_fxval_fast( a.m_val op tmp.m_val );                             \
01677 }                                                                             \
01678                                                                               \
01679 inline                                                                        \
01680 const sc_fxval_fast                                                           \
01681 operator op ( tp a, const sc_fxval_fast& b )                                  \
01682 {                                                                             \
01683     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01684     sc_fxval_fast tmp( a );                                                   \
01685     return sc_fxval_fast( tmp.m_val op b.m_val );                             \
01686 }
01687 
01688 #ifndef SC_FX_EXCLUDE_OTHER
01689 #define DEFN_BIN_OP_OTHER(op)                                                 \
01690 DEFN_BIN_OP_T(op,int64)                                                       \
01691 DEFN_BIN_OP_T(op,uint64)                                                      \
01692 DEFN_BIN_OP_T(op,const sc_int_base&)                                          \
01693 DEFN_BIN_OP_T(op,const sc_uint_base&)                                         \
01694 DEFN_BIN_OP_T(op,const sc_signed&)                                            \
01695 DEFN_BIN_OP_T(op,const sc_unsigned&)
01696 #else
01697 #define DEFN_BIN_OP_OTHER(op)
01698 #endif
01699 
01700 #define DEFN_BIN_OP(op,dummy)                                                 \
01701 inline                                                                        \
01702 const sc_fxval_fast                                                           \
01703 operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b )                \
01704 {                                                                             \
01705     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01706     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01707     return sc_fxval_fast( a.m_val op b.m_val );                               \
01708 }                                                                             \
01709                                                                               \
01710 DEFN_BIN_OP_T(op,int)                                                         \
01711 DEFN_BIN_OP_T(op,unsigned int)                                                \
01712 DEFN_BIN_OP_T(op,long)                                                        \
01713 DEFN_BIN_OP_T(op,unsigned long)                                               \
01714 DEFN_BIN_OP_T(op,double)                                                      \
01715 DEFN_BIN_OP_T(op,const char*)                                                 \
01716 DEFN_BIN_OP_OTHER(op)
01717 
01718 DEFN_BIN_OP(*,mult)
01719 DEFN_BIN_OP(+,add)
01720 DEFN_BIN_OP(-,sub)
01721 //DEFN_BIN_OP(/,div)
01722 inline
01723 const sc_fxval_fast
01724 operator / ( const sc_fxval_fast& a, const sc_fxval_fast& b )
01725 {
01726     SC_FXVAL_FAST_OBSERVER_READ_( a )
01727     SC_FXVAL_FAST_OBSERVER_READ_( b )
01728     return sc_fxval_fast( a.m_val / b.m_val );
01729 }
01730 
01731 DEFN_BIN_OP_T(/,int)
01732 DEFN_BIN_OP_T(/,unsigned int)
01733 DEFN_BIN_OP_T(/,long)
01734 DEFN_BIN_OP_T(/,unsigned long)
01735 DEFN_BIN_OP_T(/,double)
01736 DEFN_BIN_OP_T(/,const char*)
01737 //DEFN_BIN_OP_OTHER(/)
01738 #ifndef SC_FX_EXCLUDE_OTHER
01739 DEFN_BIN_OP_T(/,int64)
01740 DEFN_BIN_OP_T(/,uint64)
01741 DEFN_BIN_OP_T(/,const sc_int_base&)
01742 DEFN_BIN_OP_T(/,const sc_uint_base&)
01743 DEFN_BIN_OP_T(/,const sc_signed&)
01744 DEFN_BIN_OP_T(/,const sc_unsigned&)
01745 #endif
01746 
01747 
01748 #undef DEFN_BIN_OP_T
01749 #undef DEFN_BIN_OP_OTHER
01750 #undef DEFN_BIN_OP
01751 
01752 
01753 inline
01754 const sc_fxval_fast
01755 operator << ( const sc_fxval_fast& a, int b )
01756 {
01757     SC_FXVAL_FAST_OBSERVER_READ_( a )
01758     return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
01759 }
01760 
01761 inline
01762 const sc_fxval_fast
01763 operator >> ( const sc_fxval_fast& a, int b )
01764 {
01765     SC_FXVAL_FAST_OBSERVER_READ_( a )
01766     return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
01767 }
01768 
01769 
01770 // binary functions
01771 
01772 #define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
01773 inline                                                                        \
01774 void                                                                          \
01775 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b )                        \
01776 {                                                                             \
01777     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01778     sc_fxval_fast tmp( b );                                                   \
01779     c.m_val = a.m_val op tmp.m_val;                                           \
01780     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
01781 }                                                                             \
01782                                                                               \
01783 inline                                                                        \
01784 void                                                                          \
01785 fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b )                        \
01786 {                                                                             \
01787     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01788     sc_fxval_fast tmp( a );                                                   \
01789     c.m_val = tmp.m_val op b.m_val;                                           \
01790     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
01791 }
01792 
01793 #ifndef SC_FX_EXCLUDE_OTHER
01794 #define DEFN_BIN_FNC_OTHER(fnc,op)                                            \
01795 DEFN_BIN_FNC_T(fnc,op,int64)                                                  \
01796 DEFN_BIN_FNC_T(fnc,op,uint64)                                                 \
01797 DEFN_BIN_FNC_T(fnc,op,const sc_int_base&)                                     \
01798 DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&)                                    \
01799 DEFN_BIN_FNC_T(fnc,op,const sc_signed&)                                       \
01800 DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
01801 #else
01802 #define DEFN_BIN_FNC_OTHER(fnc,op)
01803 #endif
01804 
01805 #define DEFN_BIN_FNC(fnc,op)                                                  \
01806 inline                                                                        \
01807 void                                                                          \
01808 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxval_fast& b )      \
01809 {                                                                             \
01810     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01811     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01812     c.m_val = a.m_val op b.m_val;                                             \
01813     SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
01814 }                                                                             \
01815                                                                               \
01816 DEFN_BIN_FNC_T(fnc,op,int)                                                    \
01817 DEFN_BIN_FNC_T(fnc,op,unsigned int)                                           \
01818 DEFN_BIN_FNC_T(fnc,op,long)                                                   \
01819 DEFN_BIN_FNC_T(fnc,op,unsigned long)                                          \
01820 DEFN_BIN_FNC_T(fnc,op,double)                                                 \
01821 DEFN_BIN_FNC_T(fnc,op,const char*)                                            \
01822 DEFN_BIN_FNC_OTHER(fnc,op)
01823 
01824 DEFN_BIN_FNC(mult,*)
01825 DEFN_BIN_FNC(div,/)
01826 DEFN_BIN_FNC(add,+)
01827 DEFN_BIN_FNC(sub,-)
01828 
01829 #undef DEFN_BIN_FNC_T
01830 #undef DEFN_BIN_FNC_OTHER
01831 #undef DEFN_BIN_FNC
01832 
01833 
01834 inline
01835 void
01836 lshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b )
01837 {
01838     SC_FXVAL_FAST_OBSERVER_READ_( a )
01839     c.m_val = a.m_val * scfx_pow2( b );
01840     SC_FXVAL_FAST_OBSERVER_WRITE_( c )
01841 }
01842 
01843 inline
01844 void
01845 rshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b )
01846 {
01847     SC_FXVAL_FAST_OBSERVER_READ_( a )
01848     c.m_val = a.m_val * scfx_pow2( -b );
01849     SC_FXVAL_FAST_OBSERVER_WRITE_( c )
01850 }
01851 
01852 
01853 // relational (including equality) operators
01854 
01855 #define DEFN_REL_OP_T(op,tp)                                                  \
01856 inline                                                                        \
01857 bool                                                                          \
01858 operator op ( const sc_fxval_fast& a, tp b )                                  \
01859 {                                                                             \
01860     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01861     sc_fxval_fast tmp( b );                                                   \
01862     return ( a.m_val op tmp.m_val );                                          \
01863 }                                                                             \
01864                                                                               \
01865 inline                                                                        \
01866 bool                                                                          \
01867 operator op ( tp a, const sc_fxval_fast& b )                                  \
01868 {                                                                             \
01869     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01870     sc_fxval_fast tmp( a );                                                   \
01871     return ( tmp.m_val op b.m_val );                                          \
01872 }
01873 
01874 #ifndef SC_FX_EXCLUDE_OTHER
01875 #define DEFN_REL_OP_OTHER(op)                                                 \
01876 DEFN_REL_OP_T(op,int64)                                                       \
01877 DEFN_REL_OP_T(op,uint64)                                                      \
01878 DEFN_REL_OP_T(op,const sc_int_base&)                                          \
01879 DEFN_REL_OP_T(op,const sc_uint_base&)                                         \
01880 DEFN_REL_OP_T(op,const sc_signed&)                                            \
01881 DEFN_REL_OP_T(op,const sc_unsigned&)
01882 #else
01883 #define DEFN_REL_OP_OTHER(op)
01884 #endif
01885 
01886 #define DEFN_REL_OP(op)                                                       \
01887 inline                                                                        \
01888 bool                                                                          \
01889 operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b )                \
01890 {                                                                             \
01891     SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
01892     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01893     return ( a.m_val op b.m_val );                                            \
01894 }                                                                             \
01895                                                                               \
01896 DEFN_REL_OP_T(op,int)                                                         \
01897 DEFN_REL_OP_T(op,unsigned int)                                                \
01898 DEFN_REL_OP_T(op,long)                                                        \
01899 DEFN_REL_OP_T(op,unsigned long)                                               \
01900 DEFN_REL_OP_T(op,double)                                                      \
01901 DEFN_REL_OP_T(op,const char*)                                                 \
01902 DEFN_REL_OP_OTHER(op)
01903 
01904 DEFN_REL_OP(<)
01905 DEFN_REL_OP(<=)
01906 DEFN_REL_OP(>)
01907 DEFN_REL_OP(>=)
01908 DEFN_REL_OP(==)
01909 DEFN_REL_OP(!=)
01910 
01911 #undef DEFN_REL_OP_T
01912 #undef DEFN_REL_OP_OTHER
01913 #undef DEFN_REL_OP
01914 
01915 
01916 // assignment operators
01917 
01918 inline
01919 sc_fxval_fast&
01920 sc_fxval_fast::operator = ( const sc_fxval_fast& a )
01921 {
01922     if( &a != this )
01923     {
01924     SC_FXVAL_FAST_OBSERVER_READ_( a )
01925     m_val = a.m_val;
01926     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
01927     }
01928     return *this;
01929 }
01930 
01931 #define DEFN_ASN_OP_T(tp)                                                     \
01932 inline                                                                        \
01933 sc_fxval_fast&                                                                \
01934 sc_fxval_fast::operator = ( tp a )                                            \
01935 {                                                                             \
01936     sc_fxval_fast tmp( a );                                                   \
01937     m_val = tmp.m_val;                                                        \
01938     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
01939     return *this;                                                             \
01940 }
01941 
01942 DEFN_ASN_OP_T(int)
01943 DEFN_ASN_OP_T(unsigned int)
01944 DEFN_ASN_OP_T(long)
01945 DEFN_ASN_OP_T(unsigned long)
01946 DEFN_ASN_OP_T(double)
01947 DEFN_ASN_OP_T(const char*)
01948 DEFN_ASN_OP_T(const sc_fxval&)
01949 #ifndef SC_FX_EXCLUDE_OTHER
01950 DEFN_ASN_OP_T(int64)
01951 DEFN_ASN_OP_T(uint64)
01952 DEFN_ASN_OP_T(const sc_int_base&)
01953 DEFN_ASN_OP_T(const sc_uint_base&)
01954 DEFN_ASN_OP_T(const sc_signed&)
01955 DEFN_ASN_OP_T(const sc_unsigned&)
01956 #endif
01957 
01958 #undef DEFN_ASN_OP_T
01959 
01960 
01961 #define DEFN_ASN_OP_T(op,tp)                                                  \
01962 inline                                                                        \
01963 sc_fxval_fast&                                                                \
01964 sc_fxval_fast::operator op ( tp b )                                           \
01965 {                                                                             \
01966     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
01967     sc_fxval_fast tmp( b );                                                   \
01968     m_val op tmp.m_val;                                                       \
01969     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
01970     return *this;                                                             \
01971 }
01972 
01973 #ifndef SC_FX_EXCLUDE_OTHER
01974 #define DEFN_ASN_OP_OTHER(op)                                                 \
01975 DEFN_ASN_OP_T(op,int64)                                                       \
01976 DEFN_ASN_OP_T(op,uint64)                                                      \
01977 DEFN_ASN_OP_T(op,const sc_int_base&)                                          \
01978 DEFN_ASN_OP_T(op,const sc_uint_base&)                                         \
01979 DEFN_ASN_OP_T(op,const sc_signed&)                                            \
01980 DEFN_ASN_OP_T(op,const sc_unsigned&)
01981 #else
01982 #define DEFN_ASN_OP_OTHER(op)
01983 #endif
01984 
01985 #define DEFN_ASN_OP(op)                                                       \
01986 inline                                                                        \
01987 sc_fxval_fast&                                                                \
01988 sc_fxval_fast::operator op ( const sc_fxval_fast& b )                         \
01989 {                                                                             \
01990     SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
01991     SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
01992     m_val op b.m_val;                                                         \
01993     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
01994     return *this;                                                             \
01995 }                                                                             \
01996                                                                               \
01997 DEFN_ASN_OP_T(op,int)                                                         \
01998 DEFN_ASN_OP_T(op,unsigned int)                                                \
01999 DEFN_ASN_OP_T(op,long)                                                        \
02000 DEFN_ASN_OP_T(op,unsigned long)                                               \
02001 DEFN_ASN_OP_T(op,double)                                                      \
02002 DEFN_ASN_OP_T(op,const char*)                                                 \
02003 DEFN_ASN_OP_T(op,const sc_fxval&)                                             \
02004 DEFN_ASN_OP_OTHER(op)
02005 
02006 DEFN_ASN_OP(*=)
02007 DEFN_ASN_OP(/=)
02008 DEFN_ASN_OP(+=)
02009 DEFN_ASN_OP(-=)
02010 
02011 #undef DEFN_ASN_OP_T
02012 #undef DEFN_ASN_OP_OTHER
02013 #undef DEFN_ASN_OP
02014 
02015 
02016 inline
02017 sc_fxval_fast&
02018 sc_fxval_fast::operator <<= ( int b )
02019 {
02020     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02021     m_val *= scfx_pow2( b );
02022     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02023     return *this;
02024 }
02025 
02026 inline
02027 sc_fxval_fast&
02028 sc_fxval_fast::operator >>= ( int b )
02029 {
02030     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02031     m_val *= scfx_pow2( -b );
02032     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02033     return *this;
02034 }
02035 
02036 
02037 // auto-increment and auto-decrement
02038 
02039 inline
02040 const sc_fxval_fast
02041 sc_fxval_fast::operator ++ ( int )
02042 {
02043     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02044     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02045     double c = m_val;
02046     m_val = m_val + 1;
02047     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02048     return sc_fxval_fast( c );
02049 }
02050 
02051 inline
02052 const sc_fxval_fast
02053 sc_fxval_fast::operator -- ( int )
02054 {
02055     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02056     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02057     double c = m_val;
02058     m_val = m_val - 1;
02059     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02060     return sc_fxval_fast( c );
02061 }
02062 
02063 inline
02064 sc_fxval_fast&
02065 sc_fxval_fast::operator ++ ()
02066 {
02067     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02068     m_val = m_val + 1;
02069     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02070     return *this;
02071 }
02072 
02073 inline
02074 sc_fxval_fast&
02075 sc_fxval_fast::operator -- ()
02076 {
02077     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02078     m_val = m_val - 1;
02079     SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
02080     return *this;
02081 }
02082 
02083 
02084 // implicit conversion
02085 
02086 inline
02087 sc_fxval_fast::operator double() const
02088 {
02089     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02090     return m_val;
02091 }
02092 
02093 
02094 // explicit conversion to primitive types
02095 
02096 inline
02097 short
02098 sc_fxval_fast::to_short() const
02099 {
02100     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02101     return static_cast<short>( m_val );
02102 }
02103 
02104 inline
02105 unsigned short
02106 sc_fxval_fast::to_ushort() const
02107 {
02108     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02109     return static_cast<unsigned short>( m_val );
02110 }
02111 
02112 inline
02113 int64
02114 sc_fxval_fast::to_int64() const
02115 {
02116     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02117     return static_cast<int64>( m_val );
02118 }
02119 
02120 inline
02121 int
02122 sc_fxval_fast::to_int() const
02123 {
02124     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02125     return static_cast<int>( m_val );
02126 }
02127 
02128 inline
02129 unsigned int
02130 sc_fxval_fast::to_uint() const
02131 {
02132     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02133     return static_cast<unsigned int>( m_val );
02134 }
02135 
02136 inline
02137 uint64
02138 sc_fxval_fast::to_uint64() const
02139 {
02140     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02141     return static_cast<uint64>( m_val );
02142 }
02143 
02144 inline
02145 long
02146 sc_fxval_fast::to_long() const
02147 {
02148     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02149     return static_cast<long>( m_val );
02150 }
02151 
02152 inline
02153 unsigned long
02154 sc_fxval_fast::to_ulong() const
02155 {
02156     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02157     return static_cast<unsigned long>( m_val );
02158 }
02159 
02160 inline
02161 float
02162 sc_fxval_fast::to_float() const
02163 {
02164     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02165     return static_cast<float>( m_val );
02166 }
02167 
02168 inline
02169 double
02170 sc_fxval_fast::to_double() const
02171 {
02172     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02173     return m_val;
02174 }
02175 
02176 
02177 // query value
02178 
02179 inline
02180 bool
02181 sc_fxval_fast::is_neg() const
02182 {
02183     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02184     scfx_ieee_double id( m_val );
02185     return ( id.negative() != 0 );
02186 }
02187 
02188 inline
02189 bool
02190 sc_fxval_fast::is_zero() const
02191 {
02192     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02193     scfx_ieee_double id( m_val );
02194     return id.is_zero();
02195 }
02196 
02197 inline
02198 bool
02199 sc_fxval_fast::is_nan() const
02200 {
02201     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02202     scfx_ieee_double id( m_val );
02203     return id.is_nan();
02204 }
02205 
02206 inline
02207 bool
02208 sc_fxval_fast::is_inf() const
02209 {
02210     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02211     scfx_ieee_double id( m_val );
02212     return id.is_inf();
02213 }
02214 
02215 inline
02216 bool
02217 sc_fxval_fast::is_normal() const
02218 {
02219     SC_FXVAL_FAST_OBSERVER_READ_( *this )
02220     scfx_ieee_double id( m_val );
02221     return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
02222 }
02223 
02224 
02225 inline
02226 bool
02227 sc_fxval_fast::rounding_flag() const
02228 {
02229     // does not apply to sc_fxval_fast; included for API compatibility
02230     return false;
02231 }
02232 
02233 
02234 inline
02235 ::std::ostream&
02236 operator << ( ::std::ostream& os, const sc_fxval_fast& a )
02237 {
02238     a.print( os );
02239     return os;
02240 }
02241 
02242 inline
02243 ::std::istream&
02244 operator >> ( ::std::istream& is, sc_fxval_fast& a )
02245 {
02246     a.scan( is );
02247     return is;
02248 }
02249 
02250 } // namespace sc_dt
02251 
02252 
02253 #endif
02254 
02255 // Taf!

Generated on Wed Jan 21 15:32:08 2009 for SystemC by  doxygen 1.5.5