2 * Copyright (c) 1999-2004 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: verireal.cc,v 1.19 2007/04/07 04:46:18 steve Exp $"
25 # include "verireal.h"
38 verireal::verireal(const char*txt
)
40 char*tmp
= new char[strlen(txt
)+1];
42 for (unsigned idx
= 0 ; txt
[idx
] ; idx
+= 1) {
50 value_
= strtod(tmp
, 0);
54 verireal::verireal(long val
)
59 verireal::verireal(double val
)
68 long verireal::as_long(int shift
) const
70 double out
= value_
* pow(10.0,shift
);
75 if (out
>= (outf
+ 0.5))
79 if (out
<= (outf
- 0.5))
85 int64_t verireal::as_long64(int shift
) const
87 double out
= value_
* pow(10.0,shift
);
92 if (out
>= (outf
+ 0.5))
96 if (out
<= (outf
- 0.5))
99 return (int64_t) outf
;
102 double verireal::as_double() const
107 verireal
operator+ (const verireal
&l
, const verireal
&r
)
110 res
.value_
= l
.value_
+ r
.value_
;
114 verireal
operator- (const verireal
&l
, const verireal
&r
)
117 res
.value_
= l
.value_
- r
.value_
;
121 verireal
operator* (const verireal
&l
, const verireal
&r
)
124 res
.value_
= l
.value_
* r
.value_
;
128 verireal
operator/ (const verireal
&l
, const verireal
&r
)
131 res
.value_
= l
.value_
/ r
.value_
;
135 verireal
operator/ (const verireal
&l
, const verinum
&r
)
138 res
.value_
= l
.value_
/ (double)r
.as_long();
142 verireal
operator% (const verireal
&l
, const verireal
&r
)
149 verireal
operator% (const verireal
&l
, const verinum
&r
)
156 verireal
pow (const verireal
&l
, const verireal
&r
)
159 res
.value_
= pow(l
.value_
, r
.value_
);
163 verireal
operator- (const verireal
&l
)
166 res
.value_
= - l
.value_
;
170 ostream
& operator<< (ostream
&out
, const verireal
&v
)
177 * $Log: verireal.cc,v $
178 * Revision 1.19 2007/04/07 04:46:18 steve
179 * Handle evaluate of addition of real valued constants.
181 * Revision 1.18 2006/10/03 05:06:00 steve
182 * Support real valued specify delays, properly scaled.
184 * Revision 1.17 2006/08/08 05:11:37 steve
185 * Handle 64bit delay constants.
187 * Revision 1.16 2006/07/31 03:50:18 steve
188 * Add support for power in constant expressions.
190 * Revision 1.15 2004/06/04 23:33:51 steve
191 * Add unary minus as operator supported by verireal.
193 * Revision 1.14 2003/03/07 06:10:13 steve
194 * Use strtod to convert text to doubles.
196 * Revision 1.13 2003/03/05 03:45:01 steve
197 * Restore verireal constructor to match vvp processing of reals.
199 * Revision 1.11 2003/02/07 06:13:44 steve
200 * Store real values as native double.
202 * Revision 1.10 2003/02/07 02:48:43 steve
203 * NetEBDiv handles real value constant expressions.
205 * Revision 1.9 2003/01/26 21:15:59 steve
206 * Rework expression parsing and elaboration to
207 * accommodate real/realtime values and expressions.
209 * Revision 1.8 2002/08/12 01:35:01 steve
210 * conditional ident string using autoconfig.
212 * Revision 1.7 2002/06/15 02:35:49 steve
215 * Revision 1.6 2001/11/06 06:11:55 steve
216 * Support more real arithmetic in delay constants.
218 * Revision 1.5 2001/07/25 03:10:50 steve
219 * Create a config.h.in file to hold all the config
220 * junk, and support gcc 3.0. (Stephan Boettcher)
222 * Revision 1.4 2001/07/07 20:20:10 steve
223 * Pass parameters to system functions.
225 * Revision 1.3 2000/12/10 22:01:36 steve
226 * Support decimal constants in behavioral delays.
228 * Revision 1.2 2000/02/23 02:56:56 steve
229 * Macintosh compilers do not support ident.
231 * Revision 1.1 1999/06/15 02:50:02 steve
232 * Add lexical support for real numbers.