sc_fxnum.h revision 12027:1eb7dc7aa10b
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_fxnum.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_fxnum.h,v $
39// Revision 1.5  2011/08/29 18:04:32  acg
40//  Philipp A. Hartmann: miscellaneous clean ups.
41//
42// Revision 1.4  2011/08/24 22:05:43  acg
43//  Torsten Maehne: initialization changes to remove warnings.
44//
45// Revision 1.3  2011/01/19 18:57:40  acg
46//  Andy Goodrich: changes for IEEE_1666_2011.
47//
48// Revision 1.2  2009/03/09 17:26:46  acg
49//  Andy Goodrich: removed ; from namespace { }
50//
51// Revision 1.1.1.1  2006/12/15 20:20:04  acg
52// SystemC 2.3
53//
54// Revision 1.3  2006/01/13 18:53:58  acg
55// Andy Goodrich: added $Log command so that CVS comments are reproduced in
56// the source.
57//
58
59#ifndef SC_FXNUM_H
60#define SC_FXNUM_H
61
62
63#include "sysc/datatypes/bit/sc_lv_base.h"
64#include "sysc/datatypes/fx/sc_fxval.h"
65#include "sysc/datatypes/fx/scfx_params.h"
66#include "sysc/datatypes/fx/sc_fxnum_observer.h"
67
68
69namespace sc_core {
70	class vcd_sc_fxnum_trace;
71	class vcd_sc_fxnum_fast_trace;
72	class wif_sc_fxnum_trace;
73	class wif_sc_fxnum_fast_trace;
74}
75
76
77namespace sc_dt
78{
79
80// classes defined in this module
81class sc_fxnum_bitref;
82class sc_fxnum_fast_bitref;
83class sc_fxnum_subref;
84class sc_fxnum_fast_subref;
85class sc_fxnum;
86class sc_fxnum_fast;
87
88
89// ----------------------------------------------------------------------------
90//  CLASS : sc_fxnum_bitref
91//
92//  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
93// ----------------------------------------------------------------------------
94
95class sc_fxnum_bitref
96{
97    friend class sc_fxnum;
98    friend class sc_fxnum_fast_bitref;
99
100
101    bool get() const;
102    void set( bool );
103
104
105    // constructor
106
107    sc_fxnum_bitref( sc_fxnum&, int );
108
109public:
110
111    // copy constructor
112
113    sc_fxnum_bitref( const sc_fxnum_bitref& );
114
115
116    // assignment operators
117
118#define DECL_ASN_OP_T(op,tp)                                                  \
119    sc_fxnum_bitref& operator op ( tp );
120
121#define DECL_ASN_OP(op)                                                       \
122    DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
123    DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
124    DECL_ASN_OP_T(op,const sc_bit&)                                           \
125    DECL_ASN_OP_T(op,bool)
126
127    DECL_ASN_OP(=)
128
129    DECL_ASN_OP(&=)
130    DECL_ASN_OP(|=)
131    DECL_ASN_OP(^=)
132
133#undef DECL_ASN_OP_T
134#undef DECL_ASN_OP
135
136
137    // implicit conversion
138
139    operator bool() const;
140
141
142    // print or dump content
143
144    void print( ::std::ostream& = ::std::cout ) const;
145    void scan( ::std::istream& = ::std::cin );
146    void dump( ::std::ostream& = ::std::cout ) const;
147
148private:
149
150    sc_fxnum& m_num;
151    int       m_idx;
152
153private:
154
155    // disabled
156    sc_fxnum_bitref();
157};
158
159
160// ----------------------------------------------------------------------------
161//  CLASS : sc_fxnum_fast_bitref
162//
163//  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
164// ----------------------------------------------------------------------------
165
166class sc_fxnum_fast_bitref
167{
168    friend class sc_fxnum_fast;
169    friend class sc_fxnum_bitref;
170
171
172    bool get() const;
173    void set( bool );
174
175
176    // constructor
177
178    sc_fxnum_fast_bitref( sc_fxnum_fast&, int );
179
180public:
181
182    // copy constructor
183
184    sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& );
185
186
187    // assignment operators
188
189#define DECL_ASN_OP_T(op,tp)                                                  \
190    sc_fxnum_fast_bitref& operator op ( tp );
191
192#define DECL_ASN_OP(op)                                                       \
193    DECL_ASN_OP_T(op,const sc_fxnum_bitref&)                                  \
194    DECL_ASN_OP_T(op,const sc_fxnum_fast_bitref&)                             \
195    DECL_ASN_OP_T(op,const sc_bit&)                                           \
196    DECL_ASN_OP_T(op,bool)
197
198    DECL_ASN_OP(=)
199
200    DECL_ASN_OP(&=)
201    DECL_ASN_OP(|=)
202    DECL_ASN_OP(^=)
203
204#undef DECL_ASN_OP_T
205#undef DECL_ASN_OP
206
207
208    // implicit conversion
209
210    operator bool() const;
211
212
213    // print or dump content
214
215    void print( ::std::ostream& = ::std::cout ) const;
216    void scan( ::std::istream& = ::std::cin );
217    void dump( ::std::ostream& = ::std::cout ) const;
218
219private:
220
221    sc_fxnum_fast& m_num;
222    int            m_idx;
223
224private:
225
226    // disabled
227    sc_fxnum_fast_bitref();
228};
229
230
231// ----------------------------------------------------------------------------
232//  CLASS : sc_fxnum_subref
233//
234//  Proxy class for part-selection in class sc_fxnum,
235//  behaves like sc_bv_base.
236// ----------------------------------------------------------------------------
237
238class sc_fxnum_subref
239{
240    friend class sc_fxnum;
241    friend class sc_fxnum_fast_subref;
242
243    bool get() const;
244    bool set();
245
246
247    // constructor
248
249    sc_fxnum_subref( sc_fxnum&, int, int );
250
251public:
252
253    // copy constructor
254
255    sc_fxnum_subref( const sc_fxnum_subref& );
256
257
258    // destructor
259
260    ~sc_fxnum_subref();
261
262
263    // assignment operators
264
265#define DECL_ASN_OP_T(tp)                                                     \
266    sc_fxnum_subref& operator = ( tp );
267
268    DECL_ASN_OP_T(const sc_fxnum_subref&)
269    DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
270    DECL_ASN_OP_T(const sc_bv_base&)
271    DECL_ASN_OP_T(const sc_lv_base&)
272    DECL_ASN_OP_T(const char*)
273    DECL_ASN_OP_T(const bool*)
274    DECL_ASN_OP_T(const sc_signed&)
275    DECL_ASN_OP_T(const sc_unsigned&)
276    DECL_ASN_OP_T(const sc_int_base&)
277    DECL_ASN_OP_T(const sc_uint_base&)
278    DECL_ASN_OP_T(int64)
279    DECL_ASN_OP_T(uint64)
280    DECL_ASN_OP_T(int)
281    DECL_ASN_OP_T(unsigned int)
282    DECL_ASN_OP_T(long)
283    DECL_ASN_OP_T(unsigned long)
284    DECL_ASN_OP_T(char)
285
286#undef DECL_ASN_OP_T
287
288#define DECL_ASN_OP_T_A(op,tp)                                                \
289    sc_fxnum_subref& operator op ## = ( tp );
290
291#define DECL_ASN_OP_A(op)                                                     \
292    DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
293    DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
294    DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
295    DECL_ASN_OP_T_A(op,const sc_lv_base&)
296
297    DECL_ASN_OP_A(&)
298    DECL_ASN_OP_A(|)
299    DECL_ASN_OP_A(^)
300
301#undef DECL_ASN_OP_T_A
302#undef DECL_ASN_OP_A
303
304
305    // relational operators
306
307#define DECL_REL_OP_T(op,tp)                                                  \
308    friend bool operator op ( const sc_fxnum_subref&, tp );                   \
309    friend bool operator op ( tp, const sc_fxnum_subref& );
310
311#define DECL_REL_OP(op)                                                       \
312    friend bool operator op ( const sc_fxnum_subref&,                         \
313			      const sc_fxnum_subref& );                       \
314    friend bool operator op ( const sc_fxnum_subref&,                         \
315			      const sc_fxnum_fast_subref& );                  \
316    DECL_REL_OP_T(op,const sc_bv_base&)                                       \
317    DECL_REL_OP_T(op,const sc_lv_base&)                                       \
318    DECL_REL_OP_T(op,const char*)                                             \
319    DECL_REL_OP_T(op,const bool*)                                             \
320    DECL_REL_OP_T(op,const sc_signed&)                                        \
321    DECL_REL_OP_T(op,const sc_unsigned&)                                      \
322    DECL_REL_OP_T(op,int)                                                     \
323    DECL_REL_OP_T(op,unsigned int)                                            \
324    DECL_REL_OP_T(op,long)                                                    \
325    DECL_REL_OP_T(op,unsigned long)
326
327    DECL_REL_OP(==)
328    DECL_REL_OP(!=)
329
330#undef DECL_REL_OP_T
331#undef DECL_REL_OP
332
333
334    // reduce functions
335
336    bool and_reduce() const;
337    bool nand_reduce() const;
338    bool or_reduce() const;
339    bool nor_reduce() const;
340    bool xor_reduce() const;
341    bool xnor_reduce() const;
342
343
344    // query parameter
345
346    int length() const;
347
348
349    // explicit conversions
350
351    int           to_int() const;
352    unsigned int  to_uint() const;
353    long          to_long() const;
354    unsigned long to_ulong() const;
355    int64         to_int64() const;
356    uint64        to_uint64() const;
357
358#ifdef SC_DT_DEPRECATED
359    int           to_signed() const;
360    unsigned int  to_unsigned() const;
361#endif
362
363    const std::string to_string() const;
364    const std::string to_string( sc_numrep ) const;
365    const std::string to_string( sc_numrep, bool ) const;
366
367
368    // implicit conversion
369
370    operator sc_bv_base() const;
371
372
373    // print or dump content
374
375    void print( ::std::ostream& = ::std::cout ) const;
376    void scan( ::std::istream& = ::std::cin );
377    void dump( ::std::ostream& = ::std::cout ) const;
378
379private:
380
381    sc_fxnum& m_num;
382    int       m_from;
383    int       m_to;
384
385    sc_bv_base& m_bv;
386
387private:
388
389    // disabled
390    sc_fxnum_subref();
391};
392
393
394// ----------------------------------------------------------------------------
395//  CLASS : sc_fxnum_fast_subref
396//
397//  Proxy class for part-selection in class sc_fxnum_fast,
398//  behaves like sc_bv_base.
399// ----------------------------------------------------------------------------
400
401class sc_fxnum_fast_subref
402{
403    friend class sc_fxnum_fast;
404    friend class sc_fxnum_subref;
405
406    bool get() const;
407    bool set();
408
409
410    // constructor
411
412    sc_fxnum_fast_subref( sc_fxnum_fast&, int, int );
413
414public:
415
416    // copy constructor
417
418    sc_fxnum_fast_subref( const sc_fxnum_fast_subref& );
419
420
421    // destructor
422
423    ~sc_fxnum_fast_subref();
424
425
426    // assignment operators
427
428#define DECL_ASN_OP_T(tp)                                                     \
429    sc_fxnum_fast_subref& operator = ( tp );
430
431    DECL_ASN_OP_T(const sc_fxnum_subref&)
432    DECL_ASN_OP_T(const sc_fxnum_fast_subref&)
433    DECL_ASN_OP_T(const sc_bv_base&)
434    DECL_ASN_OP_T(const sc_lv_base&)
435    DECL_ASN_OP_T(const char*)
436    DECL_ASN_OP_T(const bool*)
437    DECL_ASN_OP_T(const sc_signed&)
438    DECL_ASN_OP_T(const sc_unsigned&)
439    DECL_ASN_OP_T(const sc_int_base&)
440    DECL_ASN_OP_T(const sc_uint_base&)
441    DECL_ASN_OP_T(int64)
442    DECL_ASN_OP_T(uint64)
443    DECL_ASN_OP_T(int)
444    DECL_ASN_OP_T(unsigned int)
445    DECL_ASN_OP_T(long)
446    DECL_ASN_OP_T(unsigned long)
447    DECL_ASN_OP_T(char)
448
449#undef DECL_ASN_OP_T
450
451#define DECL_ASN_OP_T_A(op,tp)                                                \
452    sc_fxnum_fast_subref& operator op ## = ( tp );
453
454#define DECL_ASN_OP_A(op)                                                     \
455    DECL_ASN_OP_T_A(op,const sc_fxnum_subref&)                                \
456    DECL_ASN_OP_T_A(op,const sc_fxnum_fast_subref&)                           \
457    DECL_ASN_OP_T_A(op,const sc_bv_base&)                                     \
458    DECL_ASN_OP_T_A(op,const sc_lv_base&)
459
460    DECL_ASN_OP_A(&)
461    DECL_ASN_OP_A(|)
462    DECL_ASN_OP_A(^)
463
464#undef DECL_ASN_OP_T_A
465#undef DECL_ASN_OP_A
466
467
468    // relational operators
469
470#define DECL_REL_OP_T(op,tp)                                                  \
471    friend bool operator op ( const sc_fxnum_fast_subref&, tp );              \
472    friend bool operator op ( tp, const sc_fxnum_fast_subref& );
473
474#define DECL_REL_OP(op)                                                       \
475    friend bool operator op ( const sc_fxnum_fast_subref&,                    \
476			      const sc_fxnum_fast_subref& );                  \
477    friend bool operator op ( const sc_fxnum_fast_subref&,                    \
478			      const sc_fxnum_subref& );                       \
479    DECL_REL_OP_T(op,const sc_bv_base&)                                       \
480    DECL_REL_OP_T(op,const sc_lv_base&)                                       \
481    DECL_REL_OP_T(op,const char*)                                             \
482    DECL_REL_OP_T(op,const bool*)                                             \
483    DECL_REL_OP_T(op,const sc_signed&)                                        \
484    DECL_REL_OP_T(op,const sc_unsigned&)                                      \
485    DECL_REL_OP_T(op,int)                                                     \
486    DECL_REL_OP_T(op,unsigned int)                                            \
487    DECL_REL_OP_T(op,long)                                                    \
488    DECL_REL_OP_T(op,unsigned long)
489
490    DECL_REL_OP(==)
491    DECL_REL_OP(!=)
492
493#undef DECL_REL_OP_T
494#undef DECL_REL_OP
495
496
497    // reduce functions
498
499    bool and_reduce() const;
500    bool nand_reduce() const;
501    bool or_reduce() const;
502    bool nor_reduce() const;
503    bool xor_reduce() const;
504    bool xnor_reduce() const;
505
506
507    // query parameter
508
509    int length() const;
510
511
512    // explicit conversions
513
514    int           to_int() const;
515    unsigned int  to_uint() const;
516    long          to_long() const;
517    unsigned long to_ulong() const;
518    int64         to_int64() const;
519    uint64        to_uint64() const;
520
521#ifdef SC_DT_DEPRECATED
522    int           to_signed() const;
523    unsigned int  to_unsigned() const;
524#endif
525
526    const std::string to_string() const;
527    const std::string to_string( sc_numrep ) const;
528    const std::string to_string( sc_numrep, bool ) const;
529
530
531    // implicit conversion
532
533    operator sc_bv_base() const;
534
535
536    // print or dump content
537
538    void print( ::std::ostream& = ::std::cout ) const;
539    void scan( ::std::istream& = ::std::cin );
540    void dump( ::std::ostream& = ::std::cout ) const;
541
542private:
543
544    sc_fxnum_fast& m_num;
545    int            m_from;
546    int            m_to;
547
548    sc_bv_base& m_bv;
549
550private:
551
552    // disabled
553    sc_fxnum_fast_subref();
554};
555
556
557// ----------------------------------------------------------------------------
558//  CLASS : sc_fxnum
559//
560//  Base class for the fixed-point types; arbitrary precision.
561// ----------------------------------------------------------------------------
562
563class sc_fxnum
564{
565    friend class sc_fxval;
566
567    friend class sc_fxnum_bitref;
568    friend class sc_fxnum_subref;
569    friend class sc_fxnum_fast_bitref;
570    friend class sc_fxnum_fast_subref;
571
572    friend class sc_core::vcd_sc_fxnum_trace;
573    friend class sc_core::wif_sc_fxnum_trace;
574
575protected:
576
577    sc_fxnum_observer* observer() const;
578
579
580    void cast();
581
582
583    // constructors
584
585    sc_fxnum( const sc_fxtype_params&,
586	      sc_enc,
587	      const sc_fxcast_switch&,
588	      sc_fxnum_observer* );
589
590#define DECL_CTOR_T(tp)                                                       \
591    sc_fxnum( tp,                                                             \
592	      const sc_fxtype_params&,                                        \
593	      sc_enc,                                                         \
594	      const sc_fxcast_switch&,                                        \
595	      sc_fxnum_observer* );
596
597    DECL_CTOR_T(int)
598    DECL_CTOR_T(unsigned int)
599    DECL_CTOR_T(long)
600    DECL_CTOR_T(unsigned long)
601    DECL_CTOR_T(float)
602    DECL_CTOR_T(double)
603    DECL_CTOR_T(const char*)
604    DECL_CTOR_T(const sc_fxval&)
605    DECL_CTOR_T(const sc_fxval_fast&)
606    DECL_CTOR_T(const sc_fxnum&)
607    DECL_CTOR_T(const sc_fxnum_fast&)
608#ifndef SC_FX_EXCLUDE_OTHER
609    DECL_CTOR_T(int64)
610    DECL_CTOR_T(uint64)
611    DECL_CTOR_T(const sc_int_base&)
612    DECL_CTOR_T(const sc_uint_base&)
613    DECL_CTOR_T(const sc_signed&)
614    DECL_CTOR_T(const sc_unsigned&)
615#endif
616
617#undef DECL_CTOR_T
618
619    ~sc_fxnum();
620
621
622    // internal use only;
623    const scfx_rep* get_rep() const;
624
625public:
626
627    // unary operators
628
629    const sc_fxval operator - () const;
630    const sc_fxval operator + () const;
631
632
633    // unary functions
634
635    friend void neg( sc_fxval&, const sc_fxnum& );
636    friend void neg( sc_fxnum&, const sc_fxnum& );
637
638
639    // binary operators
640
641#define DECL_BIN_OP_T(op,tp)                                                  \
642    friend const sc_fxval operator op ( const sc_fxnum&, tp );                \
643    friend const sc_fxval operator op ( tp, const sc_fxnum& );
644
645#ifndef SC_FX_EXCLUDE_OTHER
646#define DECL_BIN_OP_OTHER(op)                                                 \
647    DECL_BIN_OP_T(op,int64)                                                   \
648    DECL_BIN_OP_T(op,uint64)                                                  \
649    DECL_BIN_OP_T(op,const sc_int_base&)                                      \
650    DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
651    DECL_BIN_OP_T(op,const sc_signed&)                                        \
652    DECL_BIN_OP_T(op,const sc_unsigned&)
653#else
654#define DECL_BIN_OP_OTHER(op)
655#endif
656
657#define DECL_BIN_OP(op,dummy)                                                 \
658    friend const sc_fxval operator op ( const sc_fxnum&, const sc_fxnum& );   \
659    DECL_BIN_OP_T(op,int)                                                     \
660    DECL_BIN_OP_T(op,unsigned int)                                            \
661    DECL_BIN_OP_T(op,long)                                                    \
662    DECL_BIN_OP_T(op,unsigned long)                                           \
663    DECL_BIN_OP_T(op,float)                                                  \
664    DECL_BIN_OP_T(op,double)                                                  \
665    DECL_BIN_OP_T(op,const char*)                                             \
666    DECL_BIN_OP_T(op,const sc_fxval&)                                         \
667    DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
668    DECL_BIN_OP_T(op,const sc_fxnum_fast&)                                    \
669    DECL_BIN_OP_OTHER(op)
670
671    DECL_BIN_OP(*,mult)
672    DECL_BIN_OP(+,add)
673    DECL_BIN_OP(-,sub)
674// don't use macros
675//    DECL_BIN_OP(/,div)
676    friend const sc_fxval operator / ( const sc_fxnum&, const sc_fxnum& );
677    DECL_BIN_OP_T(/,int)
678    DECL_BIN_OP_T(/,unsigned int)
679    DECL_BIN_OP_T(/,long)
680    DECL_BIN_OP_T(/,unsigned long)
681    DECL_BIN_OP_T(/,float)
682    DECL_BIN_OP_T(/,double)
683    DECL_BIN_OP_T(/,const char*)
684    DECL_BIN_OP_T(/,const sc_fxval&)
685    DECL_BIN_OP_T(/,const sc_fxval_fast&)
686    DECL_BIN_OP_T(/,const sc_fxnum_fast&)
687//    DECL_BIN_OP_OTHER(op)
688#ifndef SC_FX_EXCLUDE_OTHER
689    DECL_BIN_OP_T(/,int64)
690    DECL_BIN_OP_T(/,uint64)
691    DECL_BIN_OP_T(/,const sc_int_base&)
692    DECL_BIN_OP_T(/,const sc_uint_base&)
693    DECL_BIN_OP_T(/,const sc_signed&)
694    DECL_BIN_OP_T(/,const sc_unsigned&)
695#endif
696
697#undef DECL_BIN_OP_T
698#undef DECL_BIN_OP_OTHER
699#undef DECL_BIN_OP
700
701    friend const sc_fxval operator << ( const sc_fxnum&, int );
702    friend const sc_fxval operator >> ( const sc_fxnum&, int );
703
704
705    // binary functions
706
707#define DECL_BIN_FNC_T(fnc,tp)                                                \
708    friend void fnc ( sc_fxval&, const sc_fxnum&, tp );                       \
709    friend void fnc ( sc_fxval&, tp, const sc_fxnum& );                       \
710    friend void fnc ( sc_fxnum&, const sc_fxnum&, tp );                       \
711    friend void fnc ( sc_fxnum&, tp, const sc_fxnum& );
712
713#ifndef SC_FX_EXCLUDE_OTHER
714#define DECL_BIN_FNC_OTHER(fnc)                                               \
715    DECL_BIN_FNC_T(fnc,int64)                                                 \
716    DECL_BIN_FNC_T(fnc,uint64)                                                \
717    DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
718    DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
719    DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
720    DECL_BIN_FNC_T(fnc,const sc_unsigned&)
721#else
722#define DECL_BIN_FNC_OTHER(fnc)
723#endif
724
725#define DECL_BIN_FNC(fnc)                                                     \
726    friend void fnc ( sc_fxval&, const sc_fxnum&, const sc_fxnum& );          \
727    friend void fnc ( sc_fxnum&, const sc_fxnum&, const sc_fxnum& );          \
728    DECL_BIN_FNC_T(fnc,int)                                                   \
729    DECL_BIN_FNC_T(fnc,unsigned int)                                          \
730    DECL_BIN_FNC_T(fnc,long)                                                  \
731    DECL_BIN_FNC_T(fnc,unsigned long)                                         \
732    DECL_BIN_FNC_T(fnc,float)                                                \
733    DECL_BIN_FNC_T(fnc,double)                                                \
734    DECL_BIN_FNC_T(fnc,const char*)                                           \
735    DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
736    DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
737    DECL_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                  \
738    DECL_BIN_FNC_OTHER(fnc)
739
740    DECL_BIN_FNC(mult)
741    DECL_BIN_FNC(div)
742    DECL_BIN_FNC(add)
743    DECL_BIN_FNC(sub)
744
745#undef DECL_BIN_FNC_T
746#undef DECL_BIN_FNC_OTHER
747#undef DECL_BIN_FNC
748
749    friend void lshift( sc_fxval&, const sc_fxnum&, int );
750    friend void rshift( sc_fxval&, const sc_fxnum&, int );
751    friend void lshift( sc_fxnum&, const sc_fxnum&, int );
752    friend void rshift( sc_fxnum&, const sc_fxnum&, int );
753
754
755    // relational (including equality) operators
756
757#define DECL_REL_OP_T(op,tp)                                                  \
758    friend bool operator op ( const sc_fxnum&, tp );                          \
759    friend bool operator op ( tp, const sc_fxnum& );
760
761#ifndef SC_FX_EXCLUDE_OTHER
762#define DECL_REL_OP_OTHER(op)                                                 \
763    DECL_REL_OP_T(op,int64)                                                   \
764    DECL_REL_OP_T(op,uint64)                                                  \
765    DECL_REL_OP_T(op,const sc_int_base&)                                      \
766    DECL_REL_OP_T(op,const sc_uint_base&)                                     \
767    DECL_REL_OP_T(op,const sc_signed&)                                        \
768    DECL_REL_OP_T(op,const sc_unsigned&)
769#else
770#define DECL_REL_OP_OTHER(op)
771#endif
772
773#define DECL_REL_OP(op)                                                       \
774    friend bool operator op ( const sc_fxnum&, const sc_fxnum& );             \
775    DECL_REL_OP_T(op,int)                                                     \
776    DECL_REL_OP_T(op,unsigned int)                                            \
777    DECL_REL_OP_T(op,long)                                                    \
778    DECL_REL_OP_T(op,unsigned long)                                           \
779    DECL_REL_OP_T(op,float)                                                  \
780    DECL_REL_OP_T(op,double)                                                  \
781    DECL_REL_OP_T(op,const char*)                                             \
782    DECL_REL_OP_T(op,const sc_fxval&)                                         \
783    DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
784    DECL_REL_OP_T(op,const sc_fxnum_fast&)                                    \
785    DECL_REL_OP_OTHER(op)
786
787    DECL_REL_OP(<)
788    DECL_REL_OP(<=)
789    DECL_REL_OP(>)
790    DECL_REL_OP(>=)
791    DECL_REL_OP(==)
792    DECL_REL_OP(!=)
793
794#undef DECL_REL_OP_T
795#undef DECL_REL_OP_OTHER
796#undef DECL_REL_OP
797
798
799    // assignment operators
800
801#define DECL_ASN_OP_T(op,tp)                                                  \
802    sc_fxnum& operator op( tp );
803
804#ifndef SC_FX_EXCLUDE_OTHER
805#define DECL_ASN_OP_OTHER(op)                                                 \
806    DECL_ASN_OP_T(op,int64)                                                   \
807    DECL_ASN_OP_T(op,uint64)                                                  \
808    DECL_ASN_OP_T(op,const sc_int_base&)                                      \
809    DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
810    DECL_ASN_OP_T(op,const sc_signed&)                                        \
811    DECL_ASN_OP_T(op,const sc_unsigned&)
812#else
813#define DECL_ASN_OP_OTHER(op)
814#endif
815
816#define DECL_ASN_OP(op)                                                       \
817    DECL_ASN_OP_T(op,int)                                                     \
818    DECL_ASN_OP_T(op,unsigned int)                                            \
819    DECL_ASN_OP_T(op,long)                                                    \
820    DECL_ASN_OP_T(op,unsigned long)                                           \
821    DECL_ASN_OP_T(op,float)                                                  \
822    DECL_ASN_OP_T(op,double)                                                  \
823    DECL_ASN_OP_T(op,const char*)                                             \
824    DECL_ASN_OP_T(op,const sc_fxval&)                                         \
825    DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
826    DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
827    DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
828    DECL_ASN_OP_OTHER(op)
829
830    DECL_ASN_OP(=)
831
832    DECL_ASN_OP(*=)
833    DECL_ASN_OP(/=)
834    DECL_ASN_OP(+=)
835    DECL_ASN_OP(-=)
836
837    DECL_ASN_OP_T(<<=,int)
838    DECL_ASN_OP_T(>>=,int)
839
840#undef DECL_ASN_OP_T
841#undef DECL_ASN_OP_OTHER
842#undef DECL_ASN_OP
843
844
845    // auto-increment and auto-decrement
846
847    const sc_fxval operator ++ ( int );
848    const sc_fxval operator -- ( int );
849
850    sc_fxnum& operator ++ ();
851    sc_fxnum& operator -- ();
852
853
854    // bit selection
855
856    const sc_fxnum_bitref operator [] ( int ) const;
857    sc_fxnum_bitref       operator [] ( int );
858
859    const sc_fxnum_bitref bit( int ) const;
860    sc_fxnum_bitref       bit( int );
861
862
863    // part selection
864
865    const sc_fxnum_subref operator () ( int, int ) const;
866    sc_fxnum_subref       operator () ( int, int );
867
868    const sc_fxnum_subref range( int, int ) const;
869    sc_fxnum_subref       range( int, int );
870
871
872    const sc_fxnum_subref operator () () const;
873    sc_fxnum_subref       operator () ();
874
875    const sc_fxnum_subref range() const;
876    sc_fxnum_subref       range();
877
878
879    // implicit conversion
880
881    operator double() const;		// necessary evil!
882
883
884    // explicit conversion to primitive types
885
886    short          to_short() const;
887    unsigned short to_ushort() const;
888    int            to_int() const;
889    unsigned int   to_uint() const;
890    long           to_long() const;
891    unsigned long  to_ulong() const;
892    int64          to_int64() const;
893    uint64         to_uint64() const;
894    float          to_float() const;
895    double         to_double() const;
896
897
898    // explicit conversion to character string
899
900    const std::string to_string() const;
901    const std::string to_string( sc_numrep ) const;
902    const std::string to_string( sc_numrep, bool ) const;
903    const std::string to_string( sc_fmt ) const;
904    const std::string to_string( sc_numrep, sc_fmt ) const;
905    const std::string to_string( sc_numrep, bool, sc_fmt ) const;
906
907    const std::string to_dec() const;
908    const std::string to_bin() const;
909    const std::string to_oct() const;
910    const std::string to_hex() const;
911
912
913    // query value
914
915    bool is_neg() const;
916    bool is_zero() const;
917
918    // internal use only;
919    bool is_normal() const;
920
921    bool quantization_flag() const;
922    bool overflow_flag() const;
923
924    const sc_fxval value() const;
925
926
927    // query parameters
928
929    int       wl() const;
930    int       iwl() const;
931    sc_q_mode q_mode() const;
932    sc_o_mode o_mode() const;
933    int       n_bits() const;
934
935    const sc_fxtype_params& type_params() const;
936
937    const sc_fxcast_switch& cast_switch() const;
938
939
940    // print or dump content
941
942    void print( ::std::ostream& = ::std::cout ) const;
943    void scan( ::std::istream& = ::std::cin );
944    void dump( ::std::ostream& = ::std::cout ) const;
945
946
947    // internal use only;
948    void observer_read() const;
949
950
951    // internal use only;
952    bool get_bit( int ) const;
953
954protected:
955
956    bool set_bit( int, bool );
957
958
959    bool get_slice( int, int, sc_bv_base& ) const;
960    bool set_slice( int, int, const sc_bv_base& );
961
962
963    sc_fxnum_observer* lock_observer() const;
964    void unlock_observer( sc_fxnum_observer* ) const;
965
966private:
967
968    scfx_rep*                  m_rep;
969
970    scfx_params                m_params;
971    bool                       m_q_flag;
972    bool                       m_o_flag;
973
974    mutable sc_fxnum_observer* m_observer;
975
976private:
977
978    // disabled
979    sc_fxnum();
980    sc_fxnum( const sc_fxnum& );
981};
982
983
984// ----------------------------------------------------------------------------
985//  CLASS : sc_fxnum_fast
986//
987//  Base class for the fixed-point types; limited precision.
988// ----------------------------------------------------------------------------
989
990class sc_fxnum_fast
991{
992    friend class sc_fxval_fast;
993
994    friend class sc_fxnum_bitref;
995    friend class sc_fxnum_subref;
996    friend class sc_fxnum_fast_bitref;
997    friend class sc_fxnum_fast_subref;
998
999    friend class sc_core::vcd_sc_fxnum_fast_trace;
1000    friend class sc_core::wif_sc_fxnum_fast_trace;
1001
1002protected:
1003
1004    sc_fxnum_fast_observer* observer() const;
1005
1006
1007    void cast();
1008
1009
1010    // constructors
1011
1012    sc_fxnum_fast( const sc_fxtype_params&,
1013		   sc_enc,
1014		   const sc_fxcast_switch&,
1015		   sc_fxnum_fast_observer* );
1016
1017#define DECL_CTOR_T(tp)                                                       \
1018    sc_fxnum_fast( tp,                                                        \
1019	           const sc_fxtype_params&,                                   \
1020	           sc_enc,                                                    \
1021	           const sc_fxcast_switch&,                                   \
1022	           sc_fxnum_fast_observer* );
1023
1024    DECL_CTOR_T(int)
1025    DECL_CTOR_T(unsigned int)
1026    DECL_CTOR_T(long)
1027    DECL_CTOR_T(unsigned long)
1028    DECL_CTOR_T(float)
1029    DECL_CTOR_T(double)
1030    DECL_CTOR_T(const char*)
1031    DECL_CTOR_T(const sc_fxval&)
1032    DECL_CTOR_T(const sc_fxval_fast&)
1033    DECL_CTOR_T(const sc_fxnum&)
1034    DECL_CTOR_T(const sc_fxnum_fast&)
1035#ifndef SC_FX_EXCLUDE_OTHER
1036    DECL_CTOR_T(int64)
1037    DECL_CTOR_T(uint64)
1038    DECL_CTOR_T(const sc_int_base&)
1039    DECL_CTOR_T(const sc_uint_base&)
1040    DECL_CTOR_T(const sc_signed&)
1041    DECL_CTOR_T(const sc_unsigned&)
1042#endif
1043
1044#undef DECL_CTOR_T
1045
1046    ~sc_fxnum_fast();
1047
1048
1049    // internal use only;
1050    double get_val() const;
1051
1052public:
1053
1054    // unary operators
1055
1056    const sc_fxval_fast operator - () const;
1057    const sc_fxval_fast operator + () const;
1058
1059
1060    // unary functions
1061
1062    friend void neg( sc_fxval_fast&, const sc_fxnum_fast& );
1063    friend void neg( sc_fxnum_fast&, const sc_fxnum_fast& );
1064
1065
1066    // binary operators
1067
1068#define DECL_BIN_OP_T(op,tp)                                                  \
1069    friend const sc_fxval_fast operator op ( const sc_fxnum_fast&, tp );      \
1070    friend const sc_fxval_fast operator op ( tp, const sc_fxnum_fast& );
1071
1072#ifndef SC_FX_EXCLUDE_OTHER
1073#define DECL_BIN_OP_OTHER(op)                                                 \
1074    DECL_BIN_OP_T(op,int64)                                                   \
1075    DECL_BIN_OP_T(op,uint64)                                                  \
1076    DECL_BIN_OP_T(op,const sc_int_base&)                                      \
1077    DECL_BIN_OP_T(op,const sc_uint_base&)                                     \
1078    DECL_BIN_OP_T(op,const sc_signed&)                                        \
1079    DECL_BIN_OP_T(op,const sc_unsigned&)
1080#else
1081#define DECL_BIN_OP_OTHER(op)
1082#endif
1083
1084#define DECL_BIN_OP(op,dummy)                                                 \
1085    friend const sc_fxval_fast operator op ( const sc_fxnum_fast&,            \
1086					     const sc_fxnum_fast& );          \
1087    DECL_BIN_OP_T(op,int)                                                     \
1088    DECL_BIN_OP_T(op,unsigned int)                                            \
1089    DECL_BIN_OP_T(op,long)                                                    \
1090    DECL_BIN_OP_T(op,unsigned long)                                           \
1091    DECL_BIN_OP_T(op,float)                                                  \
1092    DECL_BIN_OP_T(op,double)                                                  \
1093    DECL_BIN_OP_T(op,const char*)                                             \
1094    DECL_BIN_OP_T(op,const sc_fxval_fast&)                                    \
1095    DECL_BIN_OP_OTHER(op)
1096
1097    DECL_BIN_OP(*,mult)
1098    DECL_BIN_OP(+,add)
1099    DECL_BIN_OP(-,sub)
1100//    DECL_BIN_OP(/,div)
1101    friend const sc_fxval_fast operator / ( const sc_fxnum_fast&,
1102					     const sc_fxnum_fast& );
1103    DECL_BIN_OP_T(/,int)
1104    DECL_BIN_OP_T(/,unsigned int)
1105    DECL_BIN_OP_T(/,long)
1106    DECL_BIN_OP_T(/,unsigned long)
1107    DECL_BIN_OP_T(/,float)
1108    DECL_BIN_OP_T(/,double)
1109    DECL_BIN_OP_T(/,const char*)
1110    DECL_BIN_OP_T(/,const sc_fxval_fast&)
1111//    DECL_BIN_OP_OTHER(op)
1112#ifndef SC_FX_EXCLUDE_OTHER
1113    DECL_BIN_OP_T(/,int64)                                                   \
1114    DECL_BIN_OP_T(/,uint64)                                                  \
1115    DECL_BIN_OP_T(/,const sc_int_base&)                                      \
1116    DECL_BIN_OP_T(/,const sc_uint_base&)                                     \
1117    DECL_BIN_OP_T(/,const sc_signed&)                                        \
1118    DECL_BIN_OP_T(/,const sc_unsigned&)
1119#endif
1120
1121#undef DECL_BIN_OP_T
1122#undef DECL_BIN_OP_OTHER
1123#undef DECL_BIN_OP
1124
1125    friend const sc_fxval_fast operator << ( const sc_fxnum_fast&, int );
1126    friend const sc_fxval_fast operator >> ( const sc_fxnum_fast&, int );
1127
1128
1129    // binary functions
1130
1131#define DECL_BIN_FNC_T(fnc,tp)                                                \
1132    friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&, tp );             \
1133    friend void fnc ( sc_fxval_fast&, tp, const sc_fxnum_fast& );             \
1134    friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&, tp );             \
1135    friend void fnc ( sc_fxnum_fast&, tp, const sc_fxnum_fast& );
1136
1137#ifndef SC_FX_EXCLUDE_OTHER
1138#define DECL_BIN_FNC_OTHER(fnc)                                               \
1139    DECL_BIN_FNC_T(fnc,int64)                                                 \
1140    DECL_BIN_FNC_T(fnc,uint64)                                                \
1141    DECL_BIN_FNC_T(fnc,const sc_int_base&)                                    \
1142    DECL_BIN_FNC_T(fnc,const sc_uint_base&)                                   \
1143    DECL_BIN_FNC_T(fnc,const sc_signed&)                                      \
1144    DECL_BIN_FNC_T(fnc,const sc_unsigned&)
1145#else
1146#define DECL_BIN_FNC_OTHER(fnc)
1147#endif
1148
1149#define DECL_BIN_FNC(fnc)                                                     \
1150    friend void fnc ( sc_fxval_fast&, const sc_fxnum_fast&,                   \
1151		                      const sc_fxnum_fast& );                 \
1152    friend void fnc ( sc_fxnum_fast&, const sc_fxnum_fast&,                   \
1153		                      const sc_fxnum_fast& );                 \
1154    DECL_BIN_FNC_T(fnc,int)                                                   \
1155    DECL_BIN_FNC_T(fnc,unsigned int)                                          \
1156    DECL_BIN_FNC_T(fnc,long)                                                  \
1157    DECL_BIN_FNC_T(fnc,unsigned long)                                         \
1158    DECL_BIN_FNC_T(fnc,float)                                                \
1159    DECL_BIN_FNC_T(fnc,double)                                                \
1160    DECL_BIN_FNC_T(fnc,const char*)                                           \
1161    DECL_BIN_FNC_T(fnc,const sc_fxval&)                                       \
1162    DECL_BIN_FNC_T(fnc,const sc_fxval_fast&)                                  \
1163    DECL_BIN_FNC_T(fnc,const sc_fxnum&)                                       \
1164    DECL_BIN_FNC_OTHER(fnc)
1165
1166    DECL_BIN_FNC(mult)
1167    DECL_BIN_FNC(div)
1168    DECL_BIN_FNC(add)
1169    DECL_BIN_FNC(sub)
1170
1171#undef DECL_BIN_FNC_T
1172#undef DECL_BIN_FNC_OTHER
1173#undef DECL_BIN_FNC
1174
1175    friend void lshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
1176    friend void rshift( sc_fxval_fast&, const sc_fxnum_fast&, int );
1177    friend void lshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
1178    friend void rshift( sc_fxnum_fast&, const sc_fxnum_fast&, int );
1179
1180
1181    // relational (including equality) operators
1182
1183#define DECL_REL_OP_T(op,tp)                                                  \
1184    friend bool operator op ( const sc_fxnum_fast&, tp );                     \
1185    friend bool operator op ( tp, const sc_fxnum_fast& );
1186
1187#ifndef SC_FX_EXCLUDE_OTHER
1188#define DECL_REL_OP_OTHER(op)                                                 \
1189    DECL_REL_OP_T(op,int64)                                                   \
1190    DECL_REL_OP_T(op,uint64)                                                  \
1191    DECL_REL_OP_T(op,const sc_int_base&)                                      \
1192    DECL_REL_OP_T(op,const sc_uint_base&)                                     \
1193    DECL_REL_OP_T(op,const sc_signed&)                                        \
1194    DECL_REL_OP_T(op,const sc_unsigned&)
1195#else
1196#define DECL_REL_OP_OTHER(op)
1197#endif
1198
1199#define DECL_REL_OP(op)                                                       \
1200    friend bool operator op ( const sc_fxnum_fast&, const sc_fxnum_fast& );   \
1201    DECL_REL_OP_T(op,int)                                                     \
1202    DECL_REL_OP_T(op,unsigned int)                                            \
1203    DECL_REL_OP_T(op,long)                                                    \
1204    DECL_REL_OP_T(op,unsigned long)                                           \
1205    DECL_REL_OP_T(op,float)                                                  \
1206    DECL_REL_OP_T(op,double)                                                  \
1207    DECL_REL_OP_T(op,const char*)                                             \
1208    DECL_REL_OP_T(op,const sc_fxval_fast&)                                    \
1209    DECL_REL_OP_OTHER(op)
1210
1211    DECL_REL_OP(<)
1212    DECL_REL_OP(<=)
1213    DECL_REL_OP(>)
1214    DECL_REL_OP(>=)
1215    DECL_REL_OP(==)
1216    DECL_REL_OP(!=)
1217
1218#undef DECL_REL_OP_T
1219#undef DECL_REL_OP_OTHER
1220#undef DECL_REL_OP
1221
1222
1223    // assignment operators
1224
1225#define DECL_ASN_OP_T(op,tp)                                                  \
1226    sc_fxnum_fast& operator op( tp );
1227
1228#ifndef SC_FX_EXCLUDE_OTHER
1229#define DECL_ASN_OP_OTHER(op)                                                 \
1230    DECL_ASN_OP_T(op,int64)                                                   \
1231    DECL_ASN_OP_T(op,uint64)                                                  \
1232    DECL_ASN_OP_T(op,const sc_int_base&)                                      \
1233    DECL_ASN_OP_T(op,const sc_uint_base&)                                     \
1234    DECL_ASN_OP_T(op,const sc_signed&)                                        \
1235    DECL_ASN_OP_T(op,const sc_unsigned&)
1236#else
1237#define DECL_ASN_OP_OTHER(op)
1238#endif
1239
1240#define DECL_ASN_OP(op)                                                       \
1241    DECL_ASN_OP_T(op,int)                                                     \
1242    DECL_ASN_OP_T(op,unsigned int)                                            \
1243    DECL_ASN_OP_T(op,long)                                                    \
1244    DECL_ASN_OP_T(op,unsigned long)                                           \
1245    DECL_ASN_OP_T(op,float)                                                  \
1246    DECL_ASN_OP_T(op,double)                                                  \
1247    DECL_ASN_OP_T(op,const char*)                                             \
1248    DECL_ASN_OP_T(op,const sc_fxval&)                                         \
1249    DECL_ASN_OP_T(op,const sc_fxval_fast&)                                    \
1250    DECL_ASN_OP_T(op,const sc_fxnum&)                                         \
1251    DECL_ASN_OP_T(op,const sc_fxnum_fast&)                                    \
1252    DECL_ASN_OP_OTHER(op)
1253
1254    DECL_ASN_OP(=)
1255
1256    DECL_ASN_OP(*=)
1257    DECL_ASN_OP(/=)
1258    DECL_ASN_OP(+=)
1259    DECL_ASN_OP(-=)
1260
1261    DECL_ASN_OP_T(<<=,int)
1262    DECL_ASN_OP_T(>>=,int)
1263
1264#undef DECL_ASN_OP_T
1265#undef DECL_ASN_OP_OTHER
1266#undef DECL_ASN_OP
1267
1268
1269    // auto-increment and auto-decrement
1270
1271    const sc_fxval_fast operator ++ ( int );
1272    const sc_fxval_fast operator -- ( int );
1273
1274    sc_fxnum_fast& operator ++ ();
1275    sc_fxnum_fast& operator -- ();
1276
1277
1278    // bit selection
1279
1280    const sc_fxnum_fast_bitref operator [] ( int ) const;
1281    sc_fxnum_fast_bitref       operator [] ( int );
1282
1283    const sc_fxnum_fast_bitref bit( int ) const;
1284    sc_fxnum_fast_bitref       bit( int );
1285
1286
1287    // part selection
1288
1289    const sc_fxnum_fast_subref operator () ( int, int ) const;
1290    sc_fxnum_fast_subref       operator () ( int, int );
1291
1292    const sc_fxnum_fast_subref range( int, int ) const;
1293    sc_fxnum_fast_subref       range( int, int );
1294
1295
1296    const sc_fxnum_fast_subref operator () () const;
1297    sc_fxnum_fast_subref       operator () ();
1298
1299    const sc_fxnum_fast_subref range() const;
1300    sc_fxnum_fast_subref       range();
1301
1302
1303    // implicit conversion
1304
1305    operator double() const;		// necessary evil!
1306
1307
1308    // explicit conversion to primitive types
1309
1310    short          to_short() const;
1311    unsigned short to_ushort() const;
1312    int            to_int() const;
1313    unsigned int   to_uint() const;
1314    long           to_long() const;
1315    unsigned long  to_ulong() const;
1316    int64          to_int64() const;
1317    uint64         to_uint64() const;
1318    float          to_float() const;
1319    double         to_double() const;
1320
1321
1322    // explicit conversion to character string
1323
1324    const std::string to_string() const;
1325    const std::string to_string( sc_numrep ) const;
1326    const std::string to_string( sc_numrep, bool ) const;
1327    const std::string to_string( sc_fmt ) const;
1328    const std::string to_string( sc_numrep, sc_fmt ) const;
1329    const std::string to_string( sc_numrep, bool, sc_fmt ) const;
1330
1331    const std::string to_dec() const;
1332    const std::string to_bin() const;
1333    const std::string to_oct() const;
1334    const std::string to_hex() const;
1335
1336
1337    // query value
1338
1339    bool is_neg() const;
1340    bool is_zero() const;
1341
1342    // internal use only;
1343    bool is_normal() const;
1344
1345    bool quantization_flag() const;
1346    bool overflow_flag() const;
1347
1348    const sc_fxval_fast value() const;
1349
1350
1351    // query parameters
1352
1353    int       wl() const;
1354    int       iwl() const;
1355    sc_q_mode q_mode() const;
1356    sc_o_mode o_mode() const;
1357    int       n_bits() const;
1358
1359    const sc_fxtype_params& type_params() const;
1360
1361    const sc_fxcast_switch& cast_switch() const;
1362
1363
1364    // print or dump content
1365
1366    void print( ::std::ostream& = ::std::cout ) const;
1367    void scan( ::std::istream& = ::std::cin );
1368    void dump( ::std::ostream& = ::std::cout ) const;
1369
1370
1371    // internal use only;
1372    void observer_read() const;
1373
1374
1375    // internal use only;
1376    bool get_bit( int ) const;
1377
1378protected:
1379
1380    bool set_bit( int, bool );
1381
1382
1383    bool get_slice( int, int, sc_bv_base& ) const;
1384    bool set_slice( int, int, const sc_bv_base& );
1385
1386
1387    sc_fxnum_fast_observer* lock_observer() const;
1388    void unlock_observer( sc_fxnum_fast_observer* ) const;
1389
1390private:
1391
1392    double                          m_val;
1393
1394    scfx_params                     m_params;
1395    bool                            m_q_flag;
1396    bool                            m_o_flag;
1397
1398    mutable sc_fxnum_fast_observer* m_observer;
1399
1400private:
1401
1402    // disabled
1403    sc_fxnum_fast();
1404    sc_fxnum_fast( const sc_fxnum_fast& );
1405};
1406
1407
1408// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
1409
1410// ----------------------------------------------------------------------------
1411//  CLASS : sc_fxnum_bitref
1412//
1413//  Proxy class for bit-selection in class sc_fxnum, behaves like sc_bit.
1414// ----------------------------------------------------------------------------
1415
1416// constructor
1417
1418inline
1419sc_fxnum_bitref::sc_fxnum_bitref( sc_fxnum& num_, int idx_ )
1420    : m_num( num_ ), m_idx( idx_ )
1421{}
1422
1423
1424// copy constructor
1425
1426inline
1427sc_fxnum_bitref::sc_fxnum_bitref( const sc_fxnum_bitref& a )
1428    : m_num( a.m_num ), m_idx( a.m_idx )
1429{}
1430
1431
1432// assignment operators
1433
1434inline
1435sc_fxnum_bitref&
1436sc_fxnum_bitref::operator = ( const sc_fxnum_bitref& a )
1437{
1438    if( &a != this )
1439    {
1440	SC_FXNUM_OBSERVER_READ_( a.m_num )
1441	set( a.get() );
1442	SC_FXNUM_OBSERVER_WRITE_( m_num )
1443    }
1444    return *this;
1445}
1446
1447inline
1448sc_fxnum_bitref&
1449sc_fxnum_bitref::operator = ( const sc_fxnum_fast_bitref& a )
1450{
1451    SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
1452    set( a.get() );
1453    SC_FXNUM_OBSERVER_WRITE_( m_num )
1454    return *this;
1455}
1456
1457inline
1458sc_fxnum_bitref&
1459sc_fxnum_bitref::operator = ( const sc_bit& a )
1460{
1461    set( static_cast<bool>( a ) );
1462    SC_FXNUM_OBSERVER_WRITE_( m_num )
1463    return *this;
1464}
1465
1466inline
1467sc_fxnum_bitref&
1468sc_fxnum_bitref::operator = ( bool a )
1469{
1470    set( a );
1471    SC_FXNUM_OBSERVER_WRITE_( m_num )
1472    return *this;
1473}
1474
1475
1476inline
1477sc_fxnum_bitref&
1478sc_fxnum_bitref::operator &= ( const sc_fxnum_bitref& b )
1479{
1480    SC_FXNUM_OBSERVER_READ_( m_num )
1481    SC_FXNUM_OBSERVER_READ_( b.m_num )
1482    set( get() && b.get() );
1483    SC_FXNUM_OBSERVER_WRITE_( m_num )
1484    return *this;
1485}
1486
1487inline
1488sc_fxnum_bitref&
1489sc_fxnum_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
1490{
1491    SC_FXNUM_OBSERVER_READ_( m_num )
1492    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1493    set( get() && b.get() );
1494    SC_FXNUM_OBSERVER_WRITE_( m_num )
1495    return *this;
1496}
1497
1498inline
1499sc_fxnum_bitref&
1500sc_fxnum_bitref::operator &= ( const sc_bit& b )
1501{
1502    SC_FXNUM_OBSERVER_READ_( m_num )
1503    set( get() && static_cast<bool>( b ) );
1504    SC_FXNUM_OBSERVER_WRITE_( m_num )
1505    return *this;
1506}
1507
1508inline
1509sc_fxnum_bitref&
1510sc_fxnum_bitref::operator &= ( bool b )
1511{
1512    SC_FXNUM_OBSERVER_READ_( m_num )
1513    set( get() && b );
1514    SC_FXNUM_OBSERVER_WRITE_( m_num )
1515    return *this;
1516}
1517
1518
1519inline
1520sc_fxnum_bitref&
1521sc_fxnum_bitref::operator |= ( const sc_fxnum_bitref& b )
1522{
1523    SC_FXNUM_OBSERVER_READ_( m_num )
1524    SC_FXNUM_OBSERVER_READ_( b.m_num )
1525    set( get() || b.get() );
1526    SC_FXNUM_OBSERVER_WRITE_( m_num )
1527    return *this;
1528}
1529
1530inline
1531sc_fxnum_bitref&
1532sc_fxnum_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
1533{
1534    SC_FXNUM_OBSERVER_READ_( m_num )
1535    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1536    set( get() || b.get() );
1537    SC_FXNUM_OBSERVER_WRITE_( m_num )
1538    return *this;
1539}
1540
1541inline
1542sc_fxnum_bitref&
1543sc_fxnum_bitref::operator |= ( const sc_bit& b )
1544{
1545    SC_FXNUM_OBSERVER_READ_( m_num )
1546    set( get() || static_cast<bool>( b ) );
1547    SC_FXNUM_OBSERVER_WRITE_( m_num )
1548    return *this;
1549}
1550
1551inline
1552sc_fxnum_bitref&
1553sc_fxnum_bitref::operator |= ( bool b )
1554{
1555    SC_FXNUM_OBSERVER_READ_( m_num )
1556    set( get() || b );
1557    SC_FXNUM_OBSERVER_WRITE_( m_num )
1558    return *this;
1559}
1560
1561
1562inline
1563sc_fxnum_bitref&
1564sc_fxnum_bitref::operator ^= ( const sc_fxnum_bitref& b )
1565{
1566    SC_FXNUM_OBSERVER_READ_( m_num )
1567    SC_FXNUM_OBSERVER_READ_( b.m_num )
1568    set( get() != b.get() );
1569    SC_FXNUM_OBSERVER_WRITE_( m_num )
1570    return *this;
1571}
1572
1573inline
1574sc_fxnum_bitref&
1575sc_fxnum_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
1576{
1577    SC_FXNUM_OBSERVER_READ_( m_num )
1578    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1579    set( get() != b.get() );
1580    SC_FXNUM_OBSERVER_WRITE_( m_num )
1581    return *this;
1582}
1583
1584inline
1585sc_fxnum_bitref&
1586sc_fxnum_bitref::operator ^= ( const sc_bit& b )
1587{
1588    SC_FXNUM_OBSERVER_READ_( m_num )
1589    set( get() != static_cast<bool>( b ) );
1590    SC_FXNUM_OBSERVER_WRITE_( m_num )
1591    return *this;
1592}
1593
1594inline
1595sc_fxnum_bitref&
1596sc_fxnum_bitref::operator ^= ( bool b )
1597{
1598    SC_FXNUM_OBSERVER_READ_( m_num )
1599    set( get() != b );
1600    SC_FXNUM_OBSERVER_WRITE_( m_num )
1601    return *this;
1602}
1603
1604
1605// implicit conversion
1606
1607inline
1608sc_fxnum_bitref::operator bool() const
1609{
1610    SC_FXNUM_OBSERVER_READ_( m_num )
1611    return get();
1612}
1613
1614
1615inline
1616::std::ostream&
1617operator << ( ::std::ostream& os, const sc_fxnum_bitref& a )
1618{
1619    a.print( os );
1620    return os;
1621}
1622
1623inline
1624::std::istream&
1625operator >> ( ::std::istream& is, sc_fxnum_bitref& a )
1626{
1627    a.scan( is );
1628    return is;
1629}
1630
1631
1632// ----------------------------------------------------------------------------
1633//  CLASS : sc_fxnum_fast_bitref
1634//
1635//  Proxy class for bit-selection in class sc_fxnum_fast, behaves like sc_bit.
1636// ----------------------------------------------------------------------------
1637
1638// constructor
1639
1640inline
1641sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( sc_fxnum_fast& num_, int idx_ )
1642    : m_num( num_ ), m_idx( idx_ )
1643{}
1644
1645
1646// copy constructor
1647
1648inline
1649sc_fxnum_fast_bitref::sc_fxnum_fast_bitref( const sc_fxnum_fast_bitref& a )
1650    : m_num( a.m_num ), m_idx( a.m_idx )
1651{}
1652
1653
1654// assignment operators
1655
1656inline
1657sc_fxnum_fast_bitref&
1658sc_fxnum_fast_bitref::operator = ( const sc_fxnum_bitref& a )
1659{
1660    SC_FXNUM_OBSERVER_READ_( a.m_num )
1661    set( a.get() );
1662    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1663    return *this;
1664}
1665
1666inline
1667sc_fxnum_fast_bitref&
1668sc_fxnum_fast_bitref::operator = ( const sc_fxnum_fast_bitref& a )
1669{
1670    if( &a != this )
1671    {
1672	SC_FXNUM_FAST_OBSERVER_READ_( a.m_num )
1673	set( a.get() );
1674	SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1675    }
1676    return *this;
1677}
1678
1679inline
1680sc_fxnum_fast_bitref&
1681sc_fxnum_fast_bitref::operator = ( const sc_bit& a )
1682{
1683    set( static_cast<bool>( a ) );
1684    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1685    return *this;
1686}
1687
1688inline
1689sc_fxnum_fast_bitref&
1690sc_fxnum_fast_bitref::operator = ( bool a )
1691{
1692    set( a );
1693    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1694    return *this;
1695}
1696
1697
1698inline
1699sc_fxnum_fast_bitref&
1700sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_bitref& b )
1701{
1702    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1703    SC_FXNUM_OBSERVER_READ_( b.m_num )
1704    set( get() && b.get() );
1705    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1706    return *this;
1707}
1708
1709inline
1710sc_fxnum_fast_bitref&
1711sc_fxnum_fast_bitref::operator &= ( const sc_fxnum_fast_bitref& b )
1712{
1713    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1714    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1715    set( get() && b.get() );
1716    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1717    return *this;
1718}
1719
1720inline
1721sc_fxnum_fast_bitref&
1722sc_fxnum_fast_bitref::operator &= ( const sc_bit& b )
1723{
1724    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1725    set( get() && static_cast<bool>( b ) );
1726    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1727    return *this;
1728}
1729
1730inline
1731sc_fxnum_fast_bitref&
1732sc_fxnum_fast_bitref::operator &= ( bool b )
1733{
1734    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1735    set( get() && b );
1736    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1737    return *this;
1738}
1739
1740
1741inline
1742sc_fxnum_fast_bitref&
1743sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_bitref& b )
1744{
1745    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1746    SC_FXNUM_OBSERVER_READ_( b.m_num )
1747    set( get() || b.get() );
1748    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1749    return *this;
1750}
1751
1752inline
1753sc_fxnum_fast_bitref&
1754sc_fxnum_fast_bitref::operator |= ( const sc_fxnum_fast_bitref& b )
1755{
1756    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1757    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1758    set( get() || b.get() );
1759    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1760    return *this;
1761}
1762
1763inline
1764sc_fxnum_fast_bitref&
1765sc_fxnum_fast_bitref::operator |= ( const sc_bit& b )
1766{
1767    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1768    set( get() || static_cast<bool>( b ) );
1769    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1770    return *this;
1771}
1772
1773inline
1774sc_fxnum_fast_bitref&
1775sc_fxnum_fast_bitref::operator |= ( bool b )
1776{
1777    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1778    set( get() || b );
1779    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1780    return *this;
1781}
1782
1783
1784inline
1785sc_fxnum_fast_bitref&
1786sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_bitref& b )
1787{
1788    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1789    SC_FXNUM_OBSERVER_READ_( b.m_num )
1790    set( get() != b.get() );
1791    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1792    return *this;
1793}
1794
1795inline
1796sc_fxnum_fast_bitref&
1797sc_fxnum_fast_bitref::operator ^= ( const sc_fxnum_fast_bitref& b )
1798{
1799    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1800    SC_FXNUM_FAST_OBSERVER_READ_( b.m_num )
1801    set( get() != b.get() );
1802    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1803    return *this;
1804}
1805
1806inline
1807sc_fxnum_fast_bitref&
1808sc_fxnum_fast_bitref::operator ^= ( const sc_bit& b )
1809{
1810    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1811    set( get() != static_cast<bool>( b ) );
1812    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1813    return *this;
1814}
1815
1816inline
1817sc_fxnum_fast_bitref&
1818sc_fxnum_fast_bitref::operator ^= ( bool b )
1819{
1820    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1821    set( get() != b );
1822    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
1823    return *this;
1824}
1825
1826
1827// implicit conversion
1828
1829inline
1830sc_fxnum_fast_bitref::operator bool() const
1831{
1832    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
1833    return get();
1834}
1835
1836
1837inline
1838::std::ostream&
1839operator << ( ::std::ostream& os, const sc_fxnum_fast_bitref& a )
1840{
1841    a.print( os );
1842    return os;
1843}
1844
1845inline
1846::std::istream&
1847operator >> ( ::std::istream& is, sc_fxnum_fast_bitref& a )
1848{
1849    a.scan( is );
1850    return is;
1851}
1852
1853
1854// ----------------------------------------------------------------------------
1855//  CLASS : sc_fxnum_subref
1856//
1857//  Proxy class for part-selection in class sc_fxnum,
1858//  behaves like sc_bv_base.
1859// ----------------------------------------------------------------------------
1860
1861// constructor
1862
1863inline
1864sc_fxnum_subref::sc_fxnum_subref( sc_fxnum& num_, int from_, int to_ )
1865    : m_num( num_ ), m_from( from_ ), m_to( to_ ),
1866      m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
1867			     sc_min( m_from, m_to ) + 1 ) )
1868{}
1869
1870
1871// copy constructor
1872
1873inline
1874sc_fxnum_subref::sc_fxnum_subref( const sc_fxnum_subref& a )
1875    : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
1876      m_bv( *new sc_bv_base( a.m_bv ) )
1877{}
1878
1879
1880// destructor
1881
1882inline
1883sc_fxnum_subref::~sc_fxnum_subref()
1884{
1885    delete &m_bv;
1886}
1887
1888
1889// assignment operators
1890
1891inline
1892sc_fxnum_subref&
1893sc_fxnum_subref::operator = ( const sc_fxnum_subref& a )
1894{
1895    if( &a != this )
1896    {
1897	m_bv = static_cast<sc_bv_base>( a );
1898	set();
1899	SC_FXNUM_OBSERVER_WRITE_( m_num )
1900    }
1901    return *this;
1902}
1903
1904inline
1905sc_fxnum_subref&
1906sc_fxnum_subref::operator = ( const sc_fxnum_fast_subref& a )
1907{
1908    m_bv = static_cast<sc_bv_base>( a );
1909    set();
1910    SC_FXNUM_OBSERVER_WRITE_( m_num )
1911    return *this;
1912}
1913
1914#define DEFN_ASN_OP_T(tp)                                                     \
1915inline                                                                        \
1916sc_fxnum_subref&                                                              \
1917sc_fxnum_subref::operator = ( tp a )                                          \
1918{                                                                             \
1919    m_bv = a;                                                                 \
1920    set();                                                                    \
1921    SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
1922    return *this;                                                             \
1923}
1924
1925DEFN_ASN_OP_T(const sc_bv_base&)
1926DEFN_ASN_OP_T(const sc_lv_base&)
1927DEFN_ASN_OP_T(const char*)
1928DEFN_ASN_OP_T(const bool*)
1929DEFN_ASN_OP_T(const sc_signed&)
1930DEFN_ASN_OP_T(const sc_unsigned&)
1931DEFN_ASN_OP_T(const sc_int_base&)
1932DEFN_ASN_OP_T(const sc_uint_base&)
1933DEFN_ASN_OP_T(int64)
1934DEFN_ASN_OP_T(uint64)
1935DEFN_ASN_OP_T(int)
1936DEFN_ASN_OP_T(unsigned int)
1937DEFN_ASN_OP_T(long)
1938DEFN_ASN_OP_T(unsigned long)
1939DEFN_ASN_OP_T(char)
1940
1941#undef DEFN_ASN_OP_T
1942
1943
1944#define DEFN_ASN_OP_T(op,tp)                                                  \
1945inline                                                                        \
1946sc_fxnum_subref&                                                              \
1947sc_fxnum_subref::operator op ## = ( tp a )                                    \
1948{                                                                             \
1949    SC_FXNUM_OBSERVER_READ_( m_num )                                          \
1950    get();                                                                    \
1951    m_bv = m_bv op a;                                                         \
1952    set();                                                                    \
1953    SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
1954    return *this;                                                             \
1955}
1956
1957#define DEFN_ASN_OP(op)                                                       \
1958inline                                                                        \
1959sc_fxnum_subref&                                                              \
1960sc_fxnum_subref::operator op ## = ( const sc_fxnum_subref& a )                \
1961{                                                                             \
1962    SC_FXNUM_OBSERVER_READ_( m_num )                                          \
1963    get();                                                                    \
1964    m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
1965    set();                                                                    \
1966    SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
1967    return *this;                                                             \
1968}                                                                             \
1969                                                                              \
1970inline                                                                        \
1971sc_fxnum_subref&                                                              \
1972sc_fxnum_subref::operator op ## = ( const sc_fxnum_fast_subref& a )           \
1973{                                                                             \
1974    SC_FXNUM_OBSERVER_READ_( m_num )                                          \
1975    get();                                                                    \
1976    m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
1977    set();                                                                    \
1978    SC_FXNUM_OBSERVER_WRITE_( m_num )                                         \
1979    return *this;                                                             \
1980}                                                                             \
1981                                                                              \
1982DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
1983DEFN_ASN_OP_T(op,const sc_lv_base&)
1984
1985DEFN_ASN_OP(&)
1986DEFN_ASN_OP(|)
1987DEFN_ASN_OP(^)
1988
1989#undef DEFN_ASN_OP_T
1990#undef DEFN_ASN_OP
1991
1992
1993// relational operators
1994
1995#define DEFN_REL_OP_T(op,tp)                                                  \
1996inline                                                                        \
1997bool                                                                          \
1998operator op ( const sc_fxnum_subref& a, tp b )                                \
1999{                                                                             \
2000    return ( static_cast<sc_bv_base>( a ) op b );                             \
2001}                                                                             \
2002                                                                              \
2003inline                                                                        \
2004bool                                                                          \
2005operator op ( tp a, const sc_fxnum_subref& b )                                \
2006{                                                                             \
2007    return ( static_cast<sc_bv_base>( b ) op a );                             \
2008}
2009
2010#define DEFN_REL_OP(op)                                                       \
2011inline                                                                        \
2012bool                                                                          \
2013operator op ( const sc_fxnum_subref& a, const sc_fxnum_subref& b )            \
2014{                                                                             \
2015    return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
2016}                                                                             \
2017                                                                              \
2018inline                                                                        \
2019bool                                                                          \
2020operator op ( const sc_fxnum_subref& a, const sc_fxnum_fast_subref& b )       \
2021{                                                                             \
2022    return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
2023}                                                                             \
2024                                                                              \
2025DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
2026DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
2027DEFN_REL_OP_T(op,const char*)                                                 \
2028DEFN_REL_OP_T(op,const bool*)                                                 \
2029DEFN_REL_OP_T(op,const sc_signed&)                                            \
2030DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
2031DEFN_REL_OP_T(op,int)                                                         \
2032DEFN_REL_OP_T(op,unsigned int)                                                \
2033DEFN_REL_OP_T(op,long)                                                        \
2034DEFN_REL_OP_T(op,unsigned long)
2035
2036DEFN_REL_OP(==)
2037DEFN_REL_OP(!=)
2038
2039#undef DEFN_REL_OP_T
2040#undef DEFN_REL_OP
2041
2042
2043// reduce functions
2044
2045#define DEFN_RED_FNC(fnc)                                                     \
2046inline                                                                        \
2047bool                                                                          \
2048sc_fxnum_subref::fnc() const                                                  \
2049{                                                                             \
2050    SC_FXNUM_OBSERVER_READ_( m_num )                                          \
2051    get();                                                                    \
2052    return static_cast<bool>( m_bv.fnc() );                                   \
2053}
2054
2055DEFN_RED_FNC(and_reduce)
2056DEFN_RED_FNC(nand_reduce)
2057DEFN_RED_FNC(or_reduce)
2058DEFN_RED_FNC(nor_reduce)
2059DEFN_RED_FNC(xor_reduce)
2060DEFN_RED_FNC(xnor_reduce)
2061
2062#undef DEFN_RED_FNC
2063
2064
2065// query parameter
2066
2067inline
2068int
2069sc_fxnum_subref::length() const
2070{
2071    return m_bv.length();
2072}
2073
2074
2075// explicit conversions
2076
2077inline
2078int
2079sc_fxnum_subref::to_int() const
2080{
2081    SC_FXNUM_OBSERVER_READ_( m_num )
2082    get();
2083    return m_bv.to_int();
2084}
2085
2086inline
2087int64
2088sc_fxnum_subref::to_int64() const
2089{
2090    SC_FXNUM_OBSERVER_READ_( m_num )
2091    get();
2092    return m_bv.to_int64();
2093}
2094
2095inline
2096unsigned int
2097sc_fxnum_subref::to_uint() const
2098{
2099    SC_FXNUM_OBSERVER_READ_( m_num )
2100    get();
2101    return m_bv.to_uint();
2102}
2103
2104inline
2105uint64
2106sc_fxnum_subref::to_uint64() const
2107{
2108    SC_FXNUM_OBSERVER_READ_( m_num )
2109    get();
2110    return m_bv.to_uint64();
2111}
2112
2113inline
2114long
2115sc_fxnum_subref::to_long() const
2116{
2117    SC_FXNUM_OBSERVER_READ_( m_num )
2118    get();
2119    return m_bv.to_long();
2120}
2121
2122inline
2123unsigned long
2124sc_fxnum_subref::to_ulong() const
2125{
2126    SC_FXNUM_OBSERVER_READ_( m_num )
2127    get();
2128    return m_bv.to_ulong();
2129}
2130
2131
2132#ifdef SC_DT_DEPRECATED
2133
2134inline
2135int
2136sc_fxnum_subref::to_signed() const
2137{
2138    return to_int();
2139}
2140
2141inline
2142unsigned int
2143sc_fxnum_subref::to_unsigned() const
2144{
2145    return to_uint();
2146}
2147
2148#endif
2149
2150
2151inline
2152const std::string
2153sc_fxnum_subref::to_string() const
2154{
2155    get();
2156    return m_bv.to_string();
2157}
2158
2159inline
2160const std::string
2161sc_fxnum_subref::to_string( sc_numrep numrep ) const
2162{
2163    get();
2164    return m_bv.to_string( numrep );
2165}
2166
2167inline
2168const std::string
2169sc_fxnum_subref::to_string( sc_numrep numrep, bool w_prefix ) const
2170{
2171    get();
2172    return m_bv.to_string( numrep, w_prefix );
2173}
2174
2175
2176// implicit conversion
2177
2178inline
2179sc_fxnum_subref::operator sc_bv_base () const
2180{
2181    SC_FXNUM_OBSERVER_READ_( m_num )
2182    get();
2183    return m_bv;
2184}
2185
2186
2187inline
2188::std::ostream&
2189operator << ( ::std::ostream& os, const sc_fxnum_subref& a )
2190{
2191    a.print( os );
2192    return os;
2193}
2194
2195inline
2196::std::istream&
2197operator >> ( ::std::istream& is, sc_fxnum_subref& a )
2198{
2199    a.scan( is );
2200    return is;
2201}
2202
2203
2204// ----------------------------------------------------------------------------
2205//  CLASS : sc_fxnum_fast_subref
2206//
2207//  Proxy class for part-selection in class sc_fxnum_fast,
2208//  behaves like sc_bv_base.
2209// ----------------------------------------------------------------------------
2210
2211// constructor
2212
2213inline
2214sc_fxnum_fast_subref::sc_fxnum_fast_subref( sc_fxnum_fast& num_,
2215					    int from_, int to_ )
2216    : m_num( num_ ), m_from( from_ ), m_to( to_ ),
2217      m_bv( *new sc_bv_base( sc_max( m_from, m_to ) -
2218			     sc_min( m_from, m_to ) + 1 ) )
2219{}
2220
2221
2222// copy constructor
2223
2224inline
2225sc_fxnum_fast_subref::sc_fxnum_fast_subref( const sc_fxnum_fast_subref& a )
2226    : m_num( a.m_num ), m_from( a.m_from ), m_to( a.m_to ),
2227      m_bv( *new sc_bv_base( a.m_bv ) )
2228{}
2229
2230
2231// destructor
2232
2233inline
2234sc_fxnum_fast_subref::~sc_fxnum_fast_subref()
2235{
2236    delete &m_bv;
2237}
2238
2239
2240// assignment operators
2241
2242inline
2243sc_fxnum_fast_subref&
2244sc_fxnum_fast_subref::operator = ( const sc_fxnum_subref& a )
2245{
2246    m_bv = static_cast<sc_bv_base>( a );
2247    set();
2248    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
2249    return *this;
2250}
2251
2252inline
2253sc_fxnum_fast_subref&
2254sc_fxnum_fast_subref::operator = ( const sc_fxnum_fast_subref& a )
2255{
2256    if( &a != this )
2257    {
2258	m_bv = static_cast<sc_bv_base>( a );
2259	set();
2260	SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )
2261    }
2262    return *this;
2263}
2264
2265#define DEFN_ASN_OP_T(tp)                                                     \
2266inline                                                                        \
2267sc_fxnum_fast_subref&                                                         \
2268sc_fxnum_fast_subref::operator = ( tp a )                                     \
2269{                                                                             \
2270    m_bv = a;                                                                 \
2271    set();                                                                    \
2272    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
2273    return *this;                                                             \
2274}
2275
2276DEFN_ASN_OP_T(const sc_bv_base&)
2277DEFN_ASN_OP_T(const sc_lv_base&)
2278DEFN_ASN_OP_T(const char*)
2279DEFN_ASN_OP_T(const bool*)
2280DEFN_ASN_OP_T(const sc_signed&)
2281DEFN_ASN_OP_T(const sc_unsigned&)
2282DEFN_ASN_OP_T(const sc_int_base&)
2283DEFN_ASN_OP_T(const sc_uint_base&)
2284DEFN_ASN_OP_T(int64)
2285DEFN_ASN_OP_T(uint64)
2286DEFN_ASN_OP_T(int)
2287DEFN_ASN_OP_T(unsigned int)
2288DEFN_ASN_OP_T(long)
2289DEFN_ASN_OP_T(unsigned long)
2290DEFN_ASN_OP_T(char)
2291
2292#undef DEFN_ASN_OP_T
2293
2294
2295#define DEFN_ASN_OP_T(op,tp)                                                  \
2296inline                                                                        \
2297sc_fxnum_fast_subref&                                                         \
2298sc_fxnum_fast_subref::operator op ## = ( tp a )                               \
2299{                                                                             \
2300    SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
2301    get();                                                                    \
2302    m_bv = m_bv op a;                                                         \
2303    set();                                                                    \
2304    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
2305    return *this;                                                             \
2306}
2307
2308#define DEFN_ASN_OP(op)                                                       \
2309inline                                                                        \
2310sc_fxnum_fast_subref&                                                         \
2311sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_subref& a )           \
2312{                                                                             \
2313    SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
2314    get();                                                                    \
2315    m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
2316    set();                                                                    \
2317    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
2318    return *this;                                                             \
2319}                                                                             \
2320                                                                              \
2321inline                                                                        \
2322sc_fxnum_fast_subref&                                                         \
2323sc_fxnum_fast_subref::operator op ## = ( const sc_fxnum_fast_subref& a )      \
2324{                                                                             \
2325    SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
2326    get();                                                                    \
2327    m_bv = m_bv op static_cast<sc_bv_base>( a );                              \
2328    set();                                                                    \
2329    SC_FXNUM_FAST_OBSERVER_WRITE_( m_num )                                    \
2330    return *this;                                                             \
2331}                                                                             \
2332                                                                              \
2333DEFN_ASN_OP_T(op,const sc_bv_base&)                                           \
2334DEFN_ASN_OP_T(op,const sc_lv_base&)
2335
2336DEFN_ASN_OP(&)
2337DEFN_ASN_OP(|)
2338DEFN_ASN_OP(^)
2339
2340#undef DEFN_ASN_OP_T
2341#undef DEFN_ASN_OP
2342
2343
2344// relational operators
2345
2346#define DEFN_REL_OP_T(op,tp)                                                  \
2347inline                                                                        \
2348bool                                                                          \
2349operator op ( const sc_fxnum_fast_subref& a, tp b )                           \
2350{                                                                             \
2351    return ( static_cast<sc_bv_base>( a ) op b );                             \
2352}                                                                             \
2353                                                                              \
2354inline                                                                        \
2355bool                                                                          \
2356operator op ( tp a, const sc_fxnum_fast_subref& b )                           \
2357{                                                                             \
2358    return ( static_cast<sc_bv_base>( b ) op a );                             \
2359}
2360
2361#define DEFN_REL_OP(op)                                                       \
2362inline                                                                        \
2363bool                                                                          \
2364operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_fast_subref& b )  \
2365{                                                                             \
2366    return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
2367}                                                                             \
2368                                                                              \
2369inline                                                                        \
2370bool                                                                          \
2371operator op ( const sc_fxnum_fast_subref& a, const sc_fxnum_subref& b )       \
2372{                                                                             \
2373    return ( static_cast<sc_bv_base>( a ) op static_cast<sc_bv_base>( b ) );  \
2374}                                                                             \
2375                                                                              \
2376DEFN_REL_OP_T(op,const sc_bv_base&)                                           \
2377DEFN_REL_OP_T(op,const sc_lv_base&)                                           \
2378DEFN_REL_OP_T(op,const char*)                                                 \
2379DEFN_REL_OP_T(op,const bool*)                                                 \
2380DEFN_REL_OP_T(op,const sc_signed&)                                            \
2381DEFN_REL_OP_T(op,const sc_unsigned&)                                          \
2382DEFN_REL_OP_T(op,int)                                                         \
2383DEFN_REL_OP_T(op,unsigned int)                                                \
2384DEFN_REL_OP_T(op,long)                                                        \
2385DEFN_REL_OP_T(op,unsigned long)
2386
2387DEFN_REL_OP(==)
2388DEFN_REL_OP(!=)
2389
2390#undef DEFN_REL_OP_T
2391#undef DEFN_REL_OP
2392
2393
2394// reduce functions
2395
2396#define DEFN_RED_FNC(fnc)                                                     \
2397inline                                                                        \
2398bool                                                                          \
2399sc_fxnum_fast_subref::fnc() const                                             \
2400{                                                                             \
2401    SC_FXNUM_FAST_OBSERVER_READ_( m_num )                                     \
2402    get();                                                                    \
2403    return static_cast<bool>( m_bv.fnc() );                                   \
2404}
2405
2406DEFN_RED_FNC(and_reduce)
2407DEFN_RED_FNC(nand_reduce)
2408DEFN_RED_FNC(or_reduce)
2409DEFN_RED_FNC(nor_reduce)
2410DEFN_RED_FNC(xor_reduce)
2411DEFN_RED_FNC(xnor_reduce)
2412
2413#undef DEFN_RED_FNC
2414
2415
2416// query parameter
2417
2418inline
2419int
2420sc_fxnum_fast_subref::length() const
2421{
2422    return m_bv.length();
2423}
2424
2425
2426// explicit conversions
2427
2428inline
2429int
2430sc_fxnum_fast_subref::to_int() const
2431{
2432    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2433    get();
2434    return m_bv.to_int();
2435}
2436
2437inline
2438int64
2439sc_fxnum_fast_subref::to_int64() const
2440{
2441    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2442    get();
2443    return m_bv.to_int64();
2444}
2445
2446inline
2447unsigned int
2448sc_fxnum_fast_subref::to_uint() const
2449{
2450    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2451    get();
2452    return m_bv.to_uint();
2453}
2454
2455inline
2456uint64
2457sc_fxnum_fast_subref::to_uint64() const
2458{
2459    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2460    get();
2461    return m_bv.to_uint64();
2462}
2463
2464inline
2465long
2466sc_fxnum_fast_subref::to_long() const
2467{
2468    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2469    get();
2470    return m_bv.to_long();
2471}
2472
2473inline
2474unsigned long
2475sc_fxnum_fast_subref::to_ulong() const
2476{
2477    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2478    get();
2479    return m_bv.to_ulong();
2480}
2481
2482
2483#ifdef SC_DT_DEPRECATED
2484
2485inline
2486int
2487sc_fxnum_fast_subref::to_signed() const
2488{
2489    return to_int();
2490}
2491
2492inline
2493unsigned int
2494sc_fxnum_fast_subref::to_unsigned() const
2495{
2496    return to_uint();
2497}
2498
2499#endif
2500
2501
2502inline
2503const std::string
2504sc_fxnum_fast_subref::to_string() const
2505{
2506    get();
2507    return m_bv.to_string();
2508}
2509
2510inline
2511const std::string
2512sc_fxnum_fast_subref::to_string( sc_numrep numrep ) const
2513{
2514    get();
2515    return m_bv.to_string( numrep );
2516}
2517
2518inline
2519const std::string
2520sc_fxnum_fast_subref::to_string( sc_numrep numrep, bool w_prefix ) const
2521{
2522    get();
2523    return m_bv.to_string( numrep, w_prefix );
2524}
2525
2526
2527// implicit conversion
2528
2529inline
2530sc_fxnum_fast_subref::operator sc_bv_base () const
2531{
2532    SC_FXNUM_FAST_OBSERVER_READ_( m_num )
2533    get();
2534    return m_bv;
2535}
2536
2537
2538inline
2539::std::ostream&
2540operator << ( ::std::ostream& os, const sc_fxnum_fast_subref& a )
2541{
2542    a.print( os );
2543    return os;
2544}
2545
2546inline
2547::std::istream&
2548operator >> ( ::std::istream& is, sc_fxnum_fast_subref& a )
2549{
2550    a.scan( is );
2551    return is;
2552}
2553
2554
2555// ----------------------------------------------------------------------------
2556//  CLASS : sc_fxnum
2557//
2558//  Base class for the fixed-point types; arbitrary precision.
2559// ----------------------------------------------------------------------------
2560
2561inline
2562sc_fxnum_observer*
2563sc_fxnum::observer() const
2564{
2565    return m_observer;
2566}
2567
2568
2569inline
2570void
2571sc_fxnum::cast()
2572{
2573    SC_ERROR_IF_( ! m_rep->is_normal(), sc_core::SC_ID_INVALID_FX_VALUE_ );
2574
2575    if( m_params.cast_switch() == SC_ON )
2576	m_rep->cast( m_params, m_q_flag, m_o_flag );
2577}
2578
2579
2580// constructors
2581
2582inline
2583sc_fxnum::sc_fxnum( const sc_fxtype_params& type_params_,
2584		    sc_enc enc_,
2585		    const sc_fxcast_switch& cast_sw,
2586		    sc_fxnum_observer* observer_ )
2587: m_rep( new scfx_rep ),
2588  m_params( type_params_, enc_, cast_sw ),
2589  m_q_flag( false ),
2590  m_o_flag( false ),
2591  m_observer( observer_ )
2592{
2593    SC_FXNUM_OBSERVER_DEFAULT_
2594    SC_FXNUM_OBSERVER_CONSTRUCT_( *this )
2595}
2596
2597#define DEFN_CTOR_T(tp,arg)                                                   \
2598inline                                                                        \
2599sc_fxnum::sc_fxnum( tp a,                                                     \
2600		    const sc_fxtype_params& type_params_,                     \
2601		    sc_enc enc_,                                              \
2602		    const sc_fxcast_switch& cast_sw,                          \
2603		    sc_fxnum_observer* observer_ )                            \
2604: m_rep( new scfx_rep( arg ) ),                                               \
2605  m_params( type_params_, enc_, cast_sw ),                                    \
2606  m_q_flag( false ),                                                          \
2607  m_o_flag( false ),                                                          \
2608  m_observer( observer_ )                                                     \
2609{                                                                             \
2610    SC_FXNUM_OBSERVER_DEFAULT_                                                \
2611    cast();                                                                   \
2612    SC_FXNUM_OBSERVER_CONSTRUCT_( *this )                                     \
2613    SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
2614}
2615
2616#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,a)
2617#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,*a.m_rep)
2618#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
2619#define DEFN_CTOR_T_D(tp) DEFN_CTOR_T(tp,a.value())
2620
2621DEFN_CTOR_T_A(int)
2622DEFN_CTOR_T_A(unsigned int)
2623DEFN_CTOR_T_A(long)
2624DEFN_CTOR_T_A(unsigned long)
2625DEFN_CTOR_T_A(float)
2626DEFN_CTOR_T_A(double)
2627DEFN_CTOR_T_A(const char*)
2628DEFN_CTOR_T_B(const sc_fxval&)
2629DEFN_CTOR_T_C(const sc_fxval_fast&)
2630DEFN_CTOR_T_B(const sc_fxnum&)
2631DEFN_CTOR_T_C(const sc_fxnum_fast&)
2632#ifndef SC_FX_EXCLUDE_OTHER
2633DEFN_CTOR_T_A(int64)
2634DEFN_CTOR_T_A(uint64)
2635DEFN_CTOR_T_D(const sc_int_base&)
2636DEFN_CTOR_T_D(const sc_uint_base&)
2637DEFN_CTOR_T_A(const sc_signed&)
2638DEFN_CTOR_T_A(const sc_unsigned&)
2639#endif
2640
2641#undef DEFN_CTOR_T
2642#undef DEFN_CTOR_T_A
2643#undef DEFN_CTOR_T_B
2644#undef DEFN_CTOR_T_C
2645#undef DEFN_CTOR_T_D
2646
2647
2648inline
2649sc_fxnum::~sc_fxnum()
2650{
2651    SC_FXNUM_OBSERVER_DESTRUCT_( *this )
2652    delete m_rep;
2653}
2654
2655
2656// internal use only;
2657inline
2658const scfx_rep*
2659sc_fxnum::get_rep() const
2660{
2661    SC_FXNUM_OBSERVER_READ_( *this )
2662    return m_rep;
2663}
2664
2665
2666// unary operators
2667
2668inline
2669const sc_fxval
2670sc_fxnum::operator - () const
2671{
2672    SC_FXNUM_OBSERVER_READ_( *this )
2673    return sc_fxval( sc_dt::neg_scfx_rep( *m_rep ) );
2674}
2675
2676inline
2677const sc_fxval
2678sc_fxnum::operator + () const
2679{
2680    SC_FXNUM_OBSERVER_READ_( *this )
2681    return sc_fxval( new scfx_rep( *m_rep ) );
2682}
2683
2684
2685// unary functions
2686
2687inline
2688void
2689neg( sc_fxval& c, const sc_fxnum& a )
2690{
2691    SC_FXNUM_OBSERVER_READ_( a )
2692    c.set_rep( sc_dt::neg_scfx_rep( *a.m_rep ) );
2693}
2694
2695inline
2696void
2697neg( sc_fxnum& c, const sc_fxnum& a )
2698{
2699    SC_FXNUM_OBSERVER_READ_( a )
2700    delete c.m_rep;
2701    c.m_rep = sc_dt::neg_scfx_rep( *a.m_rep );
2702    c.cast();
2703    SC_FXNUM_OBSERVER_WRITE_( c )
2704}
2705
2706
2707// binary operators
2708
2709#define DEFN_BIN_OP_T(op,fnc,tp)                                              \
2710inline                                                                        \
2711const sc_fxval                                                                \
2712operator op ( const sc_fxnum& a, tp b )                                       \
2713{                                                                             \
2714    SC_FXNUM_OBSERVER_READ_( a )                                              \
2715    sc_fxval tmp( b );                                                        \
2716    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );  \
2717}                                                                             \
2718                                                                              \
2719inline                                                                        \
2720const sc_fxval                                                                \
2721operator op ( tp a, const sc_fxnum& b )                                       \
2722{                                                                             \
2723    SC_FXNUM_OBSERVER_READ_( b )                                              \
2724    sc_fxval tmp( a );                                                        \
2725    return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );  \
2726}
2727
2728#ifndef SC_FX_EXCLUDE_OTHER
2729#define DEFN_BIN_OP_OTHER(op,fnc)                                             \
2730DEFN_BIN_OP_T(op,fnc,int64)                                                   \
2731DEFN_BIN_OP_T(op,fnc,uint64)                                                  \
2732DEFN_BIN_OP_T(op,fnc,const sc_int_base&)                                      \
2733DEFN_BIN_OP_T(op,fnc,const sc_uint_base&)                                     \
2734DEFN_BIN_OP_T(op,fnc,const sc_signed&)                                        \
2735DEFN_BIN_OP_T(op,fnc,const sc_unsigned&)
2736#else
2737#define DEFN_BIN_OP_OTHER(op,fnc)
2738#endif
2739
2740#define DEFN_BIN_OP(op,fnc)                                                   \
2741inline                                                                        \
2742const sc_fxval                                                                \
2743operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
2744{                                                                             \
2745    SC_FXNUM_OBSERVER_READ_( a )                                              \
2746    SC_FXNUM_OBSERVER_READ_( b )                                              \
2747    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );        \
2748}                                                                             \
2749                                                                              \
2750inline                                                                        \
2751const sc_fxval                                                                \
2752operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
2753{                                                                             \
2754    SC_FXNUM_OBSERVER_READ_( a )                                              \
2755    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );    \
2756}                                                                             \
2757                                                                              \
2758inline                                                                        \
2759const sc_fxval                                                                \
2760operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
2761{                                                                             \
2762    SC_FXNUM_OBSERVER_READ_( b )                                              \
2763    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );    \
2764}                                                                             \
2765                                                                              \
2766DEFN_BIN_OP_T(op,fnc,int)                                                     \
2767DEFN_BIN_OP_T(op,fnc,unsigned int)                                            \
2768DEFN_BIN_OP_T(op,fnc,long)                                                    \
2769DEFN_BIN_OP_T(op,fnc,unsigned long)                                           \
2770DEFN_BIN_OP_T(op,fnc,float)                                                  \
2771DEFN_BIN_OP_T(op,fnc,double)                                                  \
2772DEFN_BIN_OP_T(op,fnc,const char*)                                             \
2773DEFN_BIN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
2774DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
2775DEFN_BIN_OP_OTHER(op,fnc)
2776
2777DEFN_BIN_OP(*,mult)
2778DEFN_BIN_OP(+,add)
2779DEFN_BIN_OP(-,sub)
2780// don't use macros
2781//DEFN_BIN_OP(/,div)
2782inline
2783const sc_fxval
2784operator / ( const sc_fxnum& a, const sc_fxnum& b )
2785{
2786    SC_FXNUM_OBSERVER_READ_( a )
2787    SC_FXNUM_OBSERVER_READ_( b )
2788    return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.m_rep ) );
2789}
2790
2791inline
2792const sc_fxval
2793operator / ( const sc_fxnum& a, const sc_fxval& b )
2794{
2795    SC_FXNUM_OBSERVER_READ_( a )
2796    return sc_fxval( sc_dt::div_scfx_rep( *a.m_rep, *b.get_rep() ) );
2797}
2798
2799inline
2800const sc_fxval
2801operator / ( const sc_fxval& a, const sc_fxnum& b )
2802{
2803    SC_FXNUM_OBSERVER_READ_( b )
2804    return sc_fxval( sc_dt::div_scfx_rep( *a.get_rep(), *b.m_rep ) );
2805}
2806
2807DEFN_BIN_OP_T(/,div,int)
2808DEFN_BIN_OP_T(/,div,unsigned int)
2809DEFN_BIN_OP_T(/,div,long)
2810DEFN_BIN_OP_T(/,div,unsigned long)
2811DEFN_BIN_OP_T(/,div,float)
2812DEFN_BIN_OP_T(/,div,double)
2813DEFN_BIN_OP_T(/,div,const char*)
2814DEFN_BIN_OP_T(/,div,const sc_fxval_fast&)
2815DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
2816//DEFN_BIN_OP_OTHER(/,div)
2817#ifndef SC_FX_EXCLUDE_OTHER
2818DEFN_BIN_OP_T(/,div,int64)
2819DEFN_BIN_OP_T(/,div,uint64)
2820DEFN_BIN_OP_T(/,div,const sc_int_base&)
2821DEFN_BIN_OP_T(/,div,const sc_uint_base&)
2822DEFN_BIN_OP_T(/,div,const sc_signed&)
2823DEFN_BIN_OP_T(/,div,const sc_unsigned&)
2824#endif
2825
2826#undef DEFN_BIN_OP_T
2827#undef DEFN_BIN_OP_OTHER
2828#undef DEFN_BIN_OP
2829
2830
2831inline
2832const sc_fxval
2833operator << ( const sc_fxnum& a, int b )
2834{
2835    SC_FXNUM_OBSERVER_READ_( a )
2836    return sc_fxval( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
2837}
2838
2839inline
2840const sc_fxval
2841operator >> ( const sc_fxnum& a, int b )
2842{
2843    SC_FXNUM_OBSERVER_READ_( a )
2844    return sc_fxval( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
2845}
2846
2847
2848// binary functions
2849
2850#define DEFN_BIN_FNC_T(fnc,tp)                                                \
2851inline                                                                        \
2852void                                                                          \
2853fnc ( sc_fxval& c, const sc_fxnum& a, tp b )                                  \
2854{                                                                             \
2855    SC_FXNUM_OBSERVER_READ_( a )                                              \
2856    sc_fxval tmp( b );                                                        \
2857    c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() ) );        \
2858}                                                                             \
2859                                                                              \
2860inline                                                                        \
2861void                                                                          \
2862fnc ( sc_fxval& c, tp a, const sc_fxnum& b )                                  \
2863{                                                                             \
2864    SC_FXNUM_OBSERVER_READ_( b )                                              \
2865    sc_fxval tmp( a );                                                        \
2866    c.set_rep( sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep ) );        \
2867}                                                                             \
2868                                                                              \
2869inline                                                                        \
2870void                                                                          \
2871fnc ( sc_fxnum& c, const sc_fxnum& a, tp b )                                  \
2872{                                                                             \
2873    SC_FXNUM_OBSERVER_READ_( a )                                              \
2874    sc_fxval tmp( b );                                                        \
2875    delete c.m_rep;                                                           \
2876    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.get_rep() );           \
2877    c.cast();                                                                 \
2878    SC_FXNUM_OBSERVER_WRITE_( c )                                             \
2879}                                                                             \
2880                                                                              \
2881inline                                                                        \
2882void                                                                          \
2883fnc ( sc_fxnum& c, tp a, const sc_fxnum& b )                                  \
2884{                                                                             \
2885    SC_FXNUM_OBSERVER_READ_( b )                                              \
2886    sc_fxval tmp( a );                                                        \
2887    delete c.m_rep;                                                           \
2888    c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.get_rep(), *b.m_rep );           \
2889    c.cast();                                                                 \
2890    SC_FXNUM_OBSERVER_WRITE_( c )                                             \
2891}
2892
2893#ifndef SC_FX_EXCLUDE_OTHER
2894#define DEFN_BIN_FNC_OTHER(fnc)                                               \
2895DEFN_BIN_FNC_T(fnc,int64)                                                     \
2896DEFN_BIN_FNC_T(fnc,uint64)                                                    \
2897DEFN_BIN_FNC_T(fnc,const sc_int_base&)                                        \
2898DEFN_BIN_FNC_T(fnc,const sc_uint_base&)                                       \
2899DEFN_BIN_FNC_T(fnc,const sc_signed&)                                          \
2900DEFN_BIN_FNC_T(fnc,const sc_unsigned&)
2901#else
2902#define DEFN_BIN_FNC_OTHER(fnc)
2903#endif
2904
2905#define DEFN_BIN_FNC(fnc)                                                     \
2906inline                                                                        \
2907void                                                                          \
2908fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxnum& b )                     \
2909{                                                                             \
2910    SC_FXNUM_OBSERVER_READ_( a )                                              \
2911    SC_FXNUM_OBSERVER_READ_( b )                                              \
2912    c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep ) );              \
2913}                                                                             \
2914                                                                              \
2915inline                                                                        \
2916void                                                                          \
2917fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxnum& b )                     \
2918{                                                                             \
2919    SC_FXNUM_OBSERVER_READ_( a )                                              \
2920    SC_FXNUM_OBSERVER_READ_( b )                                              \
2921    delete c.m_rep;                                                           \
2922    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.m_rep );                 \
2923    c.cast();                                                                 \
2924    SC_FXNUM_OBSERVER_WRITE_( c )                                             \
2925}                                                                             \
2926                                                                              \
2927inline                                                                        \
2928void                                                                          \
2929fnc ( sc_fxval& c, const sc_fxnum& a, const sc_fxval& b )                     \
2930{                                                                             \
2931    SC_FXNUM_OBSERVER_READ_( a )                                              \
2932    c.set_rep( sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() ) );          \
2933}                                                                             \
2934                                                                              \
2935inline                                                                        \
2936void                                                                          \
2937fnc ( sc_fxval& c, const sc_fxval& a, const sc_fxnum& b )                     \
2938{                                                                             \
2939    SC_FXNUM_OBSERVER_READ_( b )                                              \
2940    c.set_rep( sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep ) );          \
2941}                                                                             \
2942                                                                              \
2943inline                                                                        \
2944void                                                                          \
2945fnc ( sc_fxnum& c, const sc_fxnum& a, const sc_fxval& b )                     \
2946{                                                                             \
2947    SC_FXNUM_OBSERVER_READ_( a )                                              \
2948    delete c.m_rep;                                                           \
2949    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *b.get_rep() );             \
2950    c.cast();                                                                 \
2951    SC_FXNUM_OBSERVER_WRITE_( c )                                             \
2952}                                                                             \
2953                                                                              \
2954inline                                                                        \
2955void                                                                          \
2956fnc ( sc_fxnum& c, const sc_fxval& a, const sc_fxnum& b )                     \
2957{                                                                             \
2958    SC_FXNUM_OBSERVER_READ_( b )                                              \
2959    delete c.m_rep;                                                           \
2960    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.get_rep(), *b.m_rep );             \
2961    c.cast();                                                                 \
2962    SC_FXNUM_OBSERVER_WRITE_( c )                                             \
2963}                                                                             \
2964                                                                              \
2965DEFN_BIN_FNC_T(fnc,int)                                                       \
2966DEFN_BIN_FNC_T(fnc,unsigned int)                                              \
2967DEFN_BIN_FNC_T(fnc,long)                                                      \
2968DEFN_BIN_FNC_T(fnc,unsigned long)                                             \
2969DEFN_BIN_FNC_T(fnc,float)                                                    \
2970DEFN_BIN_FNC_T(fnc,double)                                                    \
2971DEFN_BIN_FNC_T(fnc,const char*)                                               \
2972DEFN_BIN_FNC_T(fnc,const sc_fxval_fast&)                                      \
2973DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)                                      \
2974DEFN_BIN_FNC_OTHER(fnc)
2975
2976DEFN_BIN_FNC(mult)
2977DEFN_BIN_FNC(div)
2978DEFN_BIN_FNC(add)
2979DEFN_BIN_FNC(sub)
2980
2981#undef DEFN_BIN_FNC_T
2982#undef DEFN_BIN_FNC_OTHER
2983#undef DEFN_BIN_FNC
2984
2985
2986inline
2987void
2988lshift( sc_fxval& c, const sc_fxnum& a, int b )
2989{
2990    SC_FXNUM_OBSERVER_READ_( a )
2991    c.set_rep( sc_dt::lsh_scfx_rep( *a.m_rep, b ) );
2992}
2993
2994inline
2995void
2996rshift( sc_fxval& c, const sc_fxnum& a, int b )
2997{
2998    SC_FXNUM_OBSERVER_READ_( a )
2999    c.set_rep( sc_dt::rsh_scfx_rep( *a.m_rep, b ) );
3000}
3001
3002inline
3003void
3004lshift( sc_fxnum& c, const sc_fxnum& a, int b )
3005{
3006    SC_FXNUM_OBSERVER_READ_( a )
3007    delete c.m_rep;
3008    c.m_rep = sc_dt::lsh_scfx_rep( *a.m_rep, b );
3009    c.cast();
3010    SC_FXNUM_OBSERVER_WRITE_( c )
3011}
3012
3013inline
3014void
3015rshift( sc_fxnum& c, const sc_fxnum& a, int b )
3016{
3017    SC_FXNUM_OBSERVER_READ_( a )
3018    delete c.m_rep;
3019    c.m_rep = sc_dt::rsh_scfx_rep( *a.m_rep, b );
3020    c.cast();
3021    SC_FXNUM_OBSERVER_WRITE_( c )
3022}
3023
3024
3025// relational (including equality) operators
3026
3027#define DEFN_REL_OP_T(op,ret,tp)                                              \
3028inline                                                                        \
3029bool                                                                          \
3030operator op ( const sc_fxnum& a, tp b )                                       \
3031{                                                                             \
3032    SC_FXNUM_OBSERVER_READ_( a )                                              \
3033    sc_fxval tmp( b );                                                        \
3034    int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.get_rep() );            \
3035    return ( ret );                                                           \
3036}                                                                             \
3037                                                                              \
3038inline                                                                        \
3039bool                                                                          \
3040operator op ( tp a, const sc_fxnum& b )                                       \
3041{                                                                             \
3042    SC_FXNUM_OBSERVER_READ_( b )                                              \
3043    sc_fxval tmp( a );                                                        \
3044    int result = sc_dt::cmp_scfx_rep( *tmp.get_rep(), *b.m_rep );            \
3045    return ( ret );                                                           \
3046}
3047
3048#ifndef SC_FX_EXCLUDE_OTHER
3049#define DEFN_REL_OP_OTHER(op,ret)                                             \
3050DEFN_REL_OP_T(op,ret,int64)                                                   \
3051DEFN_REL_OP_T(op,ret,uint64)                                                  \
3052DEFN_REL_OP_T(op,ret,const sc_int_base&)                                      \
3053DEFN_REL_OP_T(op,ret,const sc_uint_base&)                                     \
3054DEFN_REL_OP_T(op,ret,const sc_signed&)                                        \
3055DEFN_REL_OP_T(op,ret,const sc_unsigned&)
3056#else
3057#define DEFN_REL_OP_OTHER(op,ret)
3058#endif
3059
3060#define DEFN_REL_OP(op,ret)                                                   \
3061inline                                                                        \
3062bool                                                                          \
3063operator op ( const sc_fxnum& a, const sc_fxnum& b )                          \
3064{                                                                             \
3065    SC_FXNUM_OBSERVER_READ_( a )                                              \
3066    SC_FXNUM_OBSERVER_READ_( b )                                              \
3067    int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.m_rep );                  \
3068    return ( ret );                                                           \
3069}                                                                             \
3070                                                                              \
3071inline                                                                        \
3072bool                                                                          \
3073operator op ( const sc_fxnum& a, const sc_fxval& b )                          \
3074{                                                                             \
3075    SC_FXNUM_OBSERVER_READ_( a )                                              \
3076    int result = sc_dt::cmp_scfx_rep( *a.m_rep, *b.get_rep() );              \
3077    return ( ret );                                                           \
3078}                                                                             \
3079                                                                              \
3080inline                                                                        \
3081bool                                                                          \
3082operator op ( const sc_fxval& a, const sc_fxnum& b )                          \
3083{                                                                             \
3084    SC_FXNUM_OBSERVER_READ_( b )                                              \
3085    int result = sc_dt::cmp_scfx_rep( *a.get_rep(), *b.m_rep );              \
3086    return ( ret );                                                           \
3087}                                                                             \
3088                                                                              \
3089DEFN_REL_OP_T(op,ret,int)                                                     \
3090DEFN_REL_OP_T(op,ret,unsigned int)                                            \
3091DEFN_REL_OP_T(op,ret,long)                                                    \
3092DEFN_REL_OP_T(op,ret,unsigned long)                                           \
3093DEFN_REL_OP_T(op,ret,float)                                                  \
3094DEFN_REL_OP_T(op,ret,double)                                                  \
3095DEFN_REL_OP_T(op,ret,const char*)                                             \
3096DEFN_REL_OP_T(op,ret,const sc_fxval_fast&)                                    \
3097DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)                                    \
3098DEFN_REL_OP_OTHER(op,ret)
3099
3100DEFN_REL_OP(<,result < 0)
3101DEFN_REL_OP(<=,result <= 0)
3102DEFN_REL_OP(>,result > 0 && result != 2)
3103DEFN_REL_OP(>=,result >= 0 && result != 2)
3104DEFN_REL_OP(==,result == 0)
3105DEFN_REL_OP(!=,result != 0)
3106
3107#undef DEFN_REL_OP_T
3108#undef DEFN_REL_OP_OTHER
3109#undef DEFN_REL_OP
3110
3111
3112// assignment operators
3113
3114inline
3115sc_fxnum&
3116sc_fxnum::operator = ( const sc_fxnum& a )
3117{
3118    if( &a != this )
3119    {
3120        SC_FXNUM_OBSERVER_READ_( a )
3121	*m_rep = *a.m_rep;
3122	cast();
3123	SC_FXNUM_OBSERVER_WRITE_( *this )
3124    }
3125    return *this;
3126}
3127
3128inline
3129sc_fxnum&
3130sc_fxnum::operator = ( const sc_fxval& a )
3131{
3132    *m_rep = *a.get_rep();
3133    cast();
3134    SC_FXNUM_OBSERVER_WRITE_( *this )
3135    return *this;
3136}
3137
3138#define DEFN_ASN_OP_T(tp)                                                     \
3139inline                                                                        \
3140sc_fxnum&                                                                     \
3141sc_fxnum::operator = ( tp a )                                                 \
3142{                                                                             \
3143    sc_fxval tmp( a );                                                        \
3144    *m_rep = *tmp.get_rep();                                                  \
3145    cast();                                                                   \
3146    SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
3147    return *this;                                                             \
3148}
3149
3150DEFN_ASN_OP_T(int)
3151DEFN_ASN_OP_T(unsigned int)
3152DEFN_ASN_OP_T(long)
3153DEFN_ASN_OP_T(unsigned long)
3154DEFN_ASN_OP_T(float)
3155DEFN_ASN_OP_T(double)
3156DEFN_ASN_OP_T(const char*)
3157DEFN_ASN_OP_T(const sc_fxval_fast&)
3158DEFN_ASN_OP_T(const sc_fxnum_fast&)
3159#ifndef SC_FX_EXCLUDE_OTHER
3160DEFN_ASN_OP_T(int64)
3161DEFN_ASN_OP_T(uint64)
3162DEFN_ASN_OP_T(const sc_int_base&)
3163DEFN_ASN_OP_T(const sc_uint_base&)
3164DEFN_ASN_OP_T(const sc_signed&)
3165DEFN_ASN_OP_T(const sc_unsigned&)
3166#endif
3167
3168#undef DEFN_ASN_OP_T
3169
3170
3171#define DEFN_ASN_OP_T(op,fnc,tp)                                              \
3172inline                                                                        \
3173sc_fxnum&                                                                     \
3174sc_fxnum::operator op ( tp b )                                                \
3175{                                                                             \
3176    SC_FXNUM_OBSERVER_READ_( *this )                                          \
3177    sc_fxval tmp( b );                                                        \
3178    scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.get_rep() );   \
3179    delete m_rep;                                                             \
3180    m_rep = new_rep;                                                          \
3181    cast();                                                                   \
3182    SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
3183    return *this;                                                             \
3184}
3185
3186#ifndef SC_FX_EXCLUDE_OTHER
3187#define DEFN_ASN_OP_OTHER(op,fnc)                                             \
3188DEFN_ASN_OP_T(op,fnc,int64)                                                   \
3189DEFN_ASN_OP_T(op,fnc,uint64)                                                  \
3190DEFN_ASN_OP_T(op,fnc,const sc_int_base&)                                      \
3191DEFN_ASN_OP_T(op,fnc,const sc_uint_base&)                                     \
3192DEFN_ASN_OP_T(op,fnc,const sc_signed&)                                        \
3193DEFN_ASN_OP_T(op,fnc,const sc_unsigned&)
3194#else
3195#define DEFN_ASN_OP_OTHER(op,fnc)
3196#endif
3197
3198#define DEFN_ASN_OP(op,fnc)                                                   \
3199inline                                                                        \
3200sc_fxnum&                                                                     \
3201sc_fxnum::operator op ( const sc_fxnum& b )                                   \
3202{                                                                             \
3203    SC_FXNUM_OBSERVER_READ_( *this )                                          \
3204    SC_FXNUM_OBSERVER_READ_( b )                                              \
3205    scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.m_rep );         \
3206    delete m_rep;                                                             \
3207    m_rep = new_rep;                                                          \
3208    cast();                                                                   \
3209    SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
3210    return *this;                                                             \
3211}                                                                             \
3212                                                                              \
3213inline                                                                        \
3214sc_fxnum&                                                                     \
3215sc_fxnum::operator op ( const sc_fxval& b )                                   \
3216{                                                                             \
3217    SC_FXNUM_OBSERVER_READ_( *this )                                          \
3218    scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
3219    delete m_rep;                                                             \
3220    m_rep = new_rep;                                                          \
3221    cast();                                                                   \
3222    SC_FXNUM_OBSERVER_WRITE_( *this )                                         \
3223    return *this;                                                             \
3224}                                                                             \
3225                                                                              \
3226DEFN_ASN_OP_T(op,fnc,int)                                                     \
3227DEFN_ASN_OP_T(op,fnc,unsigned int)                                            \
3228DEFN_ASN_OP_T(op,fnc,long)                                                    \
3229DEFN_ASN_OP_T(op,fnc,unsigned long)                                           \
3230DEFN_ASN_OP_T(op,fnc,float)                                                  \
3231DEFN_ASN_OP_T(op,fnc,double)                                                  \
3232DEFN_ASN_OP_T(op,fnc,const char*)                                             \
3233DEFN_ASN_OP_T(op,fnc,const sc_fxval_fast&)                                    \
3234DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)                                    \
3235DEFN_ASN_OP_OTHER(op,fnc)
3236
3237DEFN_ASN_OP(*=,mult)
3238DEFN_ASN_OP(/=,div)
3239DEFN_ASN_OP(+=,add)
3240DEFN_ASN_OP(-=,sub)
3241
3242#undef DEFN_ASN_OP_T
3243#undef DEFN_ASN_OP_OTHER
3244#undef DEFN_ASN_OP
3245
3246
3247inline
3248sc_fxnum&
3249sc_fxnum::operator <<= ( int b )
3250{
3251    SC_FXNUM_OBSERVER_READ_( *this )
3252    m_rep->lshift( b );
3253    cast();
3254    SC_FXNUM_OBSERVER_WRITE_( *this )
3255    return *this;
3256}
3257
3258inline
3259sc_fxnum&
3260sc_fxnum::operator >>= ( int b )
3261{
3262    SC_FXNUM_OBSERVER_READ_( *this )
3263    m_rep->rshift( b );
3264    cast();
3265    SC_FXNUM_OBSERVER_WRITE_( *this )
3266    return *this;
3267}
3268
3269
3270// auto-increment and auto-decrement
3271
3272inline
3273const sc_fxval
3274sc_fxnum::operator ++ ( int )
3275{
3276    sc_fxval c( *this );
3277    (*this) += 1;
3278    return c;
3279}
3280
3281inline
3282const sc_fxval
3283sc_fxnum::operator -- ( int )
3284{
3285    sc_fxval c( *this );
3286    (*this) -= 1;
3287    return c;
3288}
3289
3290inline
3291sc_fxnum&
3292sc_fxnum::operator ++ ()
3293{
3294    (*this) += 1;
3295    return *this;
3296}
3297
3298inline
3299sc_fxnum&
3300sc_fxnum::operator -- ()
3301{
3302    (*this) -= 1;
3303    return *this;
3304}
3305
3306
3307// bit selection
3308
3309inline
3310const sc_fxnum_bitref
3311sc_fxnum::operator [] ( int i ) const
3312{
3313    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3314    return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
3315			    i - m_params.fwl() );
3316}
3317
3318inline
3319sc_fxnum_bitref
3320sc_fxnum::operator [] ( int i )
3321{
3322    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3323    return sc_fxnum_bitref( *this, i - m_params.fwl() );
3324}
3325
3326inline
3327const sc_fxnum_bitref
3328sc_fxnum::bit( int i ) const
3329{
3330    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3331    return sc_fxnum_bitref( const_cast<sc_fxnum&>( *this ),
3332			    i - m_params.fwl() );
3333}
3334
3335inline
3336sc_fxnum_bitref
3337sc_fxnum::bit( int i )
3338{
3339    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3340    return sc_fxnum_bitref( *this, i - m_params.fwl() );
3341}
3342
3343
3344// part selection
3345
3346inline
3347const sc_fxnum_subref
3348sc_fxnum::operator () ( int i, int j ) const
3349{
3350    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3351    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3352
3353    return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
3354			    i - m_params.fwl(), j - m_params.fwl() );
3355}
3356
3357inline
3358sc_fxnum_subref
3359sc_fxnum::operator () ( int i, int j )
3360{
3361    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3362    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3363
3364    return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
3365}
3366
3367inline
3368const sc_fxnum_subref
3369sc_fxnum::range( int i, int j ) const
3370{
3371    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3372    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3373
3374    return sc_fxnum_subref( const_cast<sc_fxnum&>( *this ),
3375			    i - m_params.fwl(), j - m_params.fwl() );
3376}
3377
3378inline
3379sc_fxnum_subref
3380sc_fxnum::range( int i, int j )
3381{
3382    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3383    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
3384
3385    return sc_fxnum_subref( *this, i - m_params.fwl(), j - m_params.fwl() );
3386}
3387
3388
3389inline
3390const sc_fxnum_subref
3391sc_fxnum::operator () () const
3392{
3393    return this->operator () ( m_params.wl() - 1, 0 );
3394}
3395
3396inline
3397sc_fxnum_subref
3398sc_fxnum::operator () ()
3399{
3400    return this->operator () ( m_params.wl() - 1, 0 );
3401}
3402
3403inline
3404const sc_fxnum_subref
3405sc_fxnum::range() const
3406{
3407    return this->range( m_params.wl() - 1, 0 );
3408}
3409
3410inline
3411sc_fxnum_subref
3412sc_fxnum::range()
3413{
3414    return this->range( m_params.wl() - 1, 0 );
3415}
3416
3417
3418// implicit conversion
3419
3420inline
3421sc_fxnum::operator double() const
3422{
3423    SC_FXNUM_OBSERVER_READ_( *this )
3424    return m_rep->to_double();
3425}
3426
3427
3428// explicit conversion to primitive types
3429
3430inline
3431short
3432sc_fxnum::to_short() const
3433{
3434    SC_FXNUM_OBSERVER_READ_( *this )
3435    return static_cast<short>( m_rep->to_double() );
3436}
3437
3438inline
3439unsigned short
3440sc_fxnum::to_ushort() const
3441{
3442    SC_FXNUM_OBSERVER_READ_( *this )
3443    return static_cast<unsigned short>( m_rep->to_double() );
3444}
3445
3446inline
3447int
3448sc_fxnum::to_int() const
3449{
3450    SC_FXNUM_OBSERVER_READ_( *this )
3451    return static_cast<int>( m_rep->to_double() );
3452}
3453
3454inline
3455int64
3456sc_fxnum::to_int64() const
3457{
3458    SC_FXNUM_OBSERVER_READ_( *this )
3459    return static_cast<int64>( m_rep->to_double() );
3460}
3461
3462inline
3463unsigned int
3464sc_fxnum::to_uint() const
3465{
3466    SC_FXNUM_OBSERVER_READ_( *this )
3467    return static_cast<unsigned int>( m_rep->to_double() );
3468}
3469
3470inline
3471uint64
3472sc_fxnum::to_uint64() const
3473{
3474    SC_FXNUM_OBSERVER_READ_( *this )
3475    return static_cast<uint64>( m_rep->to_double() );
3476}
3477
3478inline
3479long
3480sc_fxnum::to_long() const
3481{
3482    SC_FXNUM_OBSERVER_READ_( *this )
3483    return static_cast<long>( m_rep->to_double() );
3484}
3485
3486inline
3487unsigned long
3488sc_fxnum::to_ulong() const
3489{
3490    SC_FXNUM_OBSERVER_READ_( *this )
3491    return static_cast<unsigned long>( m_rep->to_double() );
3492}
3493
3494inline
3495float
3496sc_fxnum::to_float() const
3497{
3498    SC_FXNUM_OBSERVER_READ_( *this )
3499    return static_cast<float>( m_rep->to_double() );
3500}
3501
3502inline
3503double
3504sc_fxnum::to_double() const
3505{
3506    SC_FXNUM_OBSERVER_READ_( *this )
3507    return m_rep->to_double();
3508}
3509
3510
3511// query value
3512
3513inline
3514bool
3515sc_fxnum::is_neg() const
3516{
3517    SC_FXNUM_OBSERVER_READ_( *this )
3518    return m_rep->is_neg();
3519}
3520
3521inline
3522bool
3523sc_fxnum::is_zero() const
3524{
3525    SC_FXNUM_OBSERVER_READ_( *this )
3526    return m_rep->is_zero();
3527}
3528
3529// internal use only;
3530inline
3531bool
3532sc_fxnum::is_normal() const
3533{
3534    SC_FXNUM_OBSERVER_READ_( *this )
3535    return m_rep->is_normal();
3536}
3537
3538inline
3539bool
3540sc_fxnum::quantization_flag() const
3541{
3542    return m_q_flag;
3543}
3544
3545inline
3546bool
3547sc_fxnum::overflow_flag() const
3548{
3549    return m_o_flag;
3550}
3551
3552
3553inline
3554const sc_fxval
3555sc_fxnum::value() const
3556{
3557    SC_FXNUM_OBSERVER_READ_( *this )
3558    return sc_fxval( new scfx_rep( *m_rep ) );
3559}
3560
3561
3562// query parameters
3563
3564inline
3565int
3566sc_fxnum::wl() const
3567{
3568    return m_params.wl();
3569}
3570
3571inline
3572int
3573sc_fxnum::iwl() const
3574{
3575    return m_params.iwl();
3576}
3577
3578inline
3579sc_q_mode
3580sc_fxnum::q_mode() const
3581{
3582    return m_params.q_mode();
3583}
3584
3585inline
3586sc_o_mode
3587sc_fxnum::o_mode() const
3588{
3589    return m_params.o_mode();
3590}
3591
3592inline
3593int
3594sc_fxnum::n_bits() const
3595{
3596    return m_params.n_bits();
3597}
3598
3599
3600inline
3601const sc_fxtype_params&
3602sc_fxnum::type_params() const
3603{
3604    return m_params.type_params();
3605}
3606
3607
3608inline
3609const sc_fxcast_switch&
3610sc_fxnum::cast_switch() const
3611{
3612    return m_params.cast_switch();
3613}
3614
3615
3616// internal use only;
3617inline
3618void
3619sc_fxnum::observer_read() const
3620{
3621    SC_FXNUM_OBSERVER_READ_( *this );
3622}
3623
3624
3625// internal use only;
3626inline
3627bool
3628sc_fxnum::get_bit( int i ) const
3629{
3630    return m_rep->get_bit( i );
3631}
3632
3633
3634// protected methods and friend functions
3635
3636inline
3637bool
3638sc_fxnum::set_bit( int i, bool high )
3639{
3640    if( high )
3641        return m_rep->set( i, m_params );
3642    else
3643        return m_rep->clear( i, m_params );
3644}
3645
3646
3647inline
3648bool
3649sc_fxnum::get_slice( int i, int j, sc_bv_base& bv ) const
3650{
3651    return m_rep->get_slice( i, j, m_params, bv );
3652}
3653
3654inline
3655bool
3656sc_fxnum::set_slice( int i, int j, const sc_bv_base& bv )
3657{
3658    return m_rep->set_slice( i, j, m_params, bv );
3659}
3660
3661
3662inline
3663::std::ostream&
3664operator << ( ::std::ostream& os, const sc_fxnum& a )
3665{
3666    a.print( os );
3667    return os;
3668}
3669
3670inline
3671::std::istream&
3672operator >> ( ::std::istream& is, sc_fxnum& a )
3673{
3674    a.scan( is );
3675    return is;
3676}
3677
3678
3679// ----------------------------------------------------------------------------
3680//  CLASS : sc_fxnum_fast
3681//
3682//  Base class for the fixed-point types; limited precision.
3683// ----------------------------------------------------------------------------
3684
3685inline
3686sc_fxnum_fast_observer*
3687sc_fxnum_fast::observer() const
3688{
3689    return m_observer;
3690}
3691
3692
3693// constructors
3694
3695inline
3696sc_fxnum_fast::sc_fxnum_fast( const sc_fxtype_params& type_params_,
3697			      sc_enc enc_,
3698			      const sc_fxcast_switch& cast_sw,
3699			      sc_fxnum_fast_observer* observer_ )
3700: m_val( 0.0 ),
3701  m_params( type_params_, enc_, cast_sw ),
3702  m_q_flag( false ),
3703  m_o_flag( false ),
3704  m_observer( observer_ )
3705{
3706    SC_FXNUM_FAST_OBSERVER_DEFAULT_
3707    SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)
3708}
3709
3710inline
3711sc_fxnum_fast::sc_fxnum_fast( const sc_fxnum_fast& a,
3712			      const sc_fxtype_params& type_params_,
3713			      sc_enc enc_,
3714			      const sc_fxcast_switch& cast_sw,
3715			      sc_fxnum_fast_observer* observer_ )
3716: m_val( a.m_val ),
3717  m_params( type_params_, enc_, cast_sw ),
3718  m_q_flag( false ),
3719  m_o_flag( false ),
3720  m_observer( observer_ )
3721{
3722    SC_FXNUM_FAST_OBSERVER_DEFAULT_
3723    SC_FXNUM_FAST_OBSERVER_READ_( a )
3724    cast();
3725    SC_FXNUM_FAST_OBSERVER_CONSTRUCT_( *this )
3726    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
3727}
3728
3729#define DEFN_CTOR_T(tp,arg)                                                   \
3730inline                                                                        \
3731sc_fxnum_fast::sc_fxnum_fast( tp a,                                           \
3732		              const sc_fxtype_params& type_params_,           \
3733		              sc_enc enc_,                                    \
3734		              const sc_fxcast_switch& cast_sw,                \
3735		              sc_fxnum_fast_observer* observer_ )             \
3736: m_val( arg ),                                                               \
3737  m_params( type_params_, enc_, cast_sw ),                                    \
3738  m_q_flag( false ),                                                          \
3739  m_o_flag( false ),                                                          \
3740  m_observer( observer_ )                                                     \
3741{                                                                             \
3742    SC_FXNUM_FAST_OBSERVER_DEFAULT_                                           \
3743    cast();                                                                   \
3744    SC_FXNUM_FAST_OBSERVER_CONSTRUCT_(*this)                                  \
3745    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
3746}
3747
3748#define DEFN_CTOR_T_A(tp) DEFN_CTOR_T(tp,static_cast<double>( a ))
3749#define DEFN_CTOR_T_B(tp) DEFN_CTOR_T(tp,sc_fxval_fast::from_string( a ))
3750#define DEFN_CTOR_T_C(tp) DEFN_CTOR_T(tp,a.to_double())
3751
3752DEFN_CTOR_T_A(int)
3753DEFN_CTOR_T_A(unsigned int)
3754DEFN_CTOR_T_A(long)
3755DEFN_CTOR_T_A(unsigned long)
3756DEFN_CTOR_T_A(float)
3757DEFN_CTOR_T_A(double)
3758DEFN_CTOR_T_B(const char*)
3759DEFN_CTOR_T_C(const sc_fxval&)
3760DEFN_CTOR_T_C(const sc_fxval_fast&)
3761DEFN_CTOR_T_C(const sc_fxnum&)
3762#ifndef SC_FX_EXCLUDE_OTHER
3763DEFN_CTOR_T_A(int64)
3764DEFN_CTOR_T_A(uint64)
3765DEFN_CTOR_T_C(const sc_int_base&)
3766DEFN_CTOR_T_C(const sc_uint_base&)
3767DEFN_CTOR_T_C(const sc_signed&)
3768DEFN_CTOR_T_C(const sc_unsigned&)
3769#endif
3770
3771#undef DEFN_CTOR_T
3772#undef DEFN_CTOR_T_A
3773#undef DEFN_CTOR_T_B
3774#undef DEFN_CTOR_T_C
3775#undef DEFN_CTOR_T_D
3776#undef DEFN_CTOR_T_E
3777
3778
3779inline
3780sc_fxnum_fast::~sc_fxnum_fast()
3781{
3782    SC_FXNUM_FAST_OBSERVER_DESTRUCT_( *this )
3783}
3784
3785
3786// internal use only;
3787inline
3788double
3789sc_fxnum_fast::get_val() const
3790{
3791    SC_FXNUM_FAST_OBSERVER_READ_( *this )
3792    return m_val;
3793}
3794
3795
3796// unary operators
3797
3798inline
3799const sc_fxval_fast
3800sc_fxnum_fast::operator - () const
3801{
3802    SC_FXNUM_FAST_OBSERVER_READ_( *this )
3803    return sc_fxval_fast( - m_val );
3804}
3805
3806inline
3807const sc_fxval_fast
3808sc_fxnum_fast::operator + () const
3809{
3810    SC_FXNUM_FAST_OBSERVER_READ_( *this )
3811    return sc_fxval_fast( m_val );
3812}
3813
3814
3815// unary functions
3816
3817inline
3818void
3819neg( sc_fxval_fast& c, const sc_fxnum_fast& a )
3820{
3821    SC_FXNUM_FAST_OBSERVER_READ_( a )
3822    c.set_val( - a.m_val );
3823}
3824
3825inline
3826void
3827neg( sc_fxnum_fast& c, const sc_fxnum_fast& a )
3828{
3829    SC_FXNUM_FAST_OBSERVER_READ_( a )
3830    c.m_val = - a.m_val;
3831    c.cast();
3832    SC_FXNUM_FAST_OBSERVER_WRITE_( c )
3833}
3834
3835
3836// binary operators
3837
3838#define DEFN_BIN_OP_T(op,tp)                                                  \
3839inline                                                                        \
3840const sc_fxval_fast                                                           \
3841operator op ( const sc_fxnum_fast& a, tp b )                                  \
3842{                                                                             \
3843    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
3844    sc_fxval_fast tmp( b );                                                   \
3845    return sc_fxval_fast( a.m_val op tmp.get_val() );                         \
3846}                                                                             \
3847                                                                              \
3848inline                                                                        \
3849const sc_fxval_fast                                                           \
3850operator op ( tp a, const sc_fxnum_fast& b )                                  \
3851{                                                                             \
3852    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
3853    sc_fxval_fast tmp( a );                                                   \
3854    return sc_fxval_fast( tmp.get_val() op b.m_val );                         \
3855}
3856
3857#ifndef SC_FX_EXCLUDE_OTHER
3858#define DEFN_BIN_OP_OTHER(op)                                                 \
3859DEFN_BIN_OP_T(op,int64)                                                       \
3860DEFN_BIN_OP_T(op,uint64)                                                      \
3861DEFN_BIN_OP_T(op,const sc_int_base&)                                          \
3862DEFN_BIN_OP_T(op,const sc_uint_base&)                                         \
3863DEFN_BIN_OP_T(op,const sc_signed&)                                            \
3864DEFN_BIN_OP_T(op,const sc_unsigned&)
3865#else
3866#define DEFN_BIN_OP_OTHER(op)
3867#endif
3868
3869#define DEFN_BIN_OP(op,dummy)                                                 \
3870inline                                                                        \
3871const sc_fxval_fast                                                           \
3872operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
3873{                                                                             \
3874    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
3875    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
3876    return sc_fxval_fast( a.m_val op b.m_val );                               \
3877}                                                                             \
3878                                                                              \
3879inline                                                                        \
3880const sc_fxval_fast                                                           \
3881operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
3882{                                                                             \
3883    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
3884    return sc_fxval_fast( a.m_val op b.get_val() );                           \
3885}                                                                             \
3886                                                                              \
3887inline                                                                        \
3888const sc_fxval_fast                                                           \
3889operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
3890{                                                                             \
3891    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
3892    return sc_fxval_fast( a.get_val() op b.m_val );                           \
3893}                                                                             \
3894                                                                              \
3895DEFN_BIN_OP_T(op,int)                                                         \
3896DEFN_BIN_OP_T(op,unsigned int)                                                \
3897DEFN_BIN_OP_T(op,long)                                                        \
3898DEFN_BIN_OP_T(op,unsigned long)                                               \
3899DEFN_BIN_OP_T(op,float)                                                      \
3900DEFN_BIN_OP_T(op,double)                                                      \
3901DEFN_BIN_OP_T(op,const char*)                                                 \
3902DEFN_BIN_OP_OTHER(op)
3903
3904DEFN_BIN_OP(*,mult)
3905DEFN_BIN_OP(+,add)
3906DEFN_BIN_OP(-,sub)
3907//DEFN_BIN_OP(/,div)
3908inline
3909const sc_fxval_fast
3910operator / ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )
3911{
3912    SC_FXNUM_FAST_OBSERVER_READ_( a )
3913    SC_FXNUM_FAST_OBSERVER_READ_( b )
3914    return sc_fxval_fast( a.m_val / b.m_val );
3915}
3916
3917inline
3918const sc_fxval_fast
3919operator / ( const sc_fxnum_fast& a, const sc_fxval_fast& b )
3920{
3921    SC_FXNUM_FAST_OBSERVER_READ_( a )
3922    return sc_fxval_fast( a.m_val / b.get_val() );
3923}
3924
3925inline
3926const sc_fxval_fast
3927operator / ( const sc_fxval_fast& a, const sc_fxnum_fast& b )
3928{
3929    SC_FXNUM_FAST_OBSERVER_READ_( b )
3930    return sc_fxval_fast( a.get_val() / b.m_val );
3931}
3932
3933DEFN_BIN_OP_T(/,int)
3934DEFN_BIN_OP_T(/,unsigned int)
3935DEFN_BIN_OP_T(/,long)
3936DEFN_BIN_OP_T(/,unsigned long)
3937DEFN_BIN_OP_T(/,float)
3938DEFN_BIN_OP_T(/,double)
3939DEFN_BIN_OP_T(/,const char*)
3940//DEFN_BIN_OP_OTHER(/)
3941#ifndef SC_FX_EXCLUDE_OTHER
3942DEFN_BIN_OP_T(/,int64)
3943DEFN_BIN_OP_T(/,uint64)
3944DEFN_BIN_OP_T(/,const sc_int_base&)
3945DEFN_BIN_OP_T(/,const sc_uint_base&)
3946DEFN_BIN_OP_T(/,const sc_signed&)
3947DEFN_BIN_OP_T(/,const sc_unsigned&)
3948#endif
3949
3950#undef DEFN_BIN_OP_T
3951#undef DEFN_BIN_OP_OTHER
3952#undef DEFN_BIN_OP
3953
3954
3955inline
3956const sc_fxval_fast
3957operator << ( const sc_fxnum_fast& a, int b )
3958{
3959    SC_FXNUM_FAST_OBSERVER_READ_( a )
3960    return sc_fxval_fast( a.m_val * scfx_pow2( b ) );
3961}
3962
3963inline
3964const sc_fxval_fast
3965operator >> ( const sc_fxnum_fast& a, int b )
3966{
3967    SC_FXNUM_FAST_OBSERVER_READ_( a )
3968    return sc_fxval_fast( a.m_val * scfx_pow2( -b ) );
3969}
3970
3971
3972// binary functions
3973
3974#define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
3975inline                                                                        \
3976void                                                                          \
3977fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, tp b )                        \
3978{                                                                             \
3979    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
3980    sc_fxval_fast tmp( b );                                                   \
3981    c.set_val( a.m_val op tmp.get_val() );                                    \
3982}                                                                             \
3983                                                                              \
3984inline                                                                        \
3985void                                                                          \
3986fnc ( sc_fxval_fast& c, tp a, const sc_fxnum_fast& b )                        \
3987{                                                                             \
3988    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
3989    sc_fxval_fast tmp( a );                                                   \
3990    c.set_val( tmp.get_val() op b.m_val );                                    \
3991}                                                                             \
3992                                                                              \
3993inline                                                                        \
3994void                                                                          \
3995fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, tp b )                        \
3996{                                                                             \
3997    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
3998    sc_fxval_fast tmp( b );                                                   \
3999    c.m_val = a.m_val op tmp.get_val();                                       \
4000    c.cast();                                                                 \
4001    SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
4002}                                                                             \
4003                                                                              \
4004inline                                                                        \
4005void                                                                          \
4006fnc ( sc_fxnum_fast& c, tp a, const sc_fxnum_fast& b )                        \
4007{                                                                             \
4008    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4009    sc_fxval_fast tmp( a );                                                   \
4010    c.m_val = tmp.get_val() op b.m_val;                                       \
4011    c.cast();                                                                 \
4012    SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
4013}
4014
4015#ifndef SC_FX_EXCLUDE_OTHER
4016#define DEFN_BIN_FNC_OTHER(fnc,op)                                            \
4017DEFN_BIN_FNC_T(fnc,op,int64)                                                  \
4018DEFN_BIN_FNC_T(fnc,op,uint64)                                                 \
4019DEFN_BIN_FNC_T(fnc,op,const sc_int_base&)                                     \
4020DEFN_BIN_FNC_T(fnc,op,const sc_uint_base&)                                    \
4021DEFN_BIN_FNC_T(fnc,op,const sc_signed&)                                       \
4022DEFN_BIN_FNC_T(fnc,op,const sc_unsigned&)
4023#else
4024#define DEFN_BIN_FNC_OTHER(fnc,op)
4025#endif
4026
4027#define DEFN_BIN_FNC(fnc,op)                                                  \
4028inline                                                                        \
4029void                                                                          \
4030fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
4031{                                                                             \
4032    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4033    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4034    c.set_val( a.m_val op b.m_val );                                          \
4035}                                                                             \
4036                                                                              \
4037inline                                                                        \
4038void                                                                          \
4039fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxnum_fast& b )      \
4040{                                                                             \
4041    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4042    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4043    c.m_val = a.m_val op b.m_val;                                             \
4044    c.cast();                                                                 \
4045    SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
4046}                                                                             \
4047                                                                              \
4048inline                                                                        \
4049void                                                                          \
4050fnc ( sc_fxval_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
4051{                                                                             \
4052    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4053    c.set_val( a.m_val op b.get_val() );                                      \
4054}                                                                             \
4055                                                                              \
4056inline                                                                        \
4057void                                                                          \
4058fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
4059{                                                                             \
4060    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4061    c.set_val( a.get_val() op b.m_val );                                      \
4062}                                                                             \
4063                                                                              \
4064inline                                                                        \
4065void                                                                          \
4066fnc ( sc_fxnum_fast& c, const sc_fxnum_fast& a, const sc_fxval_fast& b )      \
4067{                                                                             \
4068    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4069    c.m_val = a.m_val op b.get_val();                                         \
4070    c.cast();                                                                 \
4071    SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
4072}                                                                             \
4073                                                                              \
4074inline                                                                        \
4075void                                                                          \
4076fnc ( sc_fxnum_fast& c, const sc_fxval_fast& a, const sc_fxnum_fast& b )      \
4077{                                                                             \
4078    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4079    c.m_val = a.get_val() op b.m_val;                                         \
4080    c.cast();                                                                 \
4081    SC_FXNUM_FAST_OBSERVER_WRITE_( c )                                        \
4082}                                                                             \
4083                                                                              \
4084DEFN_BIN_FNC_T(fnc,op,int)                                                    \
4085DEFN_BIN_FNC_T(fnc,op,unsigned int)                                           \
4086DEFN_BIN_FNC_T(fnc,op,long)                                                   \
4087DEFN_BIN_FNC_T(fnc,op,unsigned long)                                          \
4088DEFN_BIN_FNC_T(fnc,op,float)                                                 \
4089DEFN_BIN_FNC_T(fnc,op,double)                                                 \
4090DEFN_BIN_FNC_T(fnc,op,const char*)                                            \
4091DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
4092DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)                                        \
4093DEFN_BIN_FNC_OTHER(fnc,op)
4094
4095DEFN_BIN_FNC(mult,*)
4096DEFN_BIN_FNC(div,/)
4097DEFN_BIN_FNC(add,+)
4098DEFN_BIN_FNC(sub,-)
4099
4100#undef DEFN_BIN_FNC_T
4101#undef DEFN_BIN_FNC_OTHER
4102#undef DEFN_BIN_FNC
4103
4104
4105inline
4106void
4107lshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
4108{
4109    SC_FXNUM_FAST_OBSERVER_READ_( a )
4110    c.set_val( a.m_val * scfx_pow2( b ) );
4111}
4112
4113inline
4114void
4115rshift( sc_fxval_fast& c, const sc_fxnum_fast& a, int b )
4116{
4117    SC_FXNUM_FAST_OBSERVER_READ_( a )
4118    c.set_val( a.m_val * scfx_pow2( -b ) );
4119}
4120
4121inline
4122void
4123lshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
4124{
4125    SC_FXNUM_FAST_OBSERVER_READ_( a )
4126    c.m_val = a.m_val * scfx_pow2( b );
4127    c.cast();
4128    SC_FXNUM_FAST_OBSERVER_WRITE_( c )
4129}
4130
4131inline
4132void
4133rshift( sc_fxnum_fast& c, const sc_fxnum_fast& a, int b )
4134{
4135    SC_FXNUM_FAST_OBSERVER_READ_( a )
4136    c.m_val = a.m_val * scfx_pow2( -b );
4137    c.cast();
4138    SC_FXNUM_FAST_OBSERVER_WRITE_( c )
4139}
4140
4141
4142// relational (including equality) operators
4143
4144#define DEFN_REL_OP_T(op,tp)                                                  \
4145inline                                                                        \
4146bool                                                                          \
4147operator op ( const sc_fxnum_fast& a, tp b )                                  \
4148{                                                                             \
4149    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4150    sc_fxval_fast tmp( b );                                                   \
4151    return ( a.m_val op tmp.get_val() );                                      \
4152}                                                                             \
4153                                                                              \
4154inline                                                                        \
4155bool                                                                          \
4156operator op ( tp a, const sc_fxnum_fast& b )                                  \
4157{                                                                             \
4158    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4159    sc_fxval_fast tmp( a );                                                   \
4160    return ( tmp.get_val() op b.m_val );                                      \
4161}
4162
4163#ifndef SC_FX_EXCLUDE_OTHER
4164#define DEFN_REL_OP_OTHER(op)                                                 \
4165DEFN_REL_OP_T(op,int64)                                                       \
4166DEFN_REL_OP_T(op,uint64)                                                      \
4167DEFN_REL_OP_T(op,const sc_int_base&)                                          \
4168DEFN_REL_OP_T(op,const sc_uint_base&)                                         \
4169DEFN_REL_OP_T(op,const sc_signed&)                                            \
4170DEFN_REL_OP_T(op,const sc_unsigned&)
4171#else
4172#define DEFN_REL_OP_OTHER(op)
4173#endif
4174
4175#define DEFN_REL_OP(op)                                                       \
4176inline                                                                        \
4177bool                                                                          \
4178operator op ( const sc_fxnum_fast& a, const sc_fxnum_fast& b )                \
4179{                                                                             \
4180    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4181    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4182    return ( a.m_val op b.m_val );                                            \
4183}                                                                             \
4184                                                                              \
4185inline                                                                        \
4186bool                                                                          \
4187operator op ( const sc_fxnum_fast& a, const sc_fxval_fast& b )                \
4188{                                                                             \
4189    SC_FXNUM_FAST_OBSERVER_READ_( a )                                         \
4190    return ( a.m_val op b.get_val() );                                        \
4191}                                                                             \
4192                                                                              \
4193inline                                                                        \
4194bool                                                                          \
4195operator op ( const sc_fxval_fast& a, const sc_fxnum_fast& b )                \
4196{                                                                             \
4197    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4198    return ( a.get_val() op b.m_val );                                        \
4199}                                                                             \
4200                                                                              \
4201DEFN_REL_OP_T(op,int)                                                         \
4202DEFN_REL_OP_T(op,unsigned int)                                                \
4203DEFN_REL_OP_T(op,long)                                                        \
4204DEFN_REL_OP_T(op,unsigned long)                                               \
4205DEFN_REL_OP_T(op,float)                                                      \
4206DEFN_REL_OP_T(op,double)                                                      \
4207DEFN_REL_OP_T(op,const char*)                                                 \
4208DEFN_REL_OP_OTHER(op)
4209
4210DEFN_REL_OP(<)
4211DEFN_REL_OP(<=)
4212DEFN_REL_OP(>)
4213DEFN_REL_OP(>=)
4214DEFN_REL_OP(==)
4215DEFN_REL_OP(!=)
4216
4217#undef DEFN_REL_OP_T
4218#undef DEFN_REL_OP_OTHER
4219#undef DEFN_REL_OP
4220
4221
4222// assignment operators
4223
4224inline
4225sc_fxnum_fast&
4226sc_fxnum_fast::operator = ( const sc_fxnum_fast& a )
4227{
4228    if( &a != this )
4229    {
4230	SC_FXNUM_FAST_OBSERVER_READ_( a )
4231	m_val = a.m_val;
4232	cast();
4233	SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4234    }
4235    return *this;
4236}
4237
4238inline
4239sc_fxnum_fast&
4240sc_fxnum_fast::operator = ( const sc_fxval_fast& a )
4241{
4242    m_val = a.get_val();
4243    cast();
4244    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4245    return *this;
4246}
4247
4248#define DEFN_ASN_OP_T(tp)                                                     \
4249inline                                                                        \
4250sc_fxnum_fast&                                                                \
4251sc_fxnum_fast::operator = ( tp a )                                            \
4252{                                                                             \
4253    sc_fxval_fast tmp( a );                                                   \
4254    m_val = tmp.get_val();                                                    \
4255    cast();                                                                   \
4256    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
4257    return *this;                                                             \
4258}
4259
4260DEFN_ASN_OP_T(int)
4261DEFN_ASN_OP_T(unsigned int)
4262DEFN_ASN_OP_T(long)
4263DEFN_ASN_OP_T(unsigned long)
4264DEFN_ASN_OP_T(float)
4265DEFN_ASN_OP_T(double)
4266DEFN_ASN_OP_T(const char*)
4267DEFN_ASN_OP_T(const sc_fxval&)
4268DEFN_ASN_OP_T(const sc_fxnum&)
4269#ifndef SC_FX_EXCLUDE_OTHER
4270DEFN_ASN_OP_T(int64)
4271DEFN_ASN_OP_T(uint64)
4272DEFN_ASN_OP_T(const sc_int_base&)
4273DEFN_ASN_OP_T(const sc_uint_base&)
4274DEFN_ASN_OP_T(const sc_signed&)
4275DEFN_ASN_OP_T(const sc_unsigned&)
4276#endif
4277
4278#undef DEFN_ASN_OP_T
4279
4280
4281#define DEFN_ASN_OP_T(op,tp)                                                  \
4282inline                                                                        \
4283sc_fxnum_fast&                                                                \
4284sc_fxnum_fast::operator op ( tp b )                                           \
4285{                                                                             \
4286    SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
4287    sc_fxval_fast tmp( b );                                                   \
4288    m_val op tmp.get_val();                                                   \
4289    cast();                                                                   \
4290    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
4291    return *this;                                                             \
4292}
4293
4294#ifndef SC_FX_EXCLUDE_OTHER
4295#define DEFN_ASN_OP_OTHER(op)                                                 \
4296DEFN_ASN_OP_T(op,int64)                                                       \
4297DEFN_ASN_OP_T(op,uint64)                                                      \
4298DEFN_ASN_OP_T(op,const sc_int_base&)                                          \
4299DEFN_ASN_OP_T(op,const sc_uint_base&)                                         \
4300DEFN_ASN_OP_T(op,const sc_signed&)                                            \
4301DEFN_ASN_OP_T(op,const sc_unsigned&)
4302#else
4303#define DEFN_ASN_OP_OTHER(op)
4304#endif
4305
4306#define DEFN_ASN_OP(op)                                                       \
4307inline                                                                        \
4308sc_fxnum_fast&                                                                \
4309sc_fxnum_fast::operator op ( const sc_fxnum_fast& b )                         \
4310{                                                                             \
4311    SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
4312    SC_FXNUM_FAST_OBSERVER_READ_( b )                                         \
4313    m_val op b.m_val;                                                         \
4314    cast();                                                                   \
4315    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
4316    return *this;                                                             \
4317}                                                                             \
4318                                                                              \
4319inline                                                                        \
4320sc_fxnum_fast&                                                                \
4321sc_fxnum_fast::operator op ( const sc_fxval_fast& b )                         \
4322{                                                                             \
4323    SC_FXNUM_FAST_OBSERVER_READ_( *this )                                     \
4324    m_val op b.get_val();                                                     \
4325    cast();                                                                   \
4326    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )                                    \
4327    return *this;                                                             \
4328}                                                                             \
4329                                                                              \
4330DEFN_ASN_OP_T(op,int)                                                         \
4331DEFN_ASN_OP_T(op,unsigned int)                                                \
4332DEFN_ASN_OP_T(op,long)                                                        \
4333DEFN_ASN_OP_T(op,unsigned long)                                               \
4334DEFN_ASN_OP_T(op,float)                                                      \
4335DEFN_ASN_OP_T(op,double)                                                      \
4336DEFN_ASN_OP_T(op,const char*)                                                 \
4337DEFN_ASN_OP_T(op,const sc_fxval&)                                             \
4338DEFN_ASN_OP_T(op,const sc_fxnum&)                                             \
4339DEFN_ASN_OP_OTHER(op)
4340
4341DEFN_ASN_OP(*=)
4342DEFN_ASN_OP(/=)
4343DEFN_ASN_OP(+=)
4344DEFN_ASN_OP(-=)
4345
4346#undef DEFN_ASN_OP_T
4347#undef DEFN_ASN_OP_OTHER
4348#undef DEFN_ASN_OP
4349
4350
4351inline
4352sc_fxnum_fast&
4353sc_fxnum_fast::operator <<= ( int b )
4354{
4355    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4356    m_val *= scfx_pow2( b );
4357    cast();
4358    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4359    return *this;
4360}
4361
4362inline
4363sc_fxnum_fast&
4364sc_fxnum_fast::operator >>= ( int b )
4365{
4366    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4367    m_val *= scfx_pow2( -b );
4368    cast();
4369    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4370    return *this;
4371}
4372
4373
4374// auto-increment and auto-decrement
4375
4376inline
4377const sc_fxval_fast
4378sc_fxnum_fast::operator ++ ( int )
4379{
4380    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4381    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4382    double c = m_val;
4383    m_val = m_val + 1;
4384    cast();
4385    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4386    return sc_fxval_fast( c );
4387}
4388
4389inline
4390const sc_fxval_fast
4391sc_fxnum_fast::operator -- ( int )
4392{
4393    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4394    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4395    double c = m_val;
4396    m_val = m_val - 1;
4397    cast();
4398    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4399    return sc_fxval_fast( c );
4400}
4401
4402inline
4403sc_fxnum_fast&
4404sc_fxnum_fast::operator ++ ()
4405{
4406    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4407    m_val = m_val + 1;
4408    cast();
4409    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4410    return *this;
4411}
4412
4413inline
4414sc_fxnum_fast&
4415sc_fxnum_fast::operator -- ()
4416{
4417    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4418    m_val = m_val - 1;
4419    cast();
4420    SC_FXNUM_FAST_OBSERVER_WRITE_( *this )
4421    return *this;
4422}
4423
4424
4425// bit selection
4426
4427inline
4428const sc_fxnum_fast_bitref
4429sc_fxnum_fast::operator [] ( int i ) const
4430{
4431    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4432    return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
4433				 i - m_params.fwl() );
4434}
4435
4436inline
4437sc_fxnum_fast_bitref
4438sc_fxnum_fast::operator [] ( int i )
4439{
4440    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4441    return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
4442}
4443
4444inline
4445const sc_fxnum_fast_bitref
4446sc_fxnum_fast::bit( int i ) const
4447{
4448    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4449    return sc_fxnum_fast_bitref( const_cast<sc_fxnum_fast&>( *this ),
4450				 i - m_params.fwl() );
4451}
4452
4453inline
4454sc_fxnum_fast_bitref
4455sc_fxnum_fast::bit( int i )
4456{
4457    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4458    return sc_fxnum_fast_bitref( *this, i - m_params.fwl() );
4459}
4460
4461
4462// part selection
4463
4464inline
4465const sc_fxnum_fast_subref
4466sc_fxnum_fast::operator () ( int i, int j ) const
4467{
4468    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4469    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4470
4471    return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
4472				 i - m_params.fwl(), j - m_params.fwl() );
4473}
4474
4475inline
4476sc_fxnum_fast_subref
4477sc_fxnum_fast::operator () ( int i, int j )
4478{
4479    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4480    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4481
4482    return sc_fxnum_fast_subref( *this,
4483				 i - m_params.fwl(), j - m_params.fwl() );
4484}
4485
4486inline
4487const sc_fxnum_fast_subref
4488sc_fxnum_fast::range( int i, int j ) const
4489{
4490    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4491    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4492
4493    return sc_fxnum_fast_subref( const_cast<sc_fxnum_fast&>( *this ),
4494				 i - m_params.fwl(), j - m_params.fwl() );
4495}
4496
4497inline
4498sc_fxnum_fast_subref
4499sc_fxnum_fast::range( int i, int j )
4500{
4501    SC_ERROR_IF_( i < 0 || i >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4502    SC_ERROR_IF_( j < 0 || j >= m_params.wl(), sc_core::SC_ID_OUT_OF_RANGE_ );
4503
4504    return sc_fxnum_fast_subref( *this,
4505				 i - m_params.fwl(), j - m_params.fwl() );
4506}
4507
4508inline
4509const sc_fxnum_fast_subref
4510sc_fxnum_fast::operator () () const
4511{
4512    return this->operator () ( m_params.wl() - 1, 0 );
4513}
4514
4515inline
4516sc_fxnum_fast_subref
4517sc_fxnum_fast::operator () ()
4518{
4519    return this->operator () ( m_params.wl() - 1, 0 );
4520}
4521
4522inline
4523const sc_fxnum_fast_subref
4524sc_fxnum_fast::range() const
4525{
4526    return this->range( m_params.wl() - 1, 0 );
4527}
4528
4529inline
4530sc_fxnum_fast_subref
4531sc_fxnum_fast::range()
4532{
4533    return this->range( m_params.wl() - 1, 0 );
4534}
4535
4536
4537// implicit conversion
4538
4539inline
4540sc_fxnum_fast::operator double() const
4541{
4542    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4543    return m_val;
4544}
4545
4546
4547// explicit conversion to primitive types
4548
4549inline
4550short
4551sc_fxnum_fast::to_short() const
4552{
4553    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4554    return static_cast<short>( m_val );
4555}
4556
4557inline
4558unsigned short
4559sc_fxnum_fast::to_ushort() const
4560{
4561    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4562    return static_cast<unsigned short>( m_val );
4563}
4564
4565inline
4566int
4567sc_fxnum_fast::to_int() const
4568{
4569    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4570    return static_cast<int>( m_val );
4571}
4572
4573inline
4574int64
4575sc_fxnum_fast::to_int64() const
4576{
4577    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4578    return static_cast<int64>( m_val );
4579}
4580
4581inline
4582unsigned int
4583sc_fxnum_fast::to_uint() const
4584{
4585    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4586    return static_cast<unsigned int>( m_val );
4587}
4588
4589inline
4590uint64
4591sc_fxnum_fast::to_uint64() const
4592{
4593    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4594    return static_cast<uint64>( m_val );
4595}
4596
4597inline
4598long
4599sc_fxnum_fast::to_long() const
4600{
4601    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4602    return static_cast<long>( m_val );
4603}
4604
4605inline
4606unsigned long
4607sc_fxnum_fast::to_ulong() const
4608{
4609    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4610    return static_cast<unsigned long>( m_val );
4611}
4612
4613inline
4614float
4615sc_fxnum_fast::to_float() const
4616{
4617    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4618    return static_cast<float>( m_val );
4619}
4620
4621inline
4622double
4623sc_fxnum_fast::to_double() const
4624{
4625    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4626    return m_val;
4627}
4628
4629
4630// query value
4631
4632inline
4633bool
4634sc_fxnum_fast::is_neg() const
4635{
4636    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4637    scfx_ieee_double id( m_val );
4638    return ( id.negative() != 0 );
4639}
4640
4641inline
4642bool
4643sc_fxnum_fast::is_zero() const
4644{
4645    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4646    scfx_ieee_double id( m_val );
4647    return id.is_zero();
4648}
4649
4650// internal use only;
4651inline
4652bool
4653sc_fxnum_fast::is_normal() const
4654{
4655    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4656    scfx_ieee_double id( m_val );
4657    return ( id.is_normal() || id.is_subnormal() || id.is_zero() );
4658}
4659
4660
4661inline
4662bool
4663sc_fxnum_fast::quantization_flag() const
4664{
4665    return m_q_flag;
4666}
4667
4668inline
4669bool
4670sc_fxnum_fast::overflow_flag() const
4671{
4672    return m_o_flag;
4673}
4674
4675
4676inline
4677const sc_fxval_fast
4678sc_fxnum_fast::value() const
4679{
4680    SC_FXNUM_FAST_OBSERVER_READ_( *this )
4681    return sc_fxval_fast( m_val );
4682}
4683
4684
4685// query parameters
4686
4687inline
4688int
4689sc_fxnum_fast::wl() const
4690{
4691    return m_params.wl();
4692}
4693
4694inline
4695int
4696sc_fxnum_fast::iwl() const
4697{
4698    return m_params.iwl();
4699}
4700
4701inline
4702sc_q_mode
4703sc_fxnum_fast::q_mode() const
4704{
4705    return m_params.q_mode();
4706}
4707
4708inline
4709sc_o_mode
4710sc_fxnum_fast::o_mode() const
4711{
4712    return m_params.o_mode();
4713}
4714
4715inline
4716int
4717sc_fxnum_fast::n_bits() const
4718{
4719    return m_params.n_bits();
4720}
4721
4722
4723inline
4724const sc_fxtype_params&
4725sc_fxnum_fast::type_params() const
4726{
4727    return m_params.type_params();
4728}
4729
4730
4731inline
4732const sc_fxcast_switch&
4733sc_fxnum_fast::cast_switch() const
4734{
4735    return m_params.cast_switch();
4736}
4737
4738
4739// internal use only;
4740inline
4741void
4742sc_fxnum_fast::observer_read() const
4743{
4744    SC_FXNUM_OBSERVER_READ_( *this );
4745}
4746
4747
4748inline
4749::std::ostream&
4750operator << ( ::std::ostream& os, const sc_fxnum_fast& a )
4751{
4752    a.print( os );
4753    return os;
4754}
4755
4756inline
4757::std::istream&
4758operator >> ( ::std::istream& is, sc_fxnum_fast& a )
4759{
4760    a.scan( is );
4761    return is;
4762}
4763
4764
4765// ----------------------------------------------------------------------------
4766//  CLASS : sc_fxval
4767//
4768//  Fixed-point value type; arbitrary precision.
4769// ----------------------------------------------------------------------------
4770
4771// public constructors
4772
4773inline
4774sc_fxval::sc_fxval( const sc_fxnum& a,
4775		    sc_fxval_observer* observer_ )
4776: m_rep( new scfx_rep( *a.get_rep() ) ),
4777  m_observer( observer_ )
4778{
4779    SC_FXVAL_OBSERVER_DEFAULT_
4780    SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
4781    SC_FXVAL_OBSERVER_WRITE_( *this )
4782}
4783
4784inline
4785sc_fxval::sc_fxval( const sc_fxnum_fast& a,
4786		    sc_fxval_observer* observer_ )
4787: m_rep( new scfx_rep( a.to_double() ) ),
4788  m_observer( observer_ )
4789{
4790    SC_FXVAL_OBSERVER_DEFAULT_
4791    SC_FXVAL_OBSERVER_CONSTRUCT_( *this )
4792    SC_FXVAL_OBSERVER_WRITE_( *this )
4793}
4794
4795
4796// binary operators
4797
4798#define DEFN_BIN_OP_T(op,fnc,tp)                                              \
4799inline                                                                        \
4800const sc_fxval                                                                \
4801operator op ( const sc_fxval& a, tp b )                                       \
4802{                                                                             \
4803    SC_FXVAL_OBSERVER_READ_( a )                                              \
4804    sc_fxval tmp( b );                                                        \
4805    return sc_fxval( sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep ) );      \
4806}                                                                             \
4807                                                                              \
4808inline                                                                        \
4809const sc_fxval                                                                \
4810operator op ( tp a, const sc_fxval& b )                                       \
4811{                                                                             \
4812    SC_FXVAL_OBSERVER_READ_( b )                                              \
4813    sc_fxval tmp( a );                                                        \
4814    return sc_fxval( sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep ) );      \
4815}
4816
4817#define DEFN_BIN_OP(op,fnc)                                                   \
4818DEFN_BIN_OP_T(op,fnc,const sc_fxnum_fast&)
4819
4820DEFN_BIN_OP(*,mult)
4821DEFN_BIN_OP(+,add)
4822DEFN_BIN_OP(-,sub)
4823//DEFN_BIN_OP(/,div)
4824DEFN_BIN_OP_T(/,div,const sc_fxnum_fast&)
4825
4826#undef DEFN_BIN_OP_T
4827#undef DEFN_BIN_OP
4828
4829
4830// binary functions
4831
4832#define DEFN_BIN_FNC_T(fnc,tp)                                                \
4833inline                                                                        \
4834void                                                                          \
4835fnc ( sc_fxval& c, const sc_fxval& a, tp b )                                  \
4836{                                                                             \
4837    SC_FXVAL_OBSERVER_READ_( a )                                              \
4838    sc_fxval tmp( b );                                                        \
4839    delete c.m_rep;                                                           \
4840    c.m_rep = sc_dt::fnc ## _scfx_rep( *a.m_rep, *tmp.m_rep );               \
4841    SC_FXVAL_OBSERVER_WRITE_( c )                                             \
4842}                                                                             \
4843                                                                              \
4844inline                                                                        \
4845void                                                                          \
4846fnc ( sc_fxval& c, tp a, const sc_fxval& b )                                  \
4847{                                                                             \
4848    SC_FXVAL_OBSERVER_READ_( b )                                              \
4849    sc_fxval tmp( a );                                                        \
4850    delete c.m_rep;                                                           \
4851    c.m_rep = sc_dt::fnc ## _scfx_rep( *tmp.m_rep, *b.m_rep );               \
4852    SC_FXVAL_OBSERVER_WRITE_( c )                                             \
4853}
4854
4855#define DEFN_BIN_FNC(fnc)                                                     \
4856DEFN_BIN_FNC_T(fnc,const sc_fxnum_fast&)
4857
4858DEFN_BIN_FNC(mult)
4859DEFN_BIN_FNC(div)
4860DEFN_BIN_FNC(add)
4861DEFN_BIN_FNC(sub)
4862
4863#undef DEFN_BIN_FNC_T
4864#undef DEFN_BIN_FNC
4865
4866
4867// relational (including equality) operators
4868
4869#define DEFN_REL_OP_T(op,ret,tp)                                              \
4870inline                                                                        \
4871bool                                                                          \
4872operator op ( const sc_fxval& a, tp b )                                       \
4873{                                                                             \
4874    SC_FXVAL_OBSERVER_READ_( a )                                              \
4875    sc_fxval tmp( b );                                                        \
4876    int result = sc_dt::cmp_scfx_rep( *a.m_rep, *tmp.m_rep );                \
4877    return ( ret );                                                           \
4878}                                                                             \
4879                                                                              \
4880inline                                                                        \
4881bool                                                                          \
4882operator op ( tp a, const sc_fxval& b )                                       \
4883{                                                                             \
4884    SC_FXVAL_OBSERVER_READ_( b )                                              \
4885    sc_fxval tmp( a );                                                        \
4886    int result = sc_dt::cmp_scfx_rep( *tmp.m_rep, *b.m_rep );                \
4887    return ( ret );                                                           \
4888}
4889
4890
4891#define DEFN_REL_OP(op,ret)                                                   \
4892DEFN_REL_OP_T(op,ret,const sc_fxnum_fast&)
4893
4894DEFN_REL_OP(<,result < 0)
4895DEFN_REL_OP(<=,result <= 0)
4896DEFN_REL_OP(>,result > 0 && result != 2)
4897DEFN_REL_OP(>=,result >= 0 && result != 2)
4898DEFN_REL_OP(==,result == 0)
4899DEFN_REL_OP(!=,result != 0)
4900
4901#undef DEFN_REL_OP_T
4902#undef DEFN_REL_OP
4903
4904
4905// assignment operators
4906
4907inline
4908sc_fxval&
4909sc_fxval::operator = ( const sc_fxnum& a )
4910{
4911    *m_rep = *a.get_rep();
4912    SC_FXVAL_OBSERVER_WRITE_( *this )
4913    return *this;
4914}
4915
4916#define DEFN_ASN_OP_T(tp)                                                     \
4917inline                                                                        \
4918sc_fxval&                                                                     \
4919sc_fxval::operator = ( tp b )                                                 \
4920{                                                                             \
4921    sc_fxval tmp( b );                                                        \
4922    *m_rep = *tmp.m_rep;                                                      \
4923    SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
4924    return *this;                                                             \
4925}
4926
4927DEFN_ASN_OP_T(const sc_fxnum_fast&)
4928
4929#undef DEFN_ASN_OP_T
4930
4931
4932#define DEFN_ASN_OP_T(op,fnc,tp)                                              \
4933inline                                                                        \
4934sc_fxval&                                                                     \
4935sc_fxval::operator op ( tp b )                                                \
4936{                                                                             \
4937    SC_FXVAL_OBSERVER_READ_( *this )                                          \
4938    sc_fxval tmp( b );                                                        \
4939    scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *tmp.m_rep );       \
4940    delete m_rep;                                                             \
4941    m_rep = new_rep;                                                          \
4942    SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
4943    return *this;                                                             \
4944}
4945
4946#define DEFN_ASN_OP(op,fnc)                                                   \
4947inline                                                                        \
4948sc_fxval&                                                                     \
4949sc_fxval::operator op ( const sc_fxnum& b )                                   \
4950{                                                                             \
4951    SC_FXVAL_OBSERVER_READ_( *this )                                          \
4952    scfx_rep* new_rep = sc_dt::fnc ## _scfx_rep( *m_rep, *b.get_rep() );     \
4953    delete m_rep;                                                             \
4954    m_rep = new_rep;                                                          \
4955    SC_FXVAL_OBSERVER_WRITE_( *this )                                         \
4956    return *this;                                                             \
4957}                                                                             \
4958                                                                              \
4959DEFN_ASN_OP_T(op,fnc,const sc_fxnum_fast&)
4960
4961DEFN_ASN_OP(*=,mult)
4962DEFN_ASN_OP(/=,div)
4963DEFN_ASN_OP(+=,add)
4964DEFN_ASN_OP(-=,sub)
4965
4966#undef DEFN_ASN_OP_T
4967#undef DEFN_ASN_OP
4968
4969
4970// ----------------------------------------------------------------------------
4971//  CLASS : sc_fxval_fast
4972//
4973//  Fixed-point value types; limited precision.
4974// ----------------------------------------------------------------------------
4975
4976// public constructors
4977
4978inline
4979sc_fxval_fast::sc_fxval_fast( const sc_fxnum& a,
4980			      sc_fxval_fast_observer* observer_ )
4981: m_val( a.to_double() ),
4982  m_observer( observer_ )
4983{
4984    SC_FXVAL_FAST_OBSERVER_DEFAULT_
4985    SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
4986    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
4987}
4988
4989inline
4990sc_fxval_fast::sc_fxval_fast( const sc_fxnum_fast& a,
4991			      sc_fxval_fast_observer* observer_ )
4992: m_val( a.get_val() ),
4993  m_observer( observer_ )
4994{
4995    SC_FXVAL_FAST_OBSERVER_DEFAULT_
4996    SC_FXVAL_FAST_OBSERVER_CONSTRUCT_( *this )
4997    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
4998}
4999
5000
5001// binary functions
5002
5003#define DEFN_BIN_FNC_T(fnc,op,tp)                                             \
5004inline                                                                        \
5005void                                                                          \
5006fnc ( sc_fxval_fast& c, const sc_fxval_fast& a, tp b )                        \
5007{                                                                             \
5008    SC_FXVAL_FAST_OBSERVER_READ_( a )                                         \
5009    sc_fxval_fast tmp( b );                                                   \
5010    c.m_val = a.m_val op tmp.m_val;                                           \
5011    SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
5012}                                                                             \
5013                                                                              \
5014inline                                                                        \
5015void                                                                          \
5016fnc ( sc_fxval_fast& c, tp a, const sc_fxval_fast& b )                        \
5017{                                                                             \
5018    SC_FXVAL_FAST_OBSERVER_READ_( b )                                         \
5019    sc_fxval_fast tmp( a );                                                   \
5020    c.m_val = tmp.m_val op b.m_val;                                           \
5021    SC_FXVAL_FAST_OBSERVER_WRITE_( c )                                        \
5022}
5023
5024#define DEFN_BIN_FNC(fnc,op)                                                  \
5025DEFN_BIN_FNC_T(fnc,op,const sc_fxval&)                                        \
5026DEFN_BIN_FNC_T(fnc,op,const sc_fxnum&)
5027
5028DEFN_BIN_FNC(mult,*)
5029DEFN_BIN_FNC(div,/)
5030DEFN_BIN_FNC(add,+)
5031DEFN_BIN_FNC(sub,-)
5032
5033#undef DEFN_BIN_FNC_T
5034#undef DEFN_BIN_FNC
5035
5036
5037// assignment operators
5038
5039inline
5040sc_fxval_fast&
5041sc_fxval_fast::operator = ( const sc_fxnum_fast& a )
5042{
5043    m_val = a.get_val();
5044    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )
5045    return *this;
5046}
5047
5048#define DEFN_ASN_OP_T(tp)                                                     \
5049inline                                                                        \
5050sc_fxval_fast&                                                                \
5051sc_fxval_fast::operator = ( tp a )                                            \
5052{                                                                             \
5053    sc_fxval_fast tmp( a );                                                   \
5054    m_val = tmp.m_val;                                                        \
5055    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
5056    return *this;                                                             \
5057}
5058
5059DEFN_ASN_OP_T(const sc_fxnum&)
5060
5061#undef DEFN_ASN_OP_T
5062
5063
5064#define DEFN_ASN_OP_T(op,tp)                                                  \
5065inline                                                                        \
5066sc_fxval_fast&                                                                \
5067sc_fxval_fast::operator op ( tp b )                                           \
5068{                                                                             \
5069    SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
5070    sc_fxval_fast tmp( b );                                                   \
5071    m_val op tmp.m_val;                                                       \
5072    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
5073    return *this;                                                             \
5074}
5075
5076#define DEFN_ASN_OP(op)                                                       \
5077inline                                                                        \
5078sc_fxval_fast&                                                                \
5079sc_fxval_fast::operator op ( const sc_fxnum_fast& b )                         \
5080{                                                                             \
5081    SC_FXVAL_FAST_OBSERVER_READ_( *this )                                     \
5082    m_val op b.get_val();                                                     \
5083    SC_FXVAL_FAST_OBSERVER_WRITE_( *this )                                    \
5084    return *this;                                                             \
5085}                                                                             \
5086                                                                              \
5087DEFN_ASN_OP_T(op,const sc_fxnum&)
5088
5089DEFN_ASN_OP(*=)
5090DEFN_ASN_OP(/=)
5091DEFN_ASN_OP(+=)
5092DEFN_ASN_OP(-=)
5093
5094#undef DEFN_ASN_OP_T
5095#undef DEFN_ASN_OP
5096
5097} // namespace sc_dt
5098
5099
5100#endif
5101
5102// Taf!
5103