Code

make DNAN and DINF faster by caching the result of the first calculation -- pascal...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 11 May 2006 11:11:04 +0000 (11:11 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 11 May 2006 11:11:04 +0000 (11:11 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@826 a5681a0c-68f1-0310-ab6d-d61299d08faa

src/rrd_nan_inf.c

index 22886c4b9085d5fe5a0b3fa9d3392f87a7e40e97..2a5ac1455cd3c50b57fca647b5e59fcf99a477bc 100644 (file)
@@ -1,15 +1,32 @@
 #include "rrd_nan_inf.h"
 
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
+int done_nan = 0;
+int done_inf = 0;
+
+double dnan;
+double dinf;
 
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 #include <math.h>
 
-double set_to_DNAN(void) { return (double)fmod(0.0,0.0); }
-double set_to_DINF(void) { return (double)fabs((double)log(0.0)); }
+#define NAN_FUNC (double)fmod(0.0,0.0)
+#define INF_FUNC (double)fabs((double)log(0.0))
 
 #else
 
-double set_to_DNAN(void) { return (double)(0.0/0.0); }
-double set_to_DINF(void) { return (double)(1.0/0.0); }
+#define NAN_FUNC (double)(0.0/0.0)
+#define INF_FUNC (double)(1.0/0.0)
 
 #endif
+
+double set_to_DNAN(void)
+{
+  if ( !done_nan ) { dnan = NAN_FUNC; done_nan = 1; }
+  return dnan;
+}
+
+double set_to_DINF(void)
+{
+  if ( !done_inf ) { dinf = INF_FUNC; done_inf = 1; }
+  return dinf;
+}