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