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"
39 verireal::verireal(const char*txt
)
41 char*tmp
= new char[strlen(txt
)+1];
43 for (unsigned idx
= 0 ; txt
[idx
] ; idx
+= 1) {
51 value_
= strtod(tmp
, 0);
55 verireal::verireal(long val
)
60 verireal::verireal(double val
)
69 long verireal::as_long(int shift
) const
71 double out
= value_
* pow(10.0,shift
);
76 if (out
>= (outf
+ 0.5))
80 if (out
<= (outf
- 0.5))
86 int64_t verireal::as_long64(int shift
) const
88 double out
= value_
* pow(10.0,shift
);
93 if (out
>= (outf
+ 0.5))
97 if (out
<= (outf
- 0.5))
100 return (int64_t) outf
;
103 double verireal::as_double() const
108 verireal
operator+ (const verireal
&l
, const verireal
&r
)
111 res
.value_
= l
.value_
+ r
.value_
;
115 verireal
operator- (const verireal
&l
, const verireal
&r
)
118 res
.value_
= l
.value_
- r
.value_
;
122 verireal
operator* (const verireal
&l
, const verireal
&r
)
125 res
.value_
= l
.value_
* r
.value_
;
129 verireal
operator/ (const verireal
&l
, const verireal
&r
)
132 res
.value_
= l
.value_
/ r
.value_
;
136 verireal
operator/ (const verireal
&l
, const verinum
&r
)
139 res
.value_
= l
.value_
/ (double)r
.as_long();
143 verireal
operator% (const verireal
&l
, const verireal
&r
)
150 verireal
operator% (const verireal
&l
, const verinum
&r
)
157 verireal
pow (const verireal
&l
, const verireal
&r
)
160 res
.value_
= pow(l
.value_
, r
.value_
);
164 verireal
operator- (const verireal
&l
)
167 res
.value_
= - l
.value_
;
171 ostream
& operator<< (ostream
&out
, const verireal
&v
)
178 * $Log: verireal.cc,v $
179 * Revision 1.19 2007/04/07 04:46:18 steve
180 * Handle evaluate of addition of real valued constants.
182 * Revision 1.18 2006/10/03 05:06:00 steve
183 * Support real valued specify delays, properly scaled.
185 * Revision 1.17 2006/08/08 05:11:37 steve
186 * Handle 64bit delay constants.
188 * Revision 1.16 2006/07/31 03:50:18 steve
189 * Add support for power in constant expressions.
191 * Revision 1.15 2004/06/04 23:33:51 steve
192 * Add unary minus as operator supported by verireal.
194 * Revision 1.14 2003/03/07 06:10:13 steve
195 * Use strtod to convert text to doubles.
197 * Revision 1.13 2003/03/05 03:45:01 steve
198 * Restore verireal constructor to match vvp processing of reals.
200 * Revision 1.11 2003/02/07 06:13:44 steve
201 * Store real values as native double.
203 * Revision 1.10 2003/02/07 02:48:43 steve
204 * NetEBDiv handles real value constant expressions.
206 * Revision 1.9 2003/01/26 21:15:59 steve
207 * Rework expression parsing and elaboration to
208 * accommodate real/realtime values and expressions.
210 * Revision 1.8 2002/08/12 01:35:01 steve
211 * conditional ident string using autoconfig.
213 * Revision 1.7 2002/06/15 02:35:49 steve
216 * Revision 1.6 2001/11/06 06:11:55 steve
217 * Support more real arithmetic in delay constants.
219 * Revision 1.5 2001/07/25 03:10:50 steve
220 * Create a config.h.in file to hold all the config
221 * junk, and support gcc 3.0. (Stephan Boettcher)
223 * Revision 1.4 2001/07/07 20:20:10 steve
224 * Pass parameters to system functions.
226 * Revision 1.3 2000/12/10 22:01:36 steve
227 * Support decimal constants in behavioral delays.
229 * Revision 1.2 2000/02/23 02:56:56 steve
230 * Macintosh compilers do not support ident.
232 * Revision 1.1 1999/06/15 02:50:02 steve
233 * Add lexical support for real numbers.