From 7549b3409e9758213f2795c50e7a70713a44b5e1 Mon Sep 17 00:00:00 2001 From: rlar Date: Fri, 29 Apr 2016 18:38:39 +0200 Subject: [PATCH] numparam/xpressn.c, abstraction, introduce `double_to_string()' --- src/frontend/numparam/xpressn.c | 36 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index c5b2cd633..f6a5c6fae 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -1081,6 +1081,26 @@ formula(dico_t *dico, const char *s, const char *s_end, bool *perror) } +/* stupid, produce a string representation of a given double + * to be spliced back into the circuit deck + * we want *exactly* 25 chars, we have + * sign, leading digit, '.', 'e', sign, upto 3 digits exponent + * ==> 8 chars, thus we have 17 left for precision + * don't print a leading '+', something choked + */ + +static void +double_to_string(SPICE_DSTRINGPTR qstr_p, double value) +{ + char buf[ACT_CHARACTS + 1]; + if (snprintf(buf, sizeof(buf), "% 25.17e", value) != ACT_CHARACTS) { + fprintf(stderr, "ERROR: xpressn.c, %s(%d)\n", __FUNCTION__, __LINE__); + controlled_exit(1); + } + scopys(qstr_p, buf); +} + + static bool evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) { @@ -1125,20 +1145,8 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) numeric = 1; } - if (numeric) { - /* we want *exactly* 25 chars, we have - * sign, leading digit, '.', 'e', sign, upto 3 digits exponent - * ==> 8 chars, thus we have 17 left for precision - * don't print a leading '+', something choked - */ - - char buf[ACT_CHARACTS + 1]; - if (snprintf(buf, sizeof(buf), "% 25.17e", u) != ACT_CHARACTS) { - fprintf(stderr, "ERROR: xpressn.c, %s(%d)\n", __FUNCTION__, __LINE__); - controlled_exit(1); - } - scopys(qstr_p, buf); - } + if (numeric) + double_to_string(qstr_p, u); return err; }