From e6e0396ecbf855acaf2a9e9f35a9350e154baab2 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 5 Mar 2003 03:45:01 +0000 Subject: [PATCH] Restore verireal constructor to match vvp processing of reals. --- verireal.cc | 66 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/verireal.cc b/verireal.cc index 1f1f4a897..0bfc26450 100644 --- a/verireal.cc +++ b/verireal.cc @@ -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 # include # include -# include 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; - if (sscanf(buf, "%lf", &value_) != 1) { - fprintf(stderr, "PANIC: Unable to sscanf(%s)\n", txt); - assert(0); + assert(isdigit(*ptr)); + + 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.