Permalink
Browse files

Restore verireal constructor to match vvp processing of reals.

  • Loading branch information...
1 parent 44748ea commit e6e0396ecbf855acaf2a9e9f35a9350e154baab2 steve committed Mar 5, 2003
Showing with 50 additions and 16 deletions.
  1. +50 −16 verireal.cc
View
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999-2003 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 1999 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: verireal.cc,v 1.12 2003/03/05 02:36:05 steve Exp $"
+#ident "$Id: verireal.cc,v 1.13 2003/03/05 03:45:01 steve Exp $"
#endif
# include "config.h"
@@ -28,7 +28,6 @@
# include <iostream>
# include <math.h>
# include <assert.h>
-# include <stdio.h>
verireal::verireal()
{
@@ -37,23 +36,58 @@ verireal::verireal()
verireal::verireal(const char*txt)
{
- char*buf = new char[strlen(txt)+1];
- char*cp = buf;
+ unsigned long long mant = 0;
+ bool sign = false;
+ signed int exp10 = 0;
- /* filter out Verilog-isms */
- for (unsigned i = 0; txt[i]; i += 1) {
- if (txt[i] == '_') { continue; }
- *cp = txt[i]; cp++;
+ const char*ptr = txt;
+ for ( ; *ptr ; ptr += 1) {
+ if (*ptr == '.') break;
+ if (*ptr == 'e') break;
+ if (*ptr == 'E') break;
+ if (*ptr == '_') continue;
+
+ assert(isdigit(*ptr));
+
+ mant *= 10;
+ mant += *ptr - '0';
}
- *cp = '\0';
+ if (*ptr == '.') {
+ ptr += 1;
+ for ( ; *ptr ; ptr += 1) {
+ if (*ptr == 'e') break;
+ if (*ptr == 'E') break;
+ if (*ptr == '_') continue;
+
+ assert(isdigit(*ptr));
- if (sscanf(buf, "%lf", &value_) != 1) {
- fprintf(stderr, "PANIC: Unable to sscanf(%s)\n", txt);
- assert(0);
+ mant *= 10;
+ mant += *ptr - '0';
+ exp10 -= 1;
+ }
}
- delete[]buf;
+ if ((*ptr == 'e') || (*ptr == 'E')) {
+ ptr += 1;
+ long tmp = 0;
+ bool sflag = false;
+ if (*ptr == '+') {ptr += 1; sflag = false;}
+ if (*ptr == '-') {ptr += 1; sflag = true;}
+
+ for ( ; *ptr ; ptr += 1) {
+ if (*ptr == '_') continue;
+ assert(isdigit(*ptr));
+ tmp *= 10;
+ tmp += *ptr - '0';
+ }
+
+ exp10 += sflag? -tmp : +tmp;
+ }
+
+ assert(*ptr == 0);
+
+ value_ = pow(10.0,exp10) * mant * (sign? -1.0 : 1.0);
}
verireal::verireal(long val)
@@ -130,8 +164,8 @@ ostream& operator<< (ostream&out, const verireal&v)
/*
* $Log: verireal.cc,v $
- * Revision 1.12 2003/03/05 02:36:05 steve
- * Use sscanf to make doubles from strings.
+ * Revision 1.13 2003/03/05 03:45:01 steve
+ * Restore verireal constructor to match vvp processing of reals.
*
* Revision 1.11 2003/02/07 06:13:44 steve
* Store real values as native double.

0 comments on commit e6e0396

Please sign in to comment.