Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 171 lines (151 sloc) 4.05 kB
430d7b2 Add lexical support for real numbers.
steve authored
1 /*
e6e0396 Restore verireal constructor to match vvp processing of reals.
steve authored
2 * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
430d7b2 Add lexical support for real numbers.
steve authored
3 *
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)
8 * any later version.
9 *
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.
14 *
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
18 */
52bf4e6 conditional ident string using autoconfig.
steve authored
19 #ifdef HAVE_CVS_IDENT
12d432d Use strtod to convert text to doubles.
steve authored
20 #ident "$Id: verireal.cc,v 1.14 2003/03/07 06:10:13 steve Exp $"
430d7b2 Add lexical support for real numbers.
steve authored
21 #endif
22
b825f8d Create a config.h.in file to hold all the config
steve authored
23 # include "config.h"
24
430d7b2 Add lexical support for real numbers.
steve authored
25 # include "verireal.h"
f8d1e15 NetEBDiv handles real value constant expressions.
steve authored
26 # include "verinum.h"
12d432d Use strtod to convert text to doubles.
steve authored
27 # include <stdlib.h>
430d7b2 Add lexical support for real numbers.
steve authored
28 # include <ctype.h>
084a464 Support decimal constants in behavioral delays.
steve authored
29 # include <iostream>
46253ed Rework expression parsing and elaboration to
steve authored
30 # include <math.h>
430d7b2 Add lexical support for real numbers.
steve authored
31 # include <assert.h>
32
33 verireal::verireal()
34 {
79b2beb Store real values as native double.
steve authored
35 value_ = 0.0;
430d7b2 Add lexical support for real numbers.
steve authored
36 }
37
38 verireal::verireal(const char*txt)
39 {
12d432d Use strtod to convert text to doubles.
steve authored
40 char*tmp = new char[strlen(txt)+1];
41 char*cp = tmp;
42 for (unsigned idx = 0 ; txt[idx] ; idx += 1) {
43 if (txt[idx] == '_')
44 continue;
430d7b2 Add lexical support for real numbers.
steve authored
45
12d432d Use strtod to convert text to doubles.
steve authored
46 *cp++ = txt[idx];
e6e0396 Restore verireal constructor to match vvp processing of reals.
steve authored
47 }
12d432d Use strtod to convert text to doubles.
steve authored
48 cp[0] = 0;
e6e0396 Restore verireal constructor to match vvp processing of reals.
steve authored
49
12d432d Use strtod to convert text to doubles.
steve authored
50 value_ = strtod(tmp, 0);
51 delete[]tmp;
430d7b2 Add lexical support for real numbers.
steve authored
52 }
53
9572ddd Support more real arithmetic in delay constants.
steve authored
54 verireal::verireal(long val)
55 {
79b2beb Store real values as native double.
steve authored
56 value_ = (double)val;
9572ddd Support more real arithmetic in delay constants.
steve authored
57 }
430d7b2 Add lexical support for real numbers.
steve authored
58
59 verireal::~verireal()
60 {
61 }
62
084a464 Support decimal constants in behavioral delays.
steve authored
63 long verireal::as_long(int shift) const
64 {
79b2beb Store real values as native double.
steve authored
65 double out = value_ * pow(10.0,shift);
66 double outf;
67
68 if (out >= 0.0) {
69 outf = floor(out);
70 if (out >= (outf + 0.5))
71 outf += 1.0;
72 } else {
73 outf = ceil(out);
74 if (out <= (outf - 0.5))
75 outf -= 1.0;
084a464 Support decimal constants in behavioral delays.
steve authored
76 }
79b2beb Store real values as native double.
steve authored
77 return (long) outf;
084a464 Support decimal constants in behavioral delays.
steve authored
78 }
79
46253ed Rework expression parsing and elaboration to
steve authored
80 double verireal::as_double() const
81 {
79b2beb Store real values as native double.
steve authored
82 return value_;
46253ed Rework expression parsing and elaboration to
steve authored
83 }
84
9572ddd Support more real arithmetic in delay constants.
steve authored
85 verireal operator* (const verireal&l, const verireal&r)
86 {
87 verireal res;
79b2beb Store real values as native double.
steve authored
88 res.value_ = l.value_ * r.value_;
9572ddd Support more real arithmetic in delay constants.
steve authored
89 return res;
90 }
91
f8d1e15 NetEBDiv handles real value constant expressions.
steve authored
92 verireal operator/ (const verireal&l, const verireal&r)
93 {
94 verireal res;
79b2beb Store real values as native double.
steve authored
95 res.value_ = l.value_ / r.value_;
f8d1e15 NetEBDiv handles real value constant expressions.
steve authored
96 return res;
97 }
98
99 verireal operator/ (const verireal&l, const verinum&r)
100 {
101 verireal res;
79b2beb Store real values as native double.
steve authored
102 res.value_ = l.value_ / (double)r.as_long();
f8d1e15 NetEBDiv handles real value constant expressions.
steve authored
103 return res;
104 }
105
106 verireal operator% (const verireal&l, const verireal&r)
107 {
108 verireal res;
109 assert(0);
110 return res;
111 }
112
113 verireal operator% (const verireal&l, const verinum&r)
114 {
115 verireal res;
116 assert(0);
117 return res;
118 }
119
084a464 Support decimal constants in behavioral delays.
steve authored
120 ostream& operator<< (ostream&out, const verireal&v)
121 {
79b2beb Store real values as native double.
steve authored
122 out << v.value_;
8cc89a3 Pass parameters to system functions.
steve authored
123 return out;
084a464 Support decimal constants in behavioral delays.
steve authored
124 }
125
430d7b2 Add lexical support for real numbers.
steve authored
126 /*
127 * $Log: verireal.cc,v $
12d432d Use strtod to convert text to doubles.
steve authored
128 * Revision 1.14 2003/03/07 06:10:13 steve
129 * Use strtod to convert text to doubles.
130 *
e6e0396 Restore verireal constructor to match vvp processing of reals.
steve authored
131 * Revision 1.13 2003/03/05 03:45:01 steve
132 * Restore verireal constructor to match vvp processing of reals.
1e73cf8 Use sscanf to make doubles from strings.
steve authored
133 *
79b2beb Store real values as native double.
steve authored
134 * Revision 1.11 2003/02/07 06:13:44 steve
135 * Store real values as native double.
136 *
f8d1e15 NetEBDiv handles real value constant expressions.
steve authored
137 * Revision 1.10 2003/02/07 02:48:43 steve
138 * NetEBDiv handles real value constant expressions.
139 *
46253ed Rework expression parsing and elaboration to
steve authored
140 * Revision 1.9 2003/01/26 21:15:59 steve
141 * Rework expression parsing and elaboration to
142 * accommodate real/realtime values and expressions.
143 *
52bf4e6 conditional ident string using autoconfig.
steve authored
144 * Revision 1.8 2002/08/12 01:35:01 steve
145 * conditional ident string using autoconfig.
146 *
067d097 Rounding error.
steve authored
147 * Revision 1.7 2002/06/15 02:35:49 steve
148 * Rounding error.
149 *
9572ddd Support more real arithmetic in delay constants.
steve authored
150 * Revision 1.6 2001/11/06 06:11:55 steve
151 * Support more real arithmetic in delay constants.
152 *
b825f8d Create a config.h.in file to hold all the config
steve authored
153 * Revision 1.5 2001/07/25 03:10:50 steve
154 * Create a config.h.in file to hold all the config
155 * junk, and support gcc 3.0. (Stephan Boettcher)
156 *
8cc89a3 Pass parameters to system functions.
steve authored
157 * Revision 1.4 2001/07/07 20:20:10 steve
158 * Pass parameters to system functions.
159 *
084a464 Support decimal constants in behavioral delays.
steve authored
160 * Revision 1.3 2000/12/10 22:01:36 steve
161 * Support decimal constants in behavioral delays.
162 *
b734ecf Macintosh compilers do not support ident.
steve authored
163 * Revision 1.2 2000/02/23 02:56:56 steve
164 * Macintosh compilers do not support ident.
165 *
430d7b2 Add lexical support for real numbers.
steve authored
166 * Revision 1.1 1999/06/15 02:50:02 steve
167 * Add lexical support for real numbers.
168 *
169 */
170
Something went wrong with that request. Please try again.