SystemC  Recoding Infrastructure for SystemC v0.6.0 derived from Accellera SystemC 2.3.1
Accellera SystemC proof-of-concept library
sc_fxval.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_fxval.h -
21 
22  Original Author: Martin Janssen, Synopsys, Inc.
23 
24  *****************************************************************************/
25 
26 /*****************************************************************************
27 
28  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
29  changes you are making here.
30 
31  Name, Affiliation, Date:
32  Description of Modification:
33 
34  *****************************************************************************/
35 
36 // $Log: sc_fxval.h,v $
37 // Revision 1.3 2011/01/19 18:57:40 acg
38 // Andy Goodrich: changes for IEEE_1666_2011.
39 //
40 // Revision 1.2 2010/12/07 20:09:08 acg
41 // Andy Goodrich: Philipp Hartmann's constructor disambiguation fix
42 //
43 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
44 // SystemC 2.3
45 //
46 // Revision 1.3 2006/01/13 18:53:58 acg
47 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
48 // the source.
49 //
50 
51 #ifndef SC_FXVAL_H
52 #define SC_FXVAL_H
53 
54 
56 #ifndef SC_FX_EXCLUDE_OTHER
61 #endif
63 
64 #ifdef SC_FXVAL_IMPLICIT_CONV
65 # define SCFX_EXPLICIT_ // nothing
66 #else
67 # define SCFX_EXPLICIT_ explicit
68 #endif
69 #ifdef SC_FXVAL_IMPLICIT_OTHER
70 # define SCFX_EXPLICIT_OTHER_
71 #else
72 # define SCFX_EXPLICIT_OTHER_ explicit
73 #endif
74 
75 namespace sc_dt
76 {
77 
78 // classes defined in this module
79 class sc_fxval;
80 class sc_fxval_fast;
81 
82 // forward class declarations
83 class sc_fxnum;
84 class sc_fxnum_fast;
85 
86 
87 // ----------------------------------------------------------------------------
88 // CLASS : sc_fxval
89 //
90 // Fixed-point value type; arbitrary precision.
91 // ----------------------------------------------------------------------------
92 
93 class sc_fxval
94 {
95 
96  friend class sc_fxnum;
97 
98 protected:
99 
100  sc_fxval_observer* observer() const;
101 
102 public:
103 
104  // internal use only;
105  explicit sc_fxval( scfx_rep* );
106 
107 
108  explicit sc_fxval( sc_fxval_observer* = 0 );
110  SCFX_EXPLICIT_ sc_fxval( unsigned int, sc_fxval_observer* = 0 );
112  SCFX_EXPLICIT_ sc_fxval( unsigned long, sc_fxval_observer* = 0 );
114  SCFX_EXPLICIT_ sc_fxval( double, sc_fxval_observer* = 0 );
115  SCFX_EXPLICIT_ sc_fxval( const char*, sc_fxval_observer* = 0 );
116  sc_fxval( const sc_fxval&, sc_fxval_observer* = 0 );
117  sc_fxval( const sc_fxval_fast&, sc_fxval_observer* = 0 );
118  sc_fxval( const sc_fxnum&, sc_fxval_observer* = 0 );
119  sc_fxval( const sc_fxnum_fast&, sc_fxval_observer* = 0 );
120 #ifndef SC_FX_EXCLUDE_OTHER
127 #endif
128 
129  ~sc_fxval();
130 
131 
132  // internal use only;
133  const scfx_rep* get_rep() const;
134  void set_rep( scfx_rep* );
135 
136 
137  // unary operators
138 
139  const sc_fxval operator - () const;
140  const sc_fxval& operator + () const;
141 
142 
143  // unary functions
144 
145  friend void neg( sc_fxval&, const sc_fxval& );
146 
147 
148  // binary operators
149 
150 #define DECL_BIN_OP_T(op,tp) \
151  friend const sc_fxval operator op ( const sc_fxval&, tp ); \
152  friend const sc_fxval operator op ( tp, const sc_fxval& );
153 
154 #ifndef SC_FX_EXCLUDE_OTHER
155 #define DECL_BIN_OP_OTHER(op) \
156  DECL_BIN_OP_T(op,int64) \
157  DECL_BIN_OP_T(op,uint64) \
158  DECL_BIN_OP_T(op,const sc_int_base&) \
159  DECL_BIN_OP_T(op,const sc_uint_base&) \
160  DECL_BIN_OP_T(op,const sc_signed&) \
161  DECL_BIN_OP_T(op,const sc_unsigned&)
162 #else
163 #define DECL_BIN_OP_OTHER(op)
164 #endif
165 
166 #define DECL_BIN_OP(op,dummy) \
167  friend const sc_fxval operator op ( const sc_fxval&, const sc_fxval& ); \
168  DECL_BIN_OP_T(op,int) \
169  DECL_BIN_OP_T(op,unsigned int) \
170  DECL_BIN_OP_T(op,long) \
171  DECL_BIN_OP_T(op,unsigned long) \
172  DECL_BIN_OP_T(op,float) \
173  DECL_BIN_OP_T(op,double) \
174  DECL_BIN_OP_T(op,const char*) \
175  DECL_BIN_OP_T(op,const sc_fxval_fast&) \
176  DECL_BIN_OP_T(op,const sc_fxnum_fast&) \
177  DECL_BIN_OP_OTHER(op)
178 
179  DECL_BIN_OP(*,mult)
180  DECL_BIN_OP(+,add)
181  DECL_BIN_OP(-,sub)
182 // declaration below doesn't compile with BCB5 (E2206)
183 // DECL_BIN_OP(/,div)
184 // previous macro expanded
185  friend const sc_fxval operator / ( const sc_fxval&, const sc_fxval& );
186  DECL_BIN_OP_T(/,int)
187  DECL_BIN_OP_T(/,unsigned int)
188  DECL_BIN_OP_T(/,long)
189  DECL_BIN_OP_T(/,unsigned long)
190  DECL_BIN_OP_T(/,float)
191  DECL_BIN_OP_T(/,double)
192  DECL_BIN_OP_T(/,const char*)
193  DECL_BIN_OP_T(/,const sc_fxval_fast&)
194  DECL_BIN_OP_T(/,const sc_fxnum_fast&)
195 // DECL_BIN_OP_OTHER(/)
196 #ifndef SC_FX_EXCLUDE_OTHER
199  DECL_BIN_OP_T(/,const sc_int_base&) \
200  DECL_BIN_OP_T(/,const sc_uint_base&) \
201  DECL_BIN_OP_T(/,const sc_signed&) \
202  DECL_BIN_OP_T(/,const sc_unsigned&)
203 #endif
204 
205 
206 #undef DECL_BIN_OP_T
207 #undef DECL_BIN_OP_OTHER
208 #undef DECL_BIN_OP
209 
210  friend const sc_fxval operator << ( const sc_fxval&, int );
211  friend const sc_fxval operator >> ( const sc_fxval&, int );
212 
213 
214  // binary functions
215 
216 #define DECL_BIN_FNC_T(fnc,tp) \
217  friend void fnc ( sc_fxval&, const sc_fxval&, tp ); \
218  friend void fnc ( sc_fxval&, tp, const sc_fxval& );
219 
220 #ifndef SC_FX_EXCLUDE_OTHER
221 #define DECL_BIN_FNC_OTHER(fnc) \
222  DECL_BIN_FNC_T(fnc,int64) \
223  DECL_BIN_FNC_T(fnc,uint64) \
224  DECL_BIN_FNC_T(fnc,const sc_int_base&) \
225  DECL_BIN_FNC_T(fnc,const sc_uint_base&) \
226  DECL_BIN_FNC_T(fnc,const sc_signed&) \
227  DECL_BIN_FNC_T(fnc,const sc_unsigned&)
228 #else
229 #define DECL_BIN_FNC_OTHER(fnc)
230 #endif
231 
232 #define DECL_BIN_FNC(fnc) \
233  friend void fnc ( sc_fxval&, const sc_fxval&, const sc_fxval& ); \
234  DECL_BIN_FNC_T(fnc,int) \
235  DECL_BIN_FNC_T(fnc,unsigned int) \
236  DECL_BIN_FNC_T(fnc,long) \
237  DECL_BIN_FNC_T(fnc,unsigned long) \
238  DECL_BIN_FNC_T(fnc,float) \
239  DECL_BIN_FNC_T(fnc,double) \
240  DECL_BIN_FNC_T(fnc,const char*) \
241  DECL_BIN_FNC_T(fnc,const sc_fxval_fast&) \
242  DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&) \
243  DECL_BIN_FNC_OTHER(fnc)
244 
245  DECL_BIN_FNC(mult)
247  DECL_BIN_FNC(add)
248  DECL_BIN_FNC(sub)
249 
250 #undef DECL_BIN_FNC_T
251 #undef DECL_BIN_FNC_OTHER
252 #undef DECL_BIN_FNC
253 
254  friend void lshift( sc_fxval&, const sc_fxval&, int );
255  friend void rshift( sc_fxval&, const sc_fxval&, int );
256 
257 
258  // relational (including equality) operators
259 
260 #define DECL_REL_OP_T(op,tp) \
261  friend bool operator op ( const sc_fxval&, tp ); \
262  friend bool operator op ( tp, const sc_fxval& );
263 
264 #ifndef SC_FX_EXCLUDE_OTHER
265 #define DECL_REL_OP_OTHER(op) \
266  DECL_REL_OP_T(op,int64) \
267  DECL_REL_OP_T(op,uint64) \
268  DECL_REL_OP_T(op,const sc_int_base&) \
269  DECL_REL_OP_T(op,const sc_uint_base&) \
270  DECL_REL_OP_T(op,const sc_signed&) \
271  DECL_REL_OP_T(op,const sc_unsigned&)
272 #else
273 #define DECL_REL_OP_OTHER(op)
274 #endif
275 
276 #define DECL_REL_OP(op) \
277  friend bool operator op ( const sc_fxval&, const sc_fxval& ); \
278  DECL_REL_OP_T(op,int) \
279  DECL_REL_OP_T(op,unsigned int) \
280  DECL_REL_OP_T(op,long) \
281  DECL_REL_OP_T(op,unsigned long) \
282  DECL_REL_OP_T(op,float) \
283  DECL_REL_OP_T(op,double) \
284  DECL_REL_OP_T(op,const char*) \
285  DECL_REL_OP_T(op,const sc_fxval_fast&) \
286  DECL_REL_OP_T(op,const sc_fxnum_fast&) \
287  DECL_REL_OP_OTHER(op)
288 
289  DECL_REL_OP(<)
290  DECL_REL_OP(<=)
291  DECL_REL_OP(>)
292  DECL_REL_OP(>=)
293  DECL_REL_OP(==)
294  DECL_REL_OP(!=)
295 
296 #undef DECL_REL_OP_T
297 #undef DECL_REL_OP_OTHER
298 #undef DECL_REL_OP
299 
300 
301  // assignment operators
302 
303 #define DECL_ASN_OP_T(op,tp) \
304  sc_fxval& operator op( tp );
305 
306 #ifndef SC_FX_EXCLUDE_OTHER
307 #define DECL_ASN_OP_OTHER(op) \
308  DECL_ASN_OP_T(op,int64) \
309  DECL_ASN_OP_T(op,uint64) \
310  DECL_ASN_OP_T(op,const sc_int_base&) \
311  DECL_ASN_OP_T(op,const sc_uint_base&) \
312  DECL_ASN_OP_T(op,const sc_signed&) \
313  DECL_ASN_OP_T(op,const sc_unsigned&)
314 #else
315 #define DECL_ASN_OP_OTHER(op)
316 #endif
317 
318 #define DECL_ASN_OP(op) \
319  DECL_ASN_OP_T(op,int) \
320  DECL_ASN_OP_T(op,unsigned int) \
321  DECL_ASN_OP_T(op,long) \
322  DECL_ASN_OP_T(op,unsigned long) \
323  DECL_ASN_OP_T(op,float) \
324  DECL_ASN_OP_T(op,double) \
325  DECL_ASN_OP_T(op,const char*) \
326  DECL_ASN_OP_T(op,const sc_fxval&) \
327  DECL_ASN_OP_T(op,const sc_fxval_fast&) \
328  DECL_ASN_OP_T(op,const sc_fxnum&) \
329  DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
330  DECL_ASN_OP_OTHER(op)
331 
332  DECL_ASN_OP(=)
333 
334  DECL_ASN_OP(*=)
335  DECL_ASN_OP(/=)
336  DECL_ASN_OP(+=)
337  DECL_ASN_OP(-=)
338 
339  DECL_ASN_OP_T(<<=,int)
340  DECL_ASN_OP_T(>>=,int)
341 
342 #undef DECL_ASN_OP_T
343 #undef DECL_ASN_OP_OTHER
344 #undef DECL_ASN_OP
345 
346 
347  // auto-increment and auto-decrement
348 
349  const sc_fxval operator ++ ( int );
350  const sc_fxval operator -- ( int );
351 
352  sc_fxval& operator ++ ();
353  sc_fxval& operator -- ();
354 
355 
356  // implicit conversion
357 
358  operator double() const; // necessary evil!
359 
360 
361  // explicit conversion to primitive types
362 
363  short to_short() const;
364  unsigned short to_ushort() const;
365  int to_int() const;
366  unsigned int to_uint() const;
367  long to_long() const;
368  unsigned long to_ulong() const;
369  int64 to_int64() const;
370  uint64 to_uint64() const;
371  float to_float() const;
372  double to_double() const;
373 
374 
375  // explicit conversion to character string
376 
377  const std::string to_string() const;
378  const std::string to_string( sc_numrep ) const;
379  const std::string to_string( sc_numrep, bool ) const;
380  const std::string to_string( sc_fmt ) const;
381  const std::string to_string( sc_numrep, sc_fmt ) const;
382  const std::string to_string( sc_numrep, bool, sc_fmt ) const;
383 
384  const std::string to_dec() const;
385  const std::string to_bin() const;
386  const std::string to_oct() const;
387  const std::string to_hex() const;
388 
389 
390  // query value
391 
392  bool is_neg() const;
393  bool is_zero() const;
394  bool is_nan() const;
395  bool is_inf() const;
396  bool is_normal() const;
397 
398  bool rounding_flag() const;
399 
400 
401  // print or dump content
402 
403  void print( ::std::ostream& = ::std::cout ) const;
404  void scan( ::std::istream& = ::std::cin );
405  void dump( ::std::ostream& = ::std::cout ) const;
406 
407 
408  // internal use only;
409  bool get_bit( int ) const;
410 
411 protected:
412 
414  void unlock_observer( sc_fxval_observer* ) const;
415 
416 
417  void get_type( int&, int&, sc_enc& ) const;
418 
419  const sc_fxval quantization( const scfx_params&, bool& ) const;
420  const sc_fxval overflow( const scfx_params&, bool& ) const;
421 
422 private:
423 
424  scfx_rep* m_rep;
425 
426  mutable sc_fxval_observer* m_observer;
427 
428 };
429 
430 
431 // ----------------------------------------------------------------------------
432 // CLASS : sc_fxval_fast
433 //
434 // Fixed-point value type; limited precision.
435 // ----------------------------------------------------------------------------
436 
438 {
439 
440  friend class sc_fxnum_fast;
441 
442 protected:
443 
445 
446 public:
447 
448  explicit sc_fxval_fast( sc_fxval_fast_observer* = 0 );
452  SCFX_EXPLICIT_ sc_fxval_fast( unsigned long, sc_fxval_fast_observer* = 0 );
456  sc_fxval_fast( const sc_fxval&, sc_fxval_fast_observer* = 0 );
460 #ifndef SC_FX_EXCLUDE_OTHER
467 #endif
468 
469  ~sc_fxval_fast();
470 
471  // internal use only;
472  double get_val() const;
473  void set_val( double );
474 
475 
476  // unary operators
477 
478  const sc_fxval_fast operator - () const;
479  const sc_fxval_fast& operator + () const;
480 
481 
482  // unary functions
483 
484  friend void neg( sc_fxval_fast&, const sc_fxval_fast& );
485 
486 
487  // binary operators
488 
489 #define DECL_BIN_OP_T(op,tp) \
490  friend const sc_fxval_fast operator op ( const sc_fxval_fast&, tp ); \
491  friend const sc_fxval_fast operator op ( tp, const sc_fxval_fast& );
492 
493 #ifndef SC_FX_EXCLUDE_OTHER
494 #define DECL_BIN_OP_OTHER(op) \
495  DECL_BIN_OP_T(op,int64) \
496  DECL_BIN_OP_T(op,uint64) \
497  DECL_BIN_OP_T(op,const sc_int_base&) \
498  DECL_BIN_OP_T(op,const sc_uint_base&) \
499  DECL_BIN_OP_T(op,const sc_signed&) \
500  DECL_BIN_OP_T(op,const sc_unsigned&)
501 #else
502 #define DECL_BIN_OP_OTHER(op)
503 #endif
504 
505 #define DECL_BIN_OP(op,dummy) \
506  friend const sc_fxval_fast operator op ( const sc_fxval_fast&, \
507  const sc_fxval_fast& ); \
508  DECL_BIN_OP_T(op,int) \
509  DECL_BIN_OP_T(op,unsigned int) \
510  DECL_BIN_OP_T(op,long) \
511  DECL_BIN_OP_T(op,unsigned long) \
512  DECL_BIN_OP_T(op,float) \
513  DECL_BIN_OP_T(op,double) \
514  DECL_BIN_OP_T(op,const char*) \
515  DECL_BIN_OP_OTHER(op)
516 
517  DECL_BIN_OP(*,mult)
518  DECL_BIN_OP(+,add)
519  DECL_BIN_OP(-,sub)
520 // don't use macro
521 // DECL_BIN_OP(/,div)
522  friend const sc_fxval_fast operator / ( const sc_fxval_fast&,
523  const sc_fxval_fast& );
524  DECL_BIN_OP_T(/,int)
525  DECL_BIN_OP_T(/,unsigned int)
526  DECL_BIN_OP_T(/,long)
527  DECL_BIN_OP_T(/,unsigned long)
528  DECL_BIN_OP_T(/,float)
529  DECL_BIN_OP_T(/,double)
530  DECL_BIN_OP_T(/,const char*)
531 // DECL_BIN_OP_OTHER(/)
532 #ifndef SC_FX_EXCLUDE_OTHER
535  DECL_BIN_OP_T(/,const sc_int_base&) \
536  DECL_BIN_OP_T(/,const sc_uint_base&) \
537  DECL_BIN_OP_T(/,const sc_signed&) \
538  DECL_BIN_OP_T(/,const sc_unsigned&)
539 #endif
540 
541 #undef DECL_BIN_OP_T
542 #undef DECL_BIN_OP_OTHER
543 #undef DECL_BIN_OP
544 
545  friend const sc_fxval_fast operator << ( const sc_fxval_fast&, int );
546  friend const sc_fxval_fast operator >> ( const sc_fxval_fast&, int );
547 
548 
549  // binary functions
550 
551 #define DECL_BIN_FNC_T(fnc,tp) \
552  friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&, tp ); \
553  friend void fnc ( sc_fxval_fast&, tp, const sc_fxval_fast& );
554 
555 #ifndef SC_FX_EXCLUDE_OTHER
556 #define DECL_BIN_FNC_OTHER(fnc) \
557  DECL_BIN_FNC_T(fnc,int64) \
558  DECL_BIN_FNC_T(fnc,uint64) \
559  DECL_BIN_FNC_T(fnc,const sc_int_base&) \
560  DECL_BIN_FNC_T(fnc,const sc_uint_base&) \
561  DECL_BIN_FNC_T(fnc,const sc_signed&) \
562  DECL_BIN_FNC_T(fnc,const sc_unsigned&)
563 #else
564 #define DECL_BIN_FNC_OTHER(fnc)
565 #endif
566 
567 #define DECL_BIN_FNC(fnc) \
568  friend void fnc ( sc_fxval_fast&, const sc_fxval_fast&, \
569  const sc_fxval_fast& ); \
570  DECL_BIN_FNC_T(fnc,int) \
571  DECL_BIN_FNC_T(fnc,unsigned int) \
572  DECL_BIN_FNC_T(fnc,long) \
573  DECL_BIN_FNC_T(fnc,unsigned long) \
574  DECL_BIN_FNC_T(fnc,float) \
575  DECL_BIN_FNC_T(fnc,double) \
576  DECL_BIN_FNC_T(fnc,const char*) \
577  DECL_BIN_FNC_T(fnc,const sc_fxval&) \
578  DECL_BIN_FNC_T(fnc,const sc_fxnum&) \
579  DECL_BIN_FNC_OTHER(fnc)
580 
581  DECL_BIN_FNC(mult)
583  DECL_BIN_FNC(add)
584  DECL_BIN_FNC(sub)
585 
586 #undef DECL_BIN_FNC_T
587 #undef DECL_BIN_FNC_OTHER
588 #undef DECL_BIN_FNC
589 
590  friend void lshift( sc_fxval_fast&, const sc_fxval_fast&, int );
591  friend void rshift( sc_fxval_fast&, const sc_fxval_fast&, int );
592 
593 
594  // relational (including equality) operators
595 
596 #define DECL_REL_OP_T(op,tp) \
597  friend bool operator op ( const sc_fxval_fast&, tp ); \
598  friend bool operator op ( tp, const sc_fxval_fast& );
599 
600 #ifndef SC_FX_EXCLUDE_OTHER
601 #define DECL_REL_OP_OTHER(op) \
602  DECL_REL_OP_T(op,int64) \
603  DECL_REL_OP_T(op,uint64) \
604  DECL_REL_OP_T(op,const sc_int_base&) \
605  DECL_REL_OP_T(op,const sc_uint_base&) \
606  DECL_REL_OP_T(op,const sc_signed&) \
607  DECL_REL_OP_T(op,const sc_unsigned&)
608 #else
609 #define DECL_REL_OP_OTHER(op)
610 #endif
611 
612 #define DECL_REL_OP(op) \
613  friend bool operator op ( const sc_fxval_fast&, const sc_fxval_fast& ); \
614  DECL_REL_OP_T(op,int) \
615  DECL_REL_OP_T(op,unsigned int) \
616  DECL_REL_OP_T(op,long) \
617  DECL_REL_OP_T(op,unsigned long) \
618  DECL_REL_OP_T(op,float) \
619  DECL_REL_OP_T(op,double) \
620  DECL_REL_OP_T(op,const char*) \
621  DECL_REL_OP_OTHER(op)
622 
623  DECL_REL_OP(<)
624  DECL_REL_OP(<=)
625  DECL_REL_OP(>)
626  DECL_REL_OP(>=)
627  DECL_REL_OP(==)
628  DECL_REL_OP(!=)
629 
630 #undef DECL_REL_OP_T
631 #undef DECL_REL_OP_OTHER
632 #undef DECL_REL_OP
633 
634 
635  // assignment operators
636 
637 #define DECL_ASN_OP_T(op,tp) \
638  sc_fxval_fast& operator op( tp );
639 
640 #ifndef SC_FX_EXCLUDE_OTHER
641 #define DECL_ASN_OP_OTHER(op) \
642  DECL_ASN_OP_T(op,int64) \
643  DECL_ASN_OP_T(op,uint64) \
644  DECL_ASN_OP_T(op,const sc_int_base&) \
645  DECL_ASN_OP_T(op,const sc_uint_base&) \
646  DECL_ASN_OP_T(op,const sc_signed&) \
647  DECL_ASN_OP_T(op,const sc_unsigned&)
648 #else
649 #define DECL_ASN_OP_OTHER(op)
650 #endif
651 
652 #define DECL_ASN_OP(op) \
653  DECL_ASN_OP_T(op,int) \
654  DECL_ASN_OP_T(op,unsigned int) \
655  DECL_ASN_OP_T(op,long) \
656  DECL_ASN_OP_T(op,unsigned long) \
657  DECL_ASN_OP_T(op,float) \
658  DECL_ASN_OP_T(op,double) \
659  DECL_ASN_OP_T(op,const char*) \
660  DECL_ASN_OP_T(op,const sc_fxval&) \
661  DECL_ASN_OP_T(op,const sc_fxval_fast&) \
662  DECL_ASN_OP_T(op,const sc_fxnum&) \
663  DECL_ASN_OP_T(op,const sc_fxnum_fast&) \
664  DECL_ASN_OP_OTHER(op)
665 
666  DECL_ASN_OP(=)
667 
668  DECL_ASN_OP(*=)
669  DECL_ASN_OP(/=)
670  DECL_ASN_OP(+=)
671  DECL_ASN_OP(-=)
672 
673  DECL_ASN_OP_T(<<=,int)
674  DECL_ASN_OP_T(>>=,int)
675 
676 #undef DECL_ASN_OP_T
677 #undef DECL_ASN_OP_OTHER
678 #undef DECL_ASN_OP
679 
680 
681  // auto-increment and auto-decrement
682 
683  const sc_fxval_fast operator ++ ( int );
684  const sc_fxval_fast operator -- ( int );
685 
686  sc_fxval_fast& operator ++ ();
687  sc_fxval_fast& operator -- ();
688 
689 
690  // implicit conversion
691 
692  operator double() const; // necessary evil!
693 
694 
695  // explicit conversion to primitive types
696 
697  short to_short() const;
698  unsigned short to_ushort() const;
699  int to_int() const;
700  unsigned int to_uint() const;
701  long to_long() const;
702  unsigned long to_ulong() const;
703  int64 to_int64() const;
704  uint64 to_uint64() const;
705  float to_float() const;
706  double to_double() const;
707 
708 
709  // explicit conversion to character string
710 
711  const std::string to_string() const;
712  const std::string to_string( sc_numrep ) const;
713  const std::string to_string( sc_numrep, bool ) const;
714  const std::string to_string( sc_fmt ) const;
715  const std::string to_string( sc_numrep, sc_fmt ) const;
716  const std::string to_string( sc_numrep, bool, sc_fmt ) const;
717 
718  const std::string to_dec() const;
719  const std::string to_bin() const;
720  const std::string to_oct() const;
721  const std::string to_hex() const;
722 
723 
724  // query value
725 
726  bool is_neg() const;
727  bool is_zero() const;
728  bool is_nan() const;
729  bool is_inf() const;
730  bool is_normal() const;
731 
732  bool rounding_flag() const;
733 
734 
735  // print or dump content
736 
737  void print( ::std::ostream& = ::std::cout ) const;
738  void scan( ::std::istream& = ::std::cin );
739  void dump( ::std::ostream& = ::std::cout ) const;
740 
741 
742  // internal use only;
743  bool get_bit( int ) const;
744 
745 protected:
746 
747  sc_fxval_fast_observer* lock_observer() const;
748  void unlock_observer( sc_fxval_fast_observer* ) const;
749 
750 
751  static double from_string( const char* );
752 
753 private:
754 
755  double m_val;
756 
757  mutable sc_fxval_fast_observer* m_observer;
758 
759 };
760 
761 
762 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
763 
764 // ----------------------------------------------------------------------------
765 // CLASS : sc_fxval
766 //
767 // Fixed-point value type; arbitrary precision.
768 // ----------------------------------------------------------------------------
769 
770 // protected method
771 
772 inline
773 sc_fxval_observer*
775 {
776  return m_observer;
777 }
778 
779 
780 // internal use only;
781 inline
783 : m_rep( a != 0 ? a : new scfx_rep ),
784  m_observer( 0 )
785 {}
786 
787 
788 // public constructors
789 
790 inline
792 : m_rep( new scfx_rep ),
793  m_observer( observer_ )
794 {
797 }
798 
799 inline
800 sc_fxval::sc_fxval( const sc_fxval& a,
801  sc_fxval_observer* observer_ )
802 : m_rep( new scfx_rep( *a.m_rep ) ),
803  m_observer( observer_ )
804 {
808  SC_FXVAL_OBSERVER_WRITE_( *this )
809 }
810 
811 #define DEFN_CTOR_T(tp,arg) \
812 inline \
813 sc_fxval::sc_fxval( tp a, \
814  sc_fxval_observer* observer_ ) \
815 : m_rep( new scfx_rep( arg ) ), \
816  m_observer( observer_ ) \
817 { \
818  SC_FXVAL_OBSERVER_DEFAULT_ \
819  SC_FXVAL_OBSERVER_CONSTRUCT_( *this ) \
820  SC_FXVAL_OBSERVER_WRITE_( *this ) \
821 }
822 
823 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
824 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,a.to_double())
825 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.value())
826 
827 DEFN_CTOR_T_A(int)
828 DEFN_CTOR_T_A(unsigned int)
829 DEFN_CTOR_T_A(long)
830 DEFN_CTOR_T_A(unsigned long)
831 DEFN_CTOR_T_A(float)
832 DEFN_CTOR_T_A(double)
833 DEFN_CTOR_T_A(const char*)
834 DEFN_CTOR_T_B(const sc_fxval_fast&)
835 #ifndef SC_FX_EXCLUDE_OTHER
840 DEFN_CTOR_T_A(const sc_signed&)
842 #endif
843 
844 #undef DEFN_CTOR_T
845 #undef DEFN_CTOR_T_A
846 #undef DEFN_CTOR_T_B
847 #undef DEFN_CTOR_T_C
848 
849 
850 inline
852 {
854  delete m_rep;
855 }
856 
857 
858 // internal use only;
859 inline
860 const scfx_rep*
862 {
863  SC_FXVAL_OBSERVER_READ_( *this )
864  return m_rep;
865 }
866 
867 // internal use only;
868 inline
869 void
871 {
872  delete m_rep;
873  m_rep = rep_;
874  SC_FXVAL_OBSERVER_WRITE_( *this )
875 }
876 
877 
878 // unary operators
879 
880 inline
881 const sc_fxval
883 {
884  SC_FXVAL_OBSERVER_READ_( *this )
885  return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
886 }
887 
888 inline
889 const sc_fxval&
891 {
892  // SC_FXVAL_OBSERVER_READ_( *this )
893  return *this;
894 }
895 
896 
897 // unary functions
898 
899 inline
900 void
901 neg( sc_fxval& c, const sc_fxval& a )
902 {
904  delete c.m_rep;
905  c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
907 }
908 
909 
910 // binary operators
911 
912 #define DEFN_BIN_OP_T(op,fnc,tp) \
913 inline \
914 const sc_fxval \
915 operator op ( const sc_fxval& a, tp b ) \
916 { \
917  SC_FXVAL_OBSERVER_READ_( a ) \
918  sc_fxval tmp( b ); \
919  return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) ); \
920 } \
921  \
922 inline \
923 const sc_fxval \
924 operator op ( tp a, const sc_fxval& b ) \
925 { \
926  SC_FXVAL_OBSERVER_READ_( b ) \
927  sc_fxval tmp( a ); \
928  return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) ); \
929 }
930 
931 #ifndef SC_FX_EXCLUDE_OTHER
932 #define DEFN_BIN_OP_OTHER(op,fnc) \
933 DEFN_BIN_OP_T(op,fnc,int64) \
934 DEFN_BIN_OP_T(op,fnc,uint64) \
935 DEFN_BIN_OP_T(op,fnc,const sc_int_base&) \
936 DEFN_BIN_OP_T(op,fnc,const sc_uint_base&) \
937 DEFN_BIN_OP_T(op,fnc,const sc_signed&) \
938 DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
939 #else
940 #define DEFN_BIN_OP_OTHER(op,fnc)
941 #endif
942 
943 #define DEFN_BIN_OP(op,fnc) \
944 inline \
945 const sc_fxval \
946 operator op ( const sc_fxval& a, const sc_fxval& b ) \
947 { \
948  SC_FXVAL_OBSERVER_READ_( a ) \
949  SC_FXVAL_OBSERVER_READ_( b ) \
950  return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) ); \
951 } \
952  \
953 DEFN_BIN_OP_T(op,fnc,int) \
954 DEFN_BIN_OP_T(op,fnc,unsigned int) \
955 DEFN_BIN_OP_T(op,fnc,long) \
956 DEFN_BIN_OP_T(op,fnc,unsigned long) \
957 DEFN_BIN_OP_T(op,fnc,float) \
958 DEFN_BIN_OP_T(op,fnc,double) \
959 DEFN_BIN_OP_T(op,fnc,const char*) \
960 DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&) \
961 DEFN_BIN_OP_OTHER(op,fnc)
962 
963 DEFN_BIN_OP(*,mult)
964 DEFN_BIN_OP(+,add)
965 DEFN_BIN_OP(-,sub)
966 // don't use macro
967 //DEFN_BIN_OP(/,div)
968 inline
969 const sc_fxval
970 operator / ( const sc_fxval& a, const sc_fxval& b )
971 {
974  return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
975 }
976 
977 DEFN_BIN_OP_T(/,div,int)
978 DEFN_BIN_OP_T(/,div,unsigned int)
979 DEFN_BIN_OP_T(/,div,long)
980 DEFN_BIN_OP_T(/,div,unsigned long)
981 DEFN_BIN_OP_T(/,div,float)
982 DEFN_BIN_OP_T(/,div,double)
983 DEFN_BIN_OP_T(/,div,const char*)
984 DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
985 //DEFN_BIN_OP_OTHER(/,div)
986 #ifndef SC_FX_EXCLUDE_OTHER
987 DEFN_BIN_OP_T(/,div,int64) \
989 DEFN_BIN_OP_T(/,div,const sc_int_base&) \
990 DEFN_BIN_OP_T(/,div,const sc_uint_base&) \
991 DEFN_BIN_OP_T(/,div,const sc_signed&) \
992 DEFN_BIN_OP_T(/,div,const sc_unsigned&)
993 #endif
994 
995 #undef DEFN_BIN_OP_T
996 #undef DEFN_BIN_OP_OTHER
997 #undef DEFN_BIN_OP
998 
999 
1000 inline
1001 const sc_fxval
1002 operator << ( const sc_fxval& a, int b )
1005  return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
1006 }
1007 
1008 inline
1009 const sc_fxval
1010 operator >> ( const sc_fxval& a, int b )
1011 {
1013  return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
1014 }
1015 
1016 
1017 // binary functions
1018 
1019 #define DEFN_BIN_FNC_T(fnc,tp) \
1020 inline \
1021 void \
1022 fnc ( sc_fxval& c, const sc_fxval& a, tp b ) \
1023 { \
1024  SC_FXVAL_OBSERVER_READ_( a ) \
1025  sc_fxval tmp( b ); \
1026  delete c.m_rep; \
1027  c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ); \
1028  SC_FXVAL_OBSERVER_WRITE_( c ) \
1029 } \
1030  \
1031 inline \
1032 void \
1033 fnc ( sc_fxval& c, tp a, const sc_fxval& b ) \
1034 { \
1035  SC_FXVAL_OBSERVER_READ_( b ) \
1036  sc_fxval tmp( a ); \
1037  delete c.m_rep; \
1038  c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ); \
1039  SC_FXVAL_OBSERVER_WRITE_( c ) \
1040 }
1041 
1042 #ifndef SC_FX_EXCLUDE_OTHER
1043 #define DEFN_BIN_FNC_OTHER(fnc) \
1044 DEFN_BIN_FNC_T(fnc,int64) \
1045 DEFN_BIN_FNC_T(fnc,uint64) \
1046 DEFN_BIN_FNC_T(fnc,const sc_int_base&) \
1047 DEFN_BIN_FNC_T(fnc,const sc_uint_base&) \
1048 DEFN_BIN_FNC_T(fnc,const sc_signed&) \
1049 DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
1050 #else
1051 #define DEFN_BIN_FNC_OTHER(fnc)
1052 #endif
1053 
1054 #define DEFN_BIN_FNC(fnc) \
1055 inline \
1056 void \
1057 fnc( sc_fxval& c, const sc_fxval& a, const sc_fxval& b ) \
1058 { \
1059  SC_FXVAL_OBSERVER_READ_( a ) \
1060  SC_FXVAL_OBSERVER_READ_( b ) \
1061  delete c.m_rep; \
1062  c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ); \
1063  SC_FXVAL_OBSERVER_WRITE_( c ) \
1064 } \
1065  \
1066 DEFN_BIN_FNC_T(fnc,int) \
1067 DEFN_BIN_FNC_T(fnc,unsigned int) \
1068 DEFN_BIN_FNC_T(fnc,long) \
1069 DEFN_BIN_FNC_T(fnc,unsigned long) \
1070 DEFN_BIN_FNC_T(fnc,float) \
1071 DEFN_BIN_FNC_T(fnc,double) \
1072 DEFN_BIN_FNC_T(fnc,const char*) \
1073 DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&) \
1074 DEFN_BIN_FNC_OTHER(fnc)
1075 
1076 DEFN_BIN_FNC(mult)
1077 DEFN_BIN_FNC(div)
1078 DEFN_BIN_FNC(add)
1079 DEFN_BIN_FNC(sub)
1080 
1081 #undef DEFN_BIN_FNC_T
1082 #undef DEFN_BIN_FNC_OTHER
1083 #undef DEFN_BIN_FNC
1084 
1085 
1086 inline
1087 void
1088 lshift( sc_fxval& c, const sc_fxval& a, int b )
1089 {
1091  delete c.m_rep;
1092  c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
1094 }
1095 
1096 inline
1097 void
1098 rshift( sc_fxval& c, const sc_fxval& a, int b )
1099 {
1101  delete c.m_rep;
1102  c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
1104 }
1105 
1106 
1107 // relational (including equality) operators
1108 
1109 #define DEFN_REL_OP_T(op,ret,tp) \
1110 inline \
1111 bool \
1112 operator op ( const sc_fxval& a, tp b ) \
1113 { \
1114  SC_FXVAL_OBSERVER_READ_( a ) \
1115  sc_fxval tmp( b ); \
1116  int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep ); \
1117  return ( ret ); \
1118 } \
1119  \
1120 inline \
1121 bool \
1122 operator op ( tp a, const sc_fxval& b ) \
1123 { \
1124  SC_FXVAL_OBSERVER_READ_( b ) \
1125  sc_fxval tmp( a ); \
1126  int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep ); \
1127  return ( ret ); \
1128 }
1129 
1130 #ifndef SC_FX_EXCLUDE_OTHER
1131 #define DEFN_REL_OP_OTHER(op,ret) \
1132 DEFN_REL_OP_T(op,ret,int64) \
1133 DEFN_REL_OP_T(op,ret,uint64) \
1134 DEFN_REL_OP_T(op,ret,const sc_int_base&) \
1135 DEFN_REL_OP_T(op,ret,const sc_uint_base&) \
1136 DEFN_REL_OP_T(op,ret,const sc_signed&) \
1137 DEFN_REL_OP_T(op,ret,const sc_unsigned&)
1138 #else
1139 #define DEFN_REL_OP_OTHER(op,ret)
1140 #endif
1141 
1142 #define DEFN_REL_OP(op,ret) \
1143 inline \
1144 bool \
1145 operator op ( const sc_fxval& a, const sc_fxval& b) \
1146 { \
1147  SC_FXVAL_OBSERVER_READ_( a ) \
1148  SC_FXVAL_OBSERVER_READ_( b ) \
1149  int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep ); \
1150  return ( ret ); \
1151 } \
1152  \
1153 DEFN_REL_OP_T(op,ret,int) \
1154 DEFN_REL_OP_T(op,ret,unsigned int) \
1155 DEFN_REL_OP_T(op,ret,long) \
1156 DEFN_REL_OP_T(op,ret,unsigned long) \
1157 DEFN_REL_OP_T(op,ret,float) \
1158 DEFN_REL_OP_T(op,ret,double) \
1159 DEFN_REL_OP_T(op,ret,const char*) \
1160 DEFN_REL_OP_T(op,ret,const sc_fxval_fast&) \
1161 DEFN_REL_OP_OTHER(op,ret)
1162 
1163 DEFN_REL_OP(<,result < 0)
1164 DEFN_REL_OP(<=,result <= 0)
1165 DEFN_REL_OP(>,result > 0 && result != 2)
1166 DEFN_REL_OP(>=,result >= 0 && result != 2)
1167 DEFN_REL_OP(==,result == 0)
1168 DEFN_REL_OP(!=,result != 0)
1169 
1170 #undef DEFN_REL_OP_T
1171 #undef DEFN_REL_OP_OTHER
1172 #undef DEFN_REL_OP
1173 
1174 
1175 // assignment operators
1176 
1177 inline
1178 sc_fxval&
1179 sc_fxval::operator = ( const sc_fxval& a )
1180 {
1181  if( &a != this )
1182  {
1184  *m_rep = *a.m_rep;
1185  SC_FXVAL_OBSERVER_WRITE_( *this )
1186  }
1187  return *this;
1188 }
1189 
1190 #define DEFN_ASN_OP_T(tp) \
1191 inline \
1192 sc_fxval& \
1193 sc_fxval::operator = ( tp b ) \
1194 { \
1195  sc_fxval tmp( b ); \
1196  *m_rep = *tmp.m_rep; \
1197  SC_FXVAL_OBSERVER_WRITE_( *this ) \
1198  return *this; \
1199 }
1200 
1201 DEFN_ASN_OP_T(int)
1202 DEFN_ASN_OP_T(unsigned int)
1203 DEFN_ASN_OP_T(long)
1204 DEFN_ASN_OP_T(unsigned long)
1205 DEFN_ASN_OP_T(float)
1206 DEFN_ASN_OP_T(double)
1207 DEFN_ASN_OP_T(const char*)
1208 DEFN_ASN_OP_T(const sc_fxval_fast&)
1209 #ifndef SC_FX_EXCLUDE_OTHER
1212 DEFN_ASN_OP_T(const sc_int_base&)
1213 DEFN_ASN_OP_T(const sc_uint_base&)
1214 DEFN_ASN_OP_T(const sc_signed&)
1215 DEFN_ASN_OP_T(const sc_unsigned&)
1216 #endif
1217 
1218 #undef DEFN_ASN_OP_T
1219 
1220 
1221 #define DEFN_ASN_OP_T(op,fnc,tp) \
1222 inline \
1223 sc_fxval& \
1224 sc_fxval::operator op ( tp b ) \
1225 { \
1226  SC_FXVAL_OBSERVER_READ_( *this ) \
1227  sc_fxval tmp( b ); \
1228  scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep ); \
1229  delete m_rep; \
1230  m_rep = new_rep; \
1231  SC_FXVAL_OBSERVER_WRITE_( *this ) \
1232  return *this; \
1233 }
1234 
1235 #ifndef SC_FX_EXCLUDE_OTHER
1236 #define DEFN_ASN_OP_OTHER(op,fnc) \
1237 DEFN_ASN_OP_T(op,fnc,int64) \
1238 DEFN_ASN_OP_T(op,fnc,uint64) \
1239 DEFN_ASN_OP_T(op,fnc,const sc_int_base&) \
1240 DEFN_ASN_OP_T(op,fnc,const sc_uint_base&) \
1241 DEFN_ASN_OP_T(op,fnc,const sc_signed&) \
1242 DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
1243 #else
1244 #define DEFN_ASN_OP_OTHER(op,fnc)
1245 #endif
1246 
1247 #define DEFN_ASN_OP(op,fnc) \
1248 inline \
1249 sc_fxval& \
1250 sc_fxval::operator op ( const sc_fxval& b ) \
1251 { \
1252  SC_FXVAL_OBSERVER_READ_( *this ) \
1253  SC_FXVAL_OBSERVER_READ_( b ) \
1254  scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep ); \
1255  delete m_rep; \
1256  m_rep = new_rep; \
1257  SC_FXVAL_OBSERVER_WRITE_( *this ) \
1258  return *this; \
1259 } \
1260  \
1261 DEFN_ASN_OP_T(op,fnc,int) \
1262 DEFN_ASN_OP_T(op,fnc,unsigned int) \
1263 DEFN_ASN_OP_T(op,fnc,long) \
1264 DEFN_ASN_OP_T(op,fnc,unsigned long) \
1265 DEFN_ASN_OP_T(op,fnc,float) \
1266 DEFN_ASN_OP_T(op,fnc,double) \
1267 DEFN_ASN_OP_T(op,fnc,const char*) \
1268 DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&) \
1269 DEFN_ASN_OP_OTHER(op,fnc)
1270 
1271 DEFN_ASN_OP(*=,mult)
1272 DEFN_ASN_OP(/=,div)
1273 DEFN_ASN_OP(+=,add)
1274 DEFN_ASN_OP(-=,sub)
1275 
1276 #undef DEFN_ASN_OP_T
1277 #undef DEFN_ASN_OP_OTHER
1278 #undef DEFN_ASN_OP
1279 
1280 
1281 inline
1282 sc_fxval&
1283 sc_fxval::operator <<= ( int b )
1284 {
1285  SC_FXVAL_OBSERVER_READ_( *this )
1286  m_rep->lshift( b );
1287  SC_FXVAL_OBSERVER_WRITE_( *this )
1288  return *this;
1289 }
1290 
1291 inline
1292 sc_fxval&
1293 sc_fxval::operator >>= ( int b )
1294 {
1295  SC_FXVAL_OBSERVER_READ_( *this )
1296  m_rep->rshift( b );
1297  SC_FXVAL_OBSERVER_WRITE_( *this )
1298  return *this;
1299 }
1300 
1301 
1302 // auto-increment and auto-decrement
1303 
1304 inline
1305 const sc_fxval
1306 sc_fxval::operator ++ ( int )
1307 {
1308  sc_fxval c = *this;
1309  (*this) += 1;
1310  return c;
1311 }
1312 
1313 inline
1314 const sc_fxval
1316 {
1317  sc_fxval c = *this;
1318  (*this) -= 1;
1319  return c;
1320 }
1321 
1322 inline
1323 sc_fxval&
1325 {
1326  (*this) += 1;
1327  return *this;
1328 }
1329 
1330 inline
1331 sc_fxval&
1333 {
1334  (*this) -= 1;
1335  return *this;
1336 }
1337 
1338 
1339 // implicit conversion
1340 
1341 inline
1342 sc_fxval::operator double() const
1343 {
1344  SC_FXVAL_OBSERVER_READ_( *this )
1345  return m_rep->to_double();
1346 }
1347 
1348 
1349 // explicit conversion to primitive types
1350 
1351 inline
1352 short
1354 {
1355  SC_FXVAL_OBSERVER_READ_( *this )
1356  return static_cast<short>( m_rep->to_double() );
1357 }
1358 
1359 inline
1360 unsigned short
1362 {
1363  SC_FXVAL_OBSERVER_READ_( *this )
1364  return static_cast<unsigned short>( m_rep->to_double() );
1365 }
1366 
1367 inline
1368 int
1370 {
1371  SC_FXVAL_OBSERVER_READ_( *this )
1372  return static_cast<int>( m_rep->to_double() );
1373 }
1374 
1375 inline
1376 int64
1378 {
1379  SC_FXVAL_OBSERVER_READ_( *this )
1380  return static_cast<int64>( m_rep->to_double() );
1381 }
1382 
1383 inline
1384 uint64
1386 {
1387  SC_FXVAL_OBSERVER_READ_( *this )
1388  return static_cast<uint64>( m_rep->to_double() );
1389 }
1390 
1391 inline
1392 long
1394 {
1395  SC_FXVAL_OBSERVER_READ_( *this )
1396  return static_cast<long>( m_rep->to_double() );
1397 }
1398 
1399 inline
1400 unsigned int
1402 {
1403  SC_FXVAL_OBSERVER_READ_( *this )
1404  return static_cast<unsigned int>( m_rep->to_double() );
1405 }
1406 
1407 inline
1408 unsigned long
1410 {
1411  SC_FXVAL_OBSERVER_READ_( *this )
1412  return static_cast<unsigned long>( m_rep->to_double() );
1413 }
1414 
1415 inline
1416 float
1418 {
1419  SC_FXVAL_OBSERVER_READ_( *this )
1420  return static_cast<float>( m_rep->to_double() );
1421 }
1422 
1423 inline
1424 double
1426 {
1427  SC_FXVAL_OBSERVER_READ_( *this )
1428  return m_rep->to_double();
1429 }
1430 
1431 
1432 // query value
1433 
1434 inline
1435 bool
1437 {
1438  SC_FXVAL_OBSERVER_READ_( *this )
1439  return m_rep->is_neg();
1440 }
1441 
1442 inline
1443 bool
1445 {
1446  SC_FXVAL_OBSERVER_READ_( *this )
1447  return m_rep->is_zero();
1448 }
1449 
1450 inline
1451 bool
1453 {
1454  SC_FXVAL_OBSERVER_READ_( *this )
1455  return m_rep->is_nan();
1456 }
1457 
1458 inline
1459 bool
1461 {
1462  SC_FXVAL_OBSERVER_READ_( *this )
1463  return m_rep->is_inf();
1464 }
1465 
1466 inline
1467 bool
1469 {
1470  SC_FXVAL_OBSERVER_READ_( *this )
1471  return m_rep->is_normal();
1472 }
1473 
1474 
1475 inline
1476 bool
1478 {
1479  return m_rep->rounding_flag();
1480 }
1481 
1482 
1483 // internal use only;
1484 inline
1485 bool
1486 sc_fxval::get_bit( int i ) const
1487 {
1488  return m_rep->get_bit( i );
1489 }
1490 
1491 
1492 // protected methods and friend functions
1493 
1494 inline
1495 void
1496 sc_fxval::get_type( int& wl, int& iwl, sc_enc& enc ) const
1497 {
1498  m_rep->get_type( wl, iwl, enc );
1499 }
1500 
1501 
1502 inline
1503 const sc_fxval
1504 sc_fxval::quantization( const scfx_params& params, bool& q_flag ) const
1505 {
1506  return sc_fxval( sc_dt::quantization_scfx_rep( *m_rep, params, q_flag ) );
1507 }
1508 
1509 inline
1510 const sc_fxval
1511 sc_fxval::overflow( const scfx_params& params, bool& o_flag ) const
1512 {
1513  return sc_fxval( sc_dt::overflow_scfx_rep( *m_rep, params, o_flag ) );
1514 }
1515 
1516 
1517 inline
1518 ::std::ostream&
1519 operator << ( ::std::ostream& os, const sc_fxval& a )
1520 {
1521  a.print( os );
1522  return os;
1523 }
1524 
1525 inline
1526 ::std::istream&
1527 operator >> ( ::std::istream& is, sc_fxval& a )
1528 {
1529  a.scan( is );
1530  return is;
1531 }
1532 
1533 
1534 // ----------------------------------------------------------------------------
1535 // CLASS : sc_fxval_fast
1536 //
1537 // Fixed-point value type; limited precision.
1538 // ----------------------------------------------------------------------------
1539 
1540 // protected method
1541 
1542 inline
1543 sc_fxval_fast_observer*
1545 {
1546  return m_observer;
1547 }
1548 
1549 
1550 // public constructors
1551 
1552 inline
1554 : m_val( 0.0 ),
1555  m_observer( observer_ )
1556 {
1559 }
1560 
1561 inline
1562 sc_fxval_fast::sc_fxval_fast( const sc_fxval_fast& a,
1563  sc_fxval_fast_observer* observer_ )
1564 : m_val( a.m_val ),
1565  m_observer( observer_ )
1566 {
1571 }
1572 
1573 #define DEFN_CTOR_T(tp,arg) \
1574 inline \
1575 sc_fxval_fast::sc_fxval_fast( tp a, \
1576  sc_fxval_fast_observer* observer_ ) \
1577 : m_val( arg ), \
1578  m_observer( observer_ ) \
1579 { \
1580  SC_FXVAL_FAST_OBSERVER_DEFAULT_ \
1581  SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this ) \
1582  SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
1583 }
1584 
1585 #define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
1586 #define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,from_string( a ))
1587 #define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
1588 
1589 DEFN_CTOR_T_A(int)
1590 DEFN_CTOR_T_A(unsigned int)
1591 DEFN_CTOR_T_A(long)
1592 DEFN_CTOR_T_A(unsigned long)
1593 DEFN_CTOR_T_A(float)
1594 DEFN_CTOR_T_A(double)
1595 DEFN_CTOR_T_B(const char*)
1596 DEFN_CTOR_T_C(const sc_fxval&)
1597 #ifndef SC_FX_EXCLUDE_OTHER
1600 DEFN_CTOR_T_C(const sc_int_base&)
1601 DEFN_CTOR_T_C(const sc_uint_base&)
1602 DEFN_CTOR_T_C(const sc_signed&)
1603 DEFN_CTOR_T_C(const sc_unsigned&)
1604 #endif
1605 
1606 #undef DEFN_CTOR_T
1607 #undef DEFN_CTOR_T_A
1608 #undef DEFN_CTOR_T_B
1609 #undef DEFN_CTOR_T_C
1610 #undef DEFN_CTOR_T_D
1611 #undef DEFN_CTOR_T_E
1612 
1613 
1614 inline
1616 {
1618 }
1619 
1620 
1621 // internal use only;
1622 inline
1623 double
1625 {
1627  return m_val;
1628 }
1629 
1630 // internal use only;
1631 inline
1632 void
1634 {
1635  m_val = val_;
1637 }
1638 
1639 
1640 // unary operators
1641 
1642 inline
1643 const sc_fxval_fast
1645 {
1647  return sc_fxval_fast( - m_val );
1648 }
1649 
1650 inline
1651 const sc_fxval_fast&
1653 {
1654  // SC_FXVAL_FAST_OBSERVER_READ_( *this )
1655  return *this;
1656 }
1657 
1658 
1659 // unary functions
1660 
1661 inline
1662 void
1663 neg( sc_fxval_fast& c, const sc_fxval_fast& a )
1664 {
1666  c.m_val = - a.m_val;
1668 }
1669 
1670 
1671 // binary operators
1672 
1673 #define DEFN_BIN_OP_T(op,tp) \
1674 inline \
1675 const sc_fxval_fast \
1676 operator op ( const sc_fxval_fast& a, tp b ) \
1677 { \
1678  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1679  sc_fxval_fast tmp( b ); \
1680  return sc_fxval_fast( a.m_val op tmp.m_val ); \
1681 } \
1682  \
1683 inline \
1684 const sc_fxval_fast \
1685 operator op ( tp a, const sc_fxval_fast& b ) \
1686 { \
1687  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1688  sc_fxval_fast tmp( a ); \
1689  return sc_fxval_fast( tmp.m_val op b.m_val ); \
1690 }
1691 
1692 #ifndef SC_FX_EXCLUDE_OTHER
1693 #define DEFN_BIN_OP_OTHER(op) \
1694 DEFN_BIN_OP_T(op,int64) \
1695 DEFN_BIN_OP_T(op,uint64) \
1696 DEFN_BIN_OP_T(op,const sc_int_base&) \
1697 DEFN_BIN_OP_T(op,const sc_uint_base&) \
1698 DEFN_BIN_OP_T(op,const sc_signed&) \
1699 DEFN_BIN_OP_T(op,const sc_unsigned&)
1700 #else
1701 #define DEFN_BIN_OP_OTHER(op)
1702 #endif
1703 
1704 #define DEFN_BIN_OP(op,dummy) \
1705 inline \
1706 const sc_fxval_fast \
1707 operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b ) \
1708 { \
1709  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1710  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1711  return sc_fxval_fast( a.m_val op b.m_val ); \
1712 } \
1713  \
1714 DEFN_BIN_OP_T(op,int) \
1715 DEFN_BIN_OP_T(op,unsigned int) \
1716 DEFN_BIN_OP_T(op,long) \
1717 DEFN_BIN_OP_T(op,unsigned long) \
1718 DEFN_BIN_OP_T(op,float) \
1719 DEFN_BIN_OP_T(op,double) \
1720 DEFN_BIN_OP_T(op,const char*) \
1721 DEFN_BIN_OP_OTHER(op)
1722 
1723 DEFN_BIN_OP(*,mult)
1724 DEFN_BIN_OP(+,add)
1725 DEFN_BIN_OP(-,sub)
1726 //DEFN_BIN_OP(/,div)
1727 inline
1728 const sc_fxval_fast
1729 operator / ( const sc_fxval_fast& a, const sc_fxval_fast& b )
1730 {
1733  return sc_fxval_fast( a.m_val / b.m_val );
1734 }
1735 
1736 DEFN_BIN_OP_T(/,int)
1737 DEFN_BIN_OP_T(/,unsigned int)
1738 DEFN_BIN_OP_T(/,long)
1739 DEFN_BIN_OP_T(/,unsigned long)
1740 DEFN_BIN_OP_T(/,float)
1741 DEFN_BIN_OP_T(/,double)
1742 DEFN_BIN_OP_T(/,const char*)
1743 //DEFN_BIN_OP_OTHER(/)
1744 #ifndef SC_FX_EXCLUDE_OTHER
1746 DEFN_BIN_OP_T(/,uint64)
1747 DEFN_BIN_OP_T(/,const sc_int_base&)
1748 DEFN_BIN_OP_T(/,const sc_uint_base&)
1749 DEFN_BIN_OP_T(/,const sc_signed&)
1750 DEFN_BIN_OP_T(/,const sc_unsigned&)
1751 #endif
1752 
1753 
1754 #undef DEFN_BIN_OP_T
1755 #undef DEFN_BIN_OP_OTHER
1756 #undef DEFN_BIN_OP
1757 
1758 
1759 inline
1760 const sc_fxval_fast
1761 operator << ( const sc_fxval_fast& a, int b )
1762 {
1764  return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
1765 }
1766 
1767 inline
1768 const sc_fxval_fast
1769 operator >> ( const sc_fxval_fast& a, int b )
1770 {
1772  return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
1773 }
1774 
1775 
1776 // binary functions
1777 
1778 #define DEFN_BIN_FNC_T(fnc,op,tp) \
1779 inline \
1780 void \
1781 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b ) \
1782 { \
1783  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1784  sc_fxval_fast tmp( b ); \
1785  c.m_val = a.m_val op tmp.m_val; \
1786  SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \
1787 } \
1788  \
1789 inline \
1790 void \
1791 fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b ) \
1792 { \
1793  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1794  sc_fxval_fast tmp( a ); \
1795  c.m_val = tmp.m_val op b.m_val; \
1796  SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \
1797 }
1798 
1799 #ifndef SC_FX_EXCLUDE_OTHER
1800 #define DEFN_BIN_FNC_OTHER(fnc,op) \
1801 DEFN_BIN_FNC_T(fnc,op,int64) \
1802 DEFN_BIN_FNC_T(fnc,op,uint64) \
1803 DEFN_BIN_FNC_T(fnc,op,const sc_int_base&) \
1804 DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&) \
1805 DEFN_BIN_FNC_T(fnc,op,const sc_signed&) \
1806 DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
1807 #else
1808 #define DEFN_BIN_FNC_OTHER(fnc,op)
1809 #endif
1810 
1811 #define DEFN_BIN_FNC(fnc,op) \
1812 inline \
1813 void \
1814 fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxval_fast& b ) \
1815 { \
1816  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1817  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1818  c.m_val = a.m_val op b.m_val; \
1819  SC_FXVAL_FAST_OBSERVER_WRITE_( c ) \
1820 } \
1821  \
1822 DEFN_BIN_FNC_T(fnc,op,int) \
1823 DEFN_BIN_FNC_T(fnc,op,unsigned int) \
1824 DEFN_BIN_FNC_T(fnc,op,long) \
1825 DEFN_BIN_FNC_T(fnc,op,unsigned long) \
1826 DEFN_BIN_FNC_T(fnc,op,float) \
1827 DEFN_BIN_FNC_T(fnc,op,double) \
1828 DEFN_BIN_FNC_T(fnc,op,const char*) \
1829 DEFN_BIN_FNC_OTHER(fnc,op)
1830 
1831 DEFN_BIN_FNC(mult,*)
1832 DEFN_BIN_FNC(div,/)
1833 DEFN_BIN_FNC(add,+)
1834 DEFN_BIN_FNC(sub,-)
1835 
1836 #undef DEFN_BIN_FNC_T
1837 #undef DEFN_BIN_FNC_OTHER
1838 #undef DEFN_BIN_FNC
1839 
1840 
1841 inline
1842 void
1843 lshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b )
1844 {
1846  c.m_val = a.m_val * scfx_pow2( b );
1848 }
1849 
1850 inline
1851 void
1852 rshift( sc_fxval_fast& c, const sc_fxval_fast& a, int b )
1853 {
1855  c.m_val = a.m_val * scfx_pow2( -b );
1857 }
1858 
1859 
1860 // relational (including equality) operators
1861 
1862 #define DEFN_REL_OP_T(op,tp) \
1863 inline \
1864 bool \
1865 operator op ( const sc_fxval_fast& a, tp b ) \
1866 { \
1867  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1868  sc_fxval_fast tmp( b ); \
1869  return ( a.m_val op tmp.m_val ); \
1870 } \
1871  \
1872 inline \
1873 bool \
1874 operator op ( tp a, const sc_fxval_fast& b ) \
1875 { \
1876  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1877  sc_fxval_fast tmp( a ); \
1878  return ( tmp.m_val op b.m_val ); \
1879 }
1880 
1881 #ifndef SC_FX_EXCLUDE_OTHER
1882 #define DEFN_REL_OP_OTHER(op) \
1883 DEFN_REL_OP_T(op,int64) \
1884 DEFN_REL_OP_T(op,uint64) \
1885 DEFN_REL_OP_T(op,const sc_int_base&) \
1886 DEFN_REL_OP_T(op,const sc_uint_base&) \
1887 DEFN_REL_OP_T(op,const sc_signed&) \
1888 DEFN_REL_OP_T(op,const sc_unsigned&)
1889 #else
1890 #define DEFN_REL_OP_OTHER(op)
1891 #endif
1892 
1893 #define DEFN_REL_OP(op) \
1894 inline \
1895 bool \
1896 operator op ( const sc_fxval_fast& a, const sc_fxval_fast& b ) \
1897 { \
1898  SC_FXVAL_FAST_OBSERVER_READ_( a ) \
1899  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
1900  return ( a.m_val op b.m_val ); \
1901 } \
1902  \
1903 DEFN_REL_OP_T(op,int) \
1904 DEFN_REL_OP_T(op,unsigned int) \
1905 DEFN_REL_OP_T(op,long) \
1906 DEFN_REL_OP_T(op,unsigned long) \
1907 DEFN_REL_OP_T(op,float) \
1908 DEFN_REL_OP_T(op,double) \
1909 DEFN_REL_OP_T(op,const char*) \
1910 DEFN_REL_OP_OTHER(op)
1911 
1912 DEFN_REL_OP(<)
1913 DEFN_REL_OP(<=)
1914 DEFN_REL_OP(>)
1915 DEFN_REL_OP(>=)
1916 DEFN_REL_OP(==)
1917 DEFN_REL_OP(!=)
1918 
1919 #undef DEFN_REL_OP_T
1920 #undef DEFN_REL_OP_OTHER
1921 #undef DEFN_REL_OP
1922 
1923 
1924 // assignment operators
1925 
1926 inline
1927 sc_fxval_fast&
1928 sc_fxval_fast::operator = ( const sc_fxval_fast& a )
1929 {
1930  if( &a != this )
1931  {
1933  m_val = a.m_val;
1935  }
1936  return *this;
1937 }
1938 
1939 #define DEFN_ASN_OP_T(tp) \
1940 inline \
1941 sc_fxval_fast& \
1942 sc_fxval_fast::operator = ( tp a ) \
1943 { \
1944  sc_fxval_fast tmp( a ); \
1945  m_val = tmp.m_val; \
1946  SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
1947  return *this; \
1948 }
1949 
1950 DEFN_ASN_OP_T(int)
1951 DEFN_ASN_OP_T(unsigned int)
1952 DEFN_ASN_OP_T(long)
1953 DEFN_ASN_OP_T(unsigned long)
1954 DEFN_ASN_OP_T(float)
1955 DEFN_ASN_OP_T(double)
1956 DEFN_ASN_OP_T(const char*)
1957 DEFN_ASN_OP_T(const sc_fxval&)
1958 #ifndef SC_FX_EXCLUDE_OTHER
1961 DEFN_ASN_OP_T(const sc_int_base&)
1962 DEFN_ASN_OP_T(const sc_uint_base&)
1963 DEFN_ASN_OP_T(const sc_signed&)
1964 DEFN_ASN_OP_T(const sc_unsigned&)
1965 #endif
1966 
1967 #undef DEFN_ASN_OP_T
1968 
1969 
1970 #define DEFN_ASN_OP_T(op,tp) \
1971 inline \
1972 sc_fxval_fast& \
1973 sc_fxval_fast::operator op ( tp b ) \
1974 { \
1975  SC_FXVAL_FAST_OBSERVER_READ_( *this ) \
1976  sc_fxval_fast tmp( b ); \
1977  m_val op tmp.m_val; \
1978  SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
1979  return *this; \
1980 }
1981 
1982 #ifndef SC_FX_EXCLUDE_OTHER
1983 #define DEFN_ASN_OP_OTHER(op) \
1984 DEFN_ASN_OP_T(op,int64) \
1985 DEFN_ASN_OP_T(op,uint64) \
1986 DEFN_ASN_OP_T(op,const sc_int_base&) \
1987 DEFN_ASN_OP_T(op,const sc_uint_base&) \
1988 DEFN_ASN_OP_T(op,const sc_signed&) \
1989 DEFN_ASN_OP_T(op,const sc_unsigned&)
1990 #else
1991 #define DEFN_ASN_OP_OTHER(op)
1992 #endif
1993 
1994 #define DEFN_ASN_OP(op) \
1995 inline \
1996 sc_fxval_fast& \
1997 sc_fxval_fast::operator op ( const sc_fxval_fast& b ) \
1998 { \
1999  SC_FXVAL_FAST_OBSERVER_READ_( *this ) \
2000  SC_FXVAL_FAST_OBSERVER_READ_( b ) \
2001  m_val op b.m_val; \
2002  SC_FXVAL_FAST_OBSERVER_WRITE_( *this ) \
2003  return *this; \
2004 } \
2005  \
2006 DEFN_ASN_OP_T(op,int) \
2007 DEFN_ASN_OP_T(op,unsigned int) \
2008 DEFN_ASN_OP_T(op,long) \
2009 DEFN_ASN_OP_T(op,unsigned long) \
2010 DEFN_ASN_OP_T(op,float) \
2011 DEFN_ASN_OP_T(op,double) \
2012 DEFN_ASN_OP_T(op,const char*) \
2013 DEFN_ASN_OP_T(op,const sc_fxval&) \
2014 DEFN_ASN_OP_OTHER(op)
2015 
2016 DEFN_ASN_OP(*=)
2017 DEFN_ASN_OP(/=)
2018 DEFN_ASN_OP(+=)
2019 DEFN_ASN_OP(-=)
2020 
2021 #undef DEFN_ASN_OP_T
2022 #undef DEFN_ASN_OP_OTHER
2023 #undef DEFN_ASN_OP
2024 
2025 
2026 inline
2027 sc_fxval_fast&
2028 sc_fxval_fast::operator <<= ( int b )
2029 {
2031  m_val *= scfx_pow2( b );
2033  return *this;
2034 }
2035 
2036 inline
2037 sc_fxval_fast&
2038 sc_fxval_fast::operator >>= ( int b )
2039 {
2041  m_val *= scfx_pow2( -b );
2043  return *this;
2044 }
2045 
2046 
2047 // auto-increment and auto-decrement
2048 
2049 inline
2050 const sc_fxval_fast
2051 sc_fxval_fast::operator ++ ( int )
2052 {
2055  double c = m_val;
2056  m_val = m_val + 1;
2058  return sc_fxval_fast( c );
2059 }
2060 
2061 inline
2062 const sc_fxval_fast
2064 {
2067  double c = m_val;
2068  m_val = m_val - 1;
2070  return sc_fxval_fast( c );
2071 }
2072 
2073 inline
2074 sc_fxval_fast&
2076 {
2078  m_val = m_val + 1;
2080  return *this;
2081 }
2082 
2083 inline
2084 sc_fxval_fast&
2086 {
2088  m_val = m_val - 1;
2090  return *this;
2091 }
2092 
2093 
2094 // implicit conversion
2095 
2096 inline
2097 sc_fxval_fast::operator double() const
2098 {
2100  return m_val;
2101 }
2102 
2103 
2104 // explicit conversion to primitive types
2105 
2106 inline
2107 short
2109 {
2111  return static_cast<short>( m_val );
2112 }
2113 
2114 inline
2115 unsigned short
2117 {
2119  return static_cast<unsigned short>( m_val );
2120 }
2121 
2122 inline
2123 int64
2125 {
2127  return static_cast<int64>( m_val );
2128 }
2129 
2130 inline
2131 int
2133 {
2135  return static_cast<int>( m_val );
2136 }
2137 
2138 inline
2139 unsigned int
2141 {
2143  return static_cast<unsigned int>( m_val );
2144 }
2145 
2146 inline
2147 uint64
2149 {
2151  return static_cast<uint64>( m_val );
2152 }
2153 
2154 inline
2155 long
2157 {
2159  return static_cast<long>( m_val );
2160 }
2161 
2162 inline
2163 unsigned long
2165 {
2167  return static_cast<unsigned long>( m_val );
2168 }
2169 
2170 inline
2171 float
2173 {
2175  return static_cast<float>( m_val );
2176 }
2177 
2178 inline
2179 double
2181 {
2183  return m_val;
2184 }
2185 
2186 
2187 // query value
2188 
2189 inline
2190 bool
2192 {
2194  scfx_ieee_double id( m_val );
2195  return ( id.negative() != 0 );
2196 }
2197 
2198 inline
2199 bool
2201 {
2203  scfx_ieee_double id( m_val );
2204  return id.is_zero();
2205 }
2206 
2207 inline
2208 bool
2210 {
2212  scfx_ieee_double id( m_val );
2213  return id.is_nan();
2214 }
2215 
2216 inline
2217 bool
2219 {
2221  scfx_ieee_double id( m_val );
2222  return id.is_inf();
2223 }
2224 
2225 inline
2226 bool
2228 {
2230  scfx_ieee_double id( m_val );
2231  return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
2232 }
2233 
2234 
2235 inline
2236 bool
2238 {
2239  // does not apply to sc_fxval_fast; included for API compatibility
2240  return false;
2241 }
2242 
2243 
2244 inline
2245 ::std::ostream&
2246 operator << ( ::std::ostream& os, const sc_fxval_fast& a )
2247 {
2248  a.print( os );
2249  return os;
2250 }
2251 
2252 inline
2253 ::std::istream&
2254 operator >> ( ::std::istream& is, sc_fxval_fast& a )
2255 {
2256  a.scan( is );
2257  return is;
2258 }
2259 
2260 } // namespace sc_dt
2261 
2262 #undef SCFX_EXPLICIT_
2263 #undef SCFX_EXPLICIT_OTHER_
2264 
2265 #endif
2266 
2267 // Taf!
#define DEFN_ASN_OP_T(op, tp)
Definition: sc_bit.h:174
bool is_neg() const
Definition: sc_fxval.h:1436
const std::string to_string() const
bool get_bit(int) const
Definition: sc_fxval.h:1486
#define SC_FXVAL_OBSERVER_DESTRUCT_(object)
bool is_neg() const
Definition: sc_fxval.h:2191
double to_double() const
Definition: sc_fxval.h:1425
friend const sc_fxval_fast operator>>(const sc_fxval_fast &, int)
Definition: sc_fxval.h:1769
bool is_zero() const
Definition: sc_fxval.h:1444
void scan(::std::istream &=::std::cin)
int to_int() const
Definition: sc_fxval.h:2132
long to_long() const
Definition: sc_fxval.h:2156
void rshift(sc_fxval &c, const sc_fxnum &a, int b)
Definition: sc_fxnum.h:2994
friend void lshift(sc_fxval_fast &, const sc_fxval_fast &, int)
Definition: sc_fxval.h:1843
const std::string to_hex() const
#define DECL_ASN_OP(op)
Definition: sc_fix.h:477
void unlock_observer(sc_fxval_observer *) const
sc_numrep
Definition: sc_nbdefs.h:91
void get_type(int &, int &, sc_enc &) const
int64_t int64
Definition: sc_nbdefs.h:182
void set_val(double)
Definition: sc_fxval.h:1633
#define SCFX_EXPLICIT_OTHER_
Definition: sc_fxval.h:72
friend const sc_fxval operator>>(const sc_fxval &, int)
Definition: sc_fxval.h:1010
scfx_rep * rsh_scfx_rep(const scfx_rep &, int)
Definition: scfx_rep.h:432
const scfx_rep * get_rep() const
Definition: sc_fxval.h:861
bool is_normal() const
Definition: sc_fxval.h:1468
bool rounding_flag() const
Definition: sc_fxval.h:2237
unsigned long to_ulong() const
Definition: sc_fxval.h:1409
void scan(::std::istream &=::std::cin)
void get_type(int &, int &, sc_enc &) const
Definition: sc_fxval.h:1496
#define SC_FXVAL_FAST_OBSERVER_DEFAULT_
friend void neg(sc_fxval &, const sc_fxval &)
Definition: sc_fxval.h:901
short to_short() const
Definition: sc_fxval.h:1353
sc_fxval_observer * observer() const
Definition: sc_fxval.h:774
#define SCFX_EXPLICIT_
Definition: sc_fxval.h:67
int64 to_int64() const
Definition: sc_fxval.h:2124
const sc_fxval operator-() const
Definition: sc_fxval.h:882
void dump(::std::ostream &=::std::cout) const
long to_long() const
Definition: sc_fxval.h:1393
bool is_nan() const
Definition: scfx_rep.h:471
uint64 to_uint64() const
Definition: sc_fxval.h:2148
#define SC_FXVAL_OBSERVER_DEFAULT_
sc_fxval_observer * lock_observer() const
float to_float() const
Definition: sc_fxval.h:2172
bool get_bit(int) const
scfx_rep * lsh_scfx_rep(const scfx_rep &, int)
Definition: scfx_rep.h:423
#define SC_FXVAL_FAST_OBSERVER_DESTRUCT_(object)
scfx_rep * overflow_scfx_rep(const scfx_rep &a, const scfx_params &params, bool &o_flag)
Definition: scfx_rep.h:503
double to_double() const
bool is_inf() const
Definition: scfx_rep.h:478
#define DECL_BIN_FNC(fnc)
Definition: sc_fxnum.h:1147
const std::string to_string() const
DECL_BIN_OP_T(/, int64) DECL_BIN_OP_T(/
scfx_rep * neg_scfx_rep(const scfx_rep &)
Definition: scfx_rep.h:405
uint64 const sc_uint_base int b
Definition: sc_fxval.h:1003
#define DEFN_ASN_OP(op)
Definition: sc_bit.h:177
#define DECL_ASN_OP_T(op, tp)
Definition: sc_fix.h:462
float to_float() const
Definition: sc_fxval.h:1417
sc_fxval_fast_observer * observer() const
Definition: sc_fxval.h:1544
friend void lshift(sc_fxval &, const sc_fxval &, int)
Definition: sc_fxval.h:1088
unsigned int to_uint() const
Definition: sc_fxval.h:2140
sc_fxval_fast_observer * lock_observer() const
sc_enc
Definition: sc_fxdefs.h:63
const std::string to_oct() const
#define DEFN_BIN_OP(ret, op)
Definition: sc_logic.h:325
unsigned int to_uint() const
Definition: sc_fxval.h:1401
unsigned short to_ushort() const
Definition: sc_fxval.h:1361
#define SC_FXVAL_OBSERVER_WRITE_(object)
#define SC_FXVAL_FAST_OBSERVER_WRITE_(object)
sc_fxval(scfx_rep *)
Definition: sc_fxval.h:782
friend void neg(sc_fxval_fast &, const sc_fxval_fast &)
Definition: sc_fxval.h:1663
inline::std::istream & operator>>(::std::istream &is, sc_bit &a)
Definition: sc_bit.h:394
const sc_fxval overflow(const scfx_params &, bool &) const
Definition: sc_fxval.h:1511
#define SC_FXVAL_OBSERVER_READ_(object)
void print(::std::ostream &=::std::cout) const
void unlock_observer(sc_fxval_fast_observer *) const
void dump(::std::ostream &=::std::cout) const
bool is_normal() const
Definition: scfx_rep.h:485
uint64 to_uint64() const
Definition: sc_fxval.h:1385
bool is_inf() const
Definition: sc_fxval.h:2218
bool rounding_flag() const
Definition: scfx_rep.h:514
uint64_t uint64
Definition: sc_nbdefs.h:183
const std::string to_oct() const
scfx_rep * div_scfx_rep(const scfx_rep &, const scfx_rep &, int max_wl=SC_DEFAULT_DIV_WL_)
#define DEFN_CTOR_T_A(tp)
Definition: sc_fxnum.h:3746
bool is_zero() const
Definition: scfx_rep.h:455
void lshift(sc_fxval &c, const sc_fxnum &a, int b)
Definition: sc_fxnum.h:2986
bool get_bit(int) const
#define DEFN_BIN_FNC(fnc)
Definition: sc_fxnum.h:5022
bool is_inf() const
Definition: sc_fxval.h:1460
unsigned long to_ulong() const
Definition: sc_fxval.h:2164
friend void rshift(sc_fxval_fast &, const sc_fxval_fast &, int)
Definition: sc_fxval.h:1852
unsigned short to_ushort() const
Definition: sc_fxval.h:2116
void set_rep(scfx_rep *)
Definition: sc_fxval.h:870
const std::string to_hex() const
bool is_zero() const
Definition: sc_fxval.h:2200
void print(::std::ostream &=::std::cout) const
friend void rshift(sc_fxval &, const sc_fxval &, int)
Definition: sc_fxval.h:1098
const sc_fxval & operator+() const
Definition: sc_fxval.h:890
sc_fxval & operator++()
Definition: sc_fxval.h:1324
#define DEFN_REL_OP(op)
Definition: sc_fxnum.h:4889
scfx_rep * quantization_scfx_rep(const scfx_rep &a, const scfx_params &params, bool &q_flag)
Definition: scfx_rep.h:492
double to_double() const
Definition: sc_fxval.h:2180
bool is_normal() const
Definition: sc_fxval.h:2227
const std::string to_bin() const
const std::string to_dec() const
#define DECL_REL_OP(op)
Definition: sc_fxnum.h:1197
double scfx_pow2(int exp)
Definition: scfx_ieee.h:643
#define DEFN_CTOR_T_B(tp)
Definition: sc_fxnum.h:3747
void neg(sc_fxval &c, const sc_fxnum &a)
Definition: sc_fxnum.h:2687
inline::std::ostream & operator<<(::std::ostream &os, const sc_bit &a)
Definition: sc_bit.h:386
double get_val() const
Definition: sc_fxval.h:1624
const std::string to_bin() const
const sc_fxval_fast & operator+() const
Definition: sc_fxval.h:1652
#define SC_FXVAL_FAST_OBSERVER_READ_(object)
bool is_nan() const
Definition: sc_fxval.h:1452
#define DECL_BIN_OP(op, dummy)
Definition: sc_fxnum.h:1082
const sc_fxval_fast operator-() const
Definition: sc_fxval.h:1644
bool is_neg() const
Definition: scfx_rep.h:448
int to_int() const
Definition: sc_fxval.h:1369
bool is_nan() const
Definition: sc_fxval.h:2209
#define DEFN_CTOR_T_C(tp)
Definition: sc_fxnum.h:3748
sc_fxval_fast(sc_fxval_fast_observer *=0)
Definition: sc_fxval.h:1553
sc_fxval & operator--()
Definition: sc_fxval.h:1332
sc_fxval_fast & operator++()
Definition: sc_fxval.h:2075
int64 to_int64() const
Definition: sc_fxval.h:1377
bool rounding_flag() const
Definition: sc_fxval.h:1477
#define SC_FXVAL_FAST_OBSERVER_CONSTRUCT_(object)
short to_short() const
Definition: sc_fxval.h:2108
const std::string to_dec() const
#define SC_FXVAL_OBSERVER_CONSTRUCT_(object)
DEFN_BIN_OP_T(/, div, int64) DEFN_BIN_OP_T(/
static double from_string(const char *)
sc_fxval_fast & operator--()
Definition: sc_fxval.h:2085
const sc_fxval quantization(const scfx_params &, bool &) const
Definition: sc_fxval.h:1504
DECL_BIN_OP_T(/, int64) DECL_BIN_OP_T(/