From 7ad00d7ff015071e334b4023b50644de07cd4f28 Mon Sep 17 00:00:00 2001 From: oetiker Date: Thu, 11 May 2006 11:11:04 +0000 Subject: [PATCH] make DNAN and DINF faster by caching the result of the first calculation -- pascal.gloor spale.com git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@826 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_nan_inf.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/rrd_nan_inf.c b/src/rrd_nan_inf.c index 22886c4..2a5ac14 100644 --- a/src/rrd_nan_inf.c +++ b/src/rrd_nan_inf.c @@ -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 -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; +} -- 2.30.2