From f6ed60844f78115163b349514fa23103b029eee4 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 13 Feb 2011 19:20:34 +0000 Subject: [PATCH] part 2, the actual change --- ChangeLog | 3 ++ src/frontend/numparam/mystring.c | 4 +- src/frontend/numparam/spicenum.c | 6 +-- src/frontend/numparam/xpressn.c | 73 +++++++++++--------------------- 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 149cd9de8..553e1e7a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2011-02-13 Robert Larice + part 2, the actual change + 2011-02-13 Robert Larice part 1, whitespace and indentation, nothing else diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index 56bbf3b1f..c2bf621f1 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -896,7 +896,7 @@ strf (double x, int f1, int f2, SPICE_DSTRINGPTR dstr_p) /* e-format if f2<0, else f2 digits after the point, total width=f1 */ /* if f1=0, also e-format with f2 digits */ { - /* default f1=17, f2=-1 */ + /* ngspice default f1=17, f2=10 */ int dlen ; /* length of digits */ char *dbuf_p ; /* beginning of sprintf buffer */ SPICE_DSTRING fmt ; /* format string */ @@ -914,7 +914,7 @@ strf (double x, int f1, int f2, SPICE_DSTRINGPTR dstr_p) { cadd (&fmt, '.'); nadd (&fmt, f2); - sadd (&fmt, "lg"); + sadd (&fmt, "g"); } } else diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index dd879537a..e84b25343 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -60,12 +60,12 @@ extern int dynmaxline; /* inpcom.c:1529 */ overwrite any line pointers, or we start a new set after each sig=0 ? Anyway, we neutralize all & and .param lines (category[] array!) and we substitute all {} &() and &id placeholders by dummy numbers. - The placeholders are long long integers 100000000000000+n (15 digits, n small). + The placeholders are long long integers 100000000000000+n (17 digits, n small). */ /********** string handling ***********/ -#define PlaceHold 100000000000000LL +#define PlaceHold 10000000000000000LL static long placeholder = 0; @@ -135,7 +135,7 @@ stripbraces (SPICE_DSTRINGPTR dstr_p) cadd (&tstr, ' '); cadd ( &tstr, ' '); - naddll( &tstr, PlaceHold + placeholder); /* placeholder has 15 digits */ + naddll( &tstr, PlaceHold + placeholder); /* placeholder has 17 digits */ cadd ( &tstr, ' '); if (s[j] >= ' ') diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index 947f893e5..5e1d492f4 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -33,8 +33,8 @@ extern long dynsubst; /* see inpcom.c */ extern unsigned int dynLlen; #define MAX_STRING_INSERT 17 /* max. string length to be inserted and replaced */ -#define ACT_CHARACTS 15 /* actual string length to be inserted and replaced */ - /* was 10, needs to be less or equal to MAX_STRING_INSERT - 2 */ +#define ACT_CHARACTS 17 /* actual string length to be inserted and replaced */ +#define EXP_LENGTH 5 static double ternary_fcn (int conditional, double if_value, double else_value) @@ -1130,7 +1130,7 @@ operate (char op, double x, double y) x = x * y; break; case '/': - if (absf (y) > epsi) +// if (absf (y) > epsi) x = x / y; break; case '^': /* power */ @@ -1481,7 +1481,7 @@ evaluate (tdico * dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) /* transform t to result q. mode 0: expression, mode 1: simple variable */ double u = 0.0; int j, lq; - char dt, fmt; + char dt/*, fmt*/; entry *entry_p ; bool numeric, done, nolookup; bool err; @@ -1555,16 +1555,9 @@ evaluate (tdico * dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) u = formula (dico, t, &err); numeric = 1; } - if (numeric) - { - fmt = fmttype (u); - if (fmt == 'I') - stri (np_round (u), qstr_p); - else - { - strf (u, 17, 10, qstr_p); - } - } + /* set string to total length 17, mantissa after . is of length 9 + use sprintf with format string %17.10g */ + strf (u, 17, 10, qstr_p); spice_dstring_free(&vstr) ; return err; } @@ -1756,10 +1749,11 @@ compactfloatnb (SPICE_DSTRINGPTR vstr_p) /* try to squeeze a floating pt format to ACT_CHARACTS characters */ /* erase superfluous 000 digit streams before E */ /* bug: truncating, no rounding */ +/* Not used anymore !!*/ { int n, k, m, lex, lem; - char *expov ; - char *expnv ; +// char *expov ; +// char *expnv ; char *v_p ; SPICE_DSTRING expo_str ; SPICE_DSTRING expn_str ; @@ -1774,36 +1768,18 @@ compactfloatnb (SPICE_DSTRINGPTR vstr_p) pscopy (&expo_str, spice_dstring_value(vstr_p), n, spice_dstring_length(vstr_p)); lex = spice_dstring_length (&expo_str) ; - if (lex > 4) /* exponent only 2 digits */ - { - pscopy (&expn_str, spice_dstring_value(&expo_str), 1, 4); - expnv = spice_dstring_value(&expn_str) ; - if (atoi(expnv) < -99) - { - spice_dstring_reinit(&expo_str) ; - sadd(&expo_str, "e-099"); /* brutal */ - } - if (atoi(expnv) > +99) - { - spice_dstring_reinit(&expo_str) ; - sadd(&expo_str, "e+099"); - } - expov = spice_dstring_value(&expo_str) ; - expov[2] = expov[3]; - expov[3] = expov[4]; - expov[4] = '\0'; - spice_dstring_setlength(&expo_str,4) ; - lex = 4; - } - k = n ; /* mantissa is 0...k */ - m = MAX_STRING_INSERT; + k = n ; /* mantissa is [0..k[ */ + v_p = spice_dstring_value(vstr_p) ; - while (v_p[m] != ' ') - m--; - m++; + + for(m=k; m>0; --m) + if(v_p[m-1] == ' ') + break; + + /* FIXME, v_p[k] === 'e' thus this is never executed while ((v_p[k] == '0') && (v_p[k - 1] == '0')) - k--; + k--;*/ lem = k - m; @@ -1813,7 +1789,7 @@ compactfloatnb (SPICE_DSTRINGPTR vstr_p) pscopy (vstr_p, spice_dstring_value(vstr_p), m, lem); if (cpos('.', spice_dstring_value(vstr_p)) >= 0) { - while (lem < ACT_CHARACTS - 4) + while (lem < ACT_CHARACTS - EXP_LENGTH) { cadd(vstr_p, '0'); lem++; @@ -1823,7 +1799,7 @@ compactfloatnb (SPICE_DSTRINGPTR vstr_p) { cadd(vstr_p, '.'); lem++; - while (lem < ACT_CHARACTS - 4) + while (lem < ACT_CHARACTS - EXP_LENGTH) { cadd(vstr_p, '0'); lem++; @@ -1859,7 +1835,7 @@ insertnumber (tdico * dico, int i, char *s, SPICE_DSTRINGPTR ustr_p) spice_dstring_init(&vstr) ; spice_dstring_init(&mstr) ; scopyd (&vstr, ustr_p) ; - compactfloatnb (&vstr) ; +// compactfloatnb (&vstr) ; while ( spice_dstring_length (&vstr) < MAX_STRING_INSERT) cadd (&vstr, ' '); @@ -1879,8 +1855,9 @@ insertnumber (tdico * dico, int i, char *s, SPICE_DSTRINGPTR ustr_p) k = 0; accu = 0; - while (found && (k < 15)) + while (found && (k < 17)) { + /* parse a 15-digit number */ found = num (s[i + k]); if (found) @@ -1891,7 +1868,7 @@ insertnumber (tdico * dico, int i, char *s, SPICE_DSTRINGPTR ustr_p) if (found) { - accu = accu - 100000000000000LL; /* plausibility test */ + accu = accu - 10000000000000000LL; /* plausibility test */ found = (accu > 0) && (accu < dynsubst + 1); /* dynsubst numbers have been allocated */ }