From af99e6f445f9a82fb4e6bdeca013bd2c787f9f53 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 20 Nov 2007 00:08:20 +0000 Subject: [PATCH] remove last traces of rrd_nan_inf.h fix handling of min==max where min < 0 git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1234 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_format.h | 2 - program/src/rrd_graph.c | 86 +++++++++++++++++++++------------------ program/src/rrd_nan_inf.c | 3 +- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/program/src/rrd_format.h b/program/src/rrd_format.h index 65d56492..96a9a6dd 100644 --- a/program/src/rrd_format.h +++ b/program/src/rrd_format.h @@ -25,8 +25,6 @@ #define RRD_VERSION3 "0003" #define FLOAT_COOKIE 8.642135E130 -#include "rrd_nan_inf.h" - typedef union unival { unsigned long u_cnt; rrd_value_t u_val; diff --git a/program/src/rrd_graph.c b/program/src/rrd_graph.c index f04a2b30..fb3c7e9c 100644 --- a/program/src/rrd_graph.c +++ b/program/src/rrd_graph.c @@ -1115,6 +1115,39 @@ int data_calc( return 0; } +static int AlmostEqual2sComplement( + float A, + float B, + int maxUlps) +{ + + int aInt = *(int *) &A; + int bInt = *(int *) &B; + int intDiff; + + /* Make sure maxUlps is non-negative and small enough that the + default NAN won't compare as equal to anything. */ + + /* assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); */ + + /* Make aInt lexicographically ordered as a twos-complement int */ + + if (aInt < 0) + aInt = 0x80000000l - aInt; + + /* Make bInt lexicographically ordered as a twos-complement int */ + + if (bInt < 0) + bInt = 0x80000000l - bInt; + + intDiff = abs(aInt - bInt); + + if (intDiff <= maxUlps) + return 1; + + return 0; +} + /* massage data so, that we get one value for each x coordinate in the graph */ int data_proc( image_desc_t *im) @@ -1227,8 +1260,8 @@ int data_proc( } /* adjust min and max values */ + /* for logscale we add something on top */ if (isnan(im->minval) - /* don't adjust low-end with log scale *//* why not? */ || ((!im->rigid) && im->minval > minval) ) { if (im->logarithmic) @@ -1244,19 +1277,24 @@ int data_proc( else im->maxval = maxval; } + /* make sure min is smaller than max */ if (im->minval > im->maxval) { - im->minval = 0.99 * im->maxval; + if (im->minval > 0) + im->minval = 0.99 * im->maxval; + else + im->minval = 1.01 * im->maxval; } /* make sure min and max are not equal */ - if (im->minval == im->maxval) { - im->maxval *= 1.01; - if (!im->logarithmic) { - im->minval *= 0.99; - } + if (AlmostEqual2sComplement(im->minval,im->maxval,4)) { + if (im->maxval > 0) + im->maxval *= 1.01; + else + im->maxval *= 0.99; + /* make sure min and max are not both zero */ - if (im->maxval == 0.0) { + if (AlmostEqual2sComplement(im->maxval,0,4)) { im->maxval = 1.0; } } @@ -2001,38 +2039,6 @@ double frexp10( /* yes we are loosing precision by doing tos with floats instead of doubles but it seems more stable this way. */ -static int AlmostEqual2sComplement( - float A, - float B, - int maxUlps) -{ - - int aInt = *(int *) &A; - int bInt = *(int *) &B; - int intDiff; - - /* Make sure maxUlps is non-negative and small enough that the - default NAN won't compare as equal to anything. */ - - /* assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); */ - - /* Make aInt lexicographically ordered as a twos-complement int */ - - if (aInt < 0) - aInt = 0x80000000l - aInt; - - /* Make bInt lexicographically ordered as a twos-complement int */ - - if (bInt < 0) - bInt = 0x80000000l - bInt; - - intDiff = abs(aInt - bInt); - - if (intDiff <= maxUlps) - return 1; - - return 0; -} /* logaritmic horizontal grid */ int horizontal_log_grid( diff --git a/program/src/rrd_nan_inf.c b/program/src/rrd_nan_inf.c index 9eae726c..b13264e4 100644 --- a/program/src/rrd_nan_inf.c +++ b/program/src/rrd_nan_inf.c @@ -1,5 +1,3 @@ -#include "rrd_nan_inf.h" - int done_nan = 0; int done_inf = 0; @@ -8,6 +6,7 @@ double dinf; #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include +#include "rrd.h" #define NAN_FUNC (double)fmod(0.0,0.0) #define INF_FUNC (double)fabs((double)log(0.0)) -- 2.30.2