summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 40cc8b0)
raw | patch | inline | side by side (parent: 40cc8b0)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 20 Nov 2007 00:08:20 +0000 (00:08 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 20 Nov 2007 00:08:20 +0000 (00:08 +0000) |
fix handling of min==max where min < 0
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1234 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1234 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/rrd_format.h | patch | blob | history | |
src/rrd_graph.c | patch | blob | history | |
src/rrd_nan_inf.c | patch | blob | history |
diff --git a/src/rrd_format.h b/src/rrd_format.h
index 65d5649246baba9c17525fb6a076c604cd50e1c5..96a9a6dd4afbee8430cbbbe1e2091bf11d784e2d 100644 (file)
--- a/src/rrd_format.h
+++ b/src/rrd_format.h
#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/src/rrd_graph.c b/src/rrd_graph.c
index f04a2b3017ae855061c3e1e9b07726cc247c0ae8..fb3c7e9c1381d29f519f90f6c6e3f567a25624f3 100644 (file)
--- a/src/rrd_graph.c
+++ b/src/rrd_graph.c
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)
}
/* 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)
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;
}
}
/* 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/src/rrd_nan_inf.c b/src/rrd_nan_inf.c
index 9eae726cf509dd0a28d0c248bd0e736cf547c2ba..b13264e43a8c76254be130c91df04281b0b08558 100644 (file)
--- a/src/rrd_nan_inf.c
+++ b/src/rrd_nan_inf.c
-#include "rrd_nan_inf.h"
-
int done_nan = 0;
int done_inf = 0;
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
#include <math.h>
+#include "rrd.h"
#define NAN_FUNC (double)fmod(0.0,0.0)
#define INF_FUNC (double)fabs((double)log(0.0))