remove last traces of rrd_nan_inf.h
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Tue, 20 Nov 2007 00:08:20 +0000 (00:08 +0000)
committeroetiker <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

src/rrd_format.h
src/rrd_graph.c
src/rrd_nan_inf.c

index 65d5649..96a9a6d 100644 (file)
@@ -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;
index f04a2b3..fb3c7e9 100644 (file)
@@ -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(
index 9eae726..b13264e 100644 (file)
@@ -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 <math.h>
+#include "rrd.h"
 
 #define NAN_FUNC (double)fmod(0.0,0.0)
 #define INF_FUNC (double)fabs((double)log(0.0))