Skip to content
This repository
Browse code

Use strtod to convert text to doubles.

  • Loading branch information...
commit 12d432d94ddb93b89f750eade9bde742656345ba 1 parent 258013f
steve authored

Showing 1 changed file with 14 additions and 50 deletions. Show diff stats Hide diff stats

  1. +14 50 verireal.cc
64 verireal.cc
@@ -17,13 +17,14 @@
17 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 18 */
19 19 #ifdef HAVE_CVS_IDENT
20   -#ident "$Id: verireal.cc,v 1.13 2003/03/05 03:45:01 steve Exp $"
  20 +#ident "$Id: verireal.cc,v 1.14 2003/03/07 06:10:13 steve Exp $"
21 21 #endif
22 22
23 23 # include "config.h"
24 24
25 25 # include "verireal.h"
26 26 # include "verinum.h"
  27 +# include <stdlib.h>
27 28 # include <ctype.h>
28 29 # include <iostream>
29 30 # include <math.h>
@@ -36,58 +37,18 @@ verireal::verireal()
36 37
37 38 verireal::verireal(const char*txt)
38 39 {
39   - unsigned long long mant = 0;
40   - bool sign = false;
41   - signed int exp10 = 0;
  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;
42 45
43   - const char*ptr = txt;
44   - for ( ; *ptr ; ptr += 1) {
45   - if (*ptr == '.') break;
46   - if (*ptr == 'e') break;
47   - if (*ptr == 'E') break;
48   - if (*ptr == '_') continue;
49   -
50   - assert(isdigit(*ptr));
51   -
52   - mant *= 10;
53   - mant += *ptr - '0';
54   - }
55   -
56   - if (*ptr == '.') {
57   - ptr += 1;
58   - for ( ; *ptr ; ptr += 1) {
59   - if (*ptr == 'e') break;
60   - if (*ptr == 'E') break;
61   - if (*ptr == '_') continue;
62   -
63   - assert(isdigit(*ptr));
64   -
65   - mant *= 10;
66   - mant += *ptr - '0';
67   - exp10 -= 1;
68   - }
69   - }
70   -
71   - if ((*ptr == 'e') || (*ptr == 'E')) {
72   - ptr += 1;
73   - long tmp = 0;
74   - bool sflag = false;
75   - if (*ptr == '+') {ptr += 1; sflag = false;}
76   - if (*ptr == '-') {ptr += 1; sflag = true;}
77   -
78   - for ( ; *ptr ; ptr += 1) {
79   - if (*ptr == '_') continue;
80   - assert(isdigit(*ptr));
81   - tmp *= 10;
82   - tmp += *ptr - '0';
83   - }
84   -
85   - exp10 += sflag? -tmp : +tmp;
  46 + *cp++ = txt[idx];
86 47 }
  48 + cp[0] = 0;
87 49
88   - assert(*ptr == 0);
89   -
90   - value_ = pow(10.0,exp10) * mant * (sign? -1.0 : 1.0);
  50 + value_ = strtod(tmp, 0);
  51 + delete[]tmp;
91 52 }
92 53
93 54 verireal::verireal(long val)
@@ -164,6 +125,9 @@ ostream& operator<< (ostream&out, const verireal&v)
164 125
165 126 /*
166 127 * $Log: verireal.cc,v $
  128 + * Revision 1.14 2003/03/07 06:10:13 steve
  129 + * Use strtod to convert text to doubles.
  130 + *
167 131 * Revision 1.13 2003/03/05 03:45:01 steve
168 132 * Restore verireal constructor to match vvp processing of reals.
169 133 *

0 comments on commit 12d432d

Please sign in to comment.
Something went wrong with that request. Please try again.