summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c20f3bf)
raw | patch | inline | side by side (parent: c20f3bf)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 10 Mar 2003 00:30:34 +0000 (00:30 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 10 Mar 2003 00:30:34 +0000 (00:30 +0000) |
-- Sasha Mikheev <sasha@avalon-net.co.il>
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@191 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@191 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/rrd_diff.c | patch | blob | history |
diff --git a/src/rrd_diff.c b/src/rrd_diff.c
index 3f80a156bd4f2694f83b38d6c0b186328ca54456..c7c11f93a42dc32f61fb7925e48026adab7008eb 100644 (file)
--- a/src/rrd_diff.c
+++ b/src/rrd_diff.c
*****************************************************************************
* $Id$
* $Log$
+ * Revision 1.4 2003/03/10 00:30:34 oetiker
+ * handle cases with two negative numbers
+ * -- Sasha Mikheev <sasha@avalon-net.co.il>
+ *
* Revision 1.3 2002/04/01 18:31:22 oetiker
* "!" takes a higher preference than "||" this means rrd_update N:: would
* segfault -- Oliver Cook <ollie@uk.clara.net>
{
char res[LAST_DS_LEN+1], *a1, *b1, *r1, *fix;
int c,x,m;
-
- while (!(isdigit((int)*a) || *a==0))
+ char a_neg=0, b_neg=0;
+ double result;
+
+ while (!(isdigit((int)*a) || *a==0)) {
+ if(*a=='-')
+ a_neg = 1;
a++;
+ }
fix=a;
while (isdigit((int)*fix))
fix++;
*fix = 0; /* maybe there is some non digit data in the string */
- while (!(isdigit((int)*b) || *b==0))
+ while (!(isdigit((int)*b) || *b==0)) {
+ if(*b=='-')
+ b_neg = 1;
b++;
+ }
fix=b;
while (isdigit((int)*fix))
fix++;
*fix = 0; /* maybe there is some non digit data in the string */
if(!isdigit((int)*a) || !isdigit((int)*b))
return DNAN;
+ if(a_neg+b_neg == 1) /* can not handle numbers with different signs yet */
+ return DNAN;
a1 = &a[strlen(a)-1];
m = max(strlen(a),strlen(b));
if (m > LAST_DS_LEN) return DNAN; /* result string too short */
c=0;
}
}
- return(-atof(res));
+ result = -atof(res);
} else
- return(atof(res));
+ result = atof(res);
+
+ if(a_neg+b_neg==2) /* both are negatives, reverse sign */
+ result = -result;
+
+ return result;
}