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