X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_diff.c;h=c7c11f93a42dc32f61fb7925e48026adab7008eb;hb=f1d2d0fe8cd9a70dbe77e6523df45c856a1cc88b;hp=1d0d1f54f2ff9f0619ee22e3343a8ed3f1b14075;hpb=5837606887a6d81e8b1f7588525cb1c8783fb62b;p=rrdtool.git diff --git a/src/rrd_diff.c b/src/rrd_diff.c index 1d0d1f5..c7c11f9 100644 --- a/src/rrd_diff.c +++ b/src/rrd_diff.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.0.33 Copyright Tobias Oetiker, 1999 + * RRDtool 1.1.x Copyright Tobias Oetiker, 1999 * This code is stolen from rateup (mrtg-2.x) by Dave Rand ***************************************************************************** * diff calculate the difference between two very long integers available as @@ -7,8 +7,19 @@ ***************************************************************************** * $Id$ * $Log$ - * Revision 1.1 2001/02/25 22:25:05 oetiker - * Initial revision + * Revision 1.4 2003/03/10 00:30:34 oetiker + * handle cases with two negative numbers + * -- Sasha Mikheev + * + * Revision 1.3 2002/04/01 18:31:22 oetiker + * "!" takes a higher preference than "||" this means rrd_update N:: would + * segfault -- Oliver Cook + * + * Revision 1.2 2002/02/01 20:34:49 oetiker + * fixed version number and date/time + * + * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker + * checkin * * Revision 1.1 1998/10/08 18:21:45 oetiker * Initial revision @@ -31,21 +42,31 @@ rrd_diff(char *a, char *b) { 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 */ @@ -86,7 +107,12 @@ rrd_diff(char *a, char *b) 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; }