Support for wide modulus operations.
[iverilog.git] / verireal.h
blob51fccb08680ff87eb22cdd0ac6d5d51fc6f0d0cf
1 #ifndef __verireal_H
2 #define __verireal_H
3 /*
4 * Copyright (c) 1999-2004 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #ifdef HAVE_CVS_IDENT
22 #ident "$Id: verireal.h,v 1.16 2007/04/07 04:46:19 steve Exp $"
23 #endif
25 # include "config.h"
26 #ifdef HAVE_IOSFWD
27 # include <iosfwd>
28 #else
29 class ostream;
30 #endif
32 using namespace std;
34 class verinum;
37 * This class holds a floating point decimal number. The number is
38 * stored as an integer mantissa and a power of 10. The mantissa is an
39 * integer so that decimal numbers in the source (which are decimal)
40 * can be stored exactly.
43 class verireal {
45 friend ostream& operator<< (ostream&, const verireal&);
46 friend verireal operator+ (const verireal&, const verireal&);
47 friend verireal operator- (const verireal&, const verireal&);
48 friend verireal operator* (const verireal&, const verireal&);
49 friend verireal operator/ (const verireal&, const verireal&);
50 friend verireal operator/ (const verireal&, const verinum&);
51 friend verireal operator% (const verireal&, const verireal&);
52 friend verireal operator% (const verireal&, const verinum&);
53 friend verireal pow(const verireal&, const verireal&);
55 // Unary minus.
56 friend verireal operator- (const verireal&);
58 public:
59 explicit verireal();
60 explicit verireal(const char*text);
61 explicit verireal(long val);
62 explicit verireal(double val);
63 ~verireal();
65 /* Return the value of the floating point number as an
66 integer, rounded as needed. The shift is the power of 10 to
67 multiply the value before calculating the result. So for
68 example if the value is 2.5 and shift == 1, the result
69 is 25. */
70 long as_long(int shift =0) const;
71 int64_t as_long64(int shift =0) const;
73 double as_double() const;
75 private:
76 double value_;
79 extern ostream& operator<< (ostream&, const verireal&);
80 extern verireal operator* (const verireal&, const verireal&);
81 extern verireal operator/ (const verireal&, const verireal&);
82 extern verireal operator/ (const verireal&, const verinum&);
83 extern verireal operator% (const verireal&, const verireal&);
84 extern verireal operator% (const verireal&, const verinum&);
85 extern verireal pow(const verireal&, const verireal&);
86 extern verireal operator- (const verireal&);
89 * $Log: verireal.h,v $
90 * Revision 1.16 2007/04/07 04:46:19 steve
91 * Handle evaluate of addition of real valued constants.
93 * Revision 1.15 2007/02/02 04:33:01 steve
94 * Use inttypes.h instead of stdint.h for portability.
96 * Revision 1.14 2006/10/03 05:06:00 steve
97 * Support real valued specify delays, properly scaled.
99 * Revision 1.13 2006/08/08 05:11:37 steve
100 * Handle 64bit delay constants.
102 * Revision 1.12 2006/07/31 03:50:18 steve
103 * Add support for power in constant expressions.
105 * Revision 1.11 2005/06/14 19:13:43 steve
106 * gcc3/4 compile errors.
108 * Revision 1.10 2004/06/04 23:33:51 steve
109 * Add unary minus as operator supported by verireal.
111 * Revision 1.9 2003/02/07 06:13:44 steve
112 * Store real values as native double.
114 * Revision 1.8 2003/02/07 02:48:43 steve
115 * NetEBDiv handles real value constant expressions.
117 * Revision 1.7 2003/01/26 21:15:59 steve
118 * Rework expression parsing and elaboration to
119 * accommodate real/realtime values and expressions.
121 * Revision 1.6 2002/08/12 01:35:01 steve
122 * conditional ident string using autoconfig.
124 * Revision 1.5 2001/11/06 06:11:55 steve
125 * Support more real arithmetic in delay constants.
127 * Revision 1.4 2001/01/16 02:44:18 steve
128 * Use the iosfwd header if available.
130 * Revision 1.3 2000/12/10 22:01:36 steve
131 * Support decimal constants in behavioral delays.
133 * Revision 1.2 2000/02/23 02:56:56 steve
134 * Macintosh compilers do not support ident.
136 * Revision 1.1 1999/06/15 02:50:02 steve
137 * Add lexical support for real numbers.
140 #endif