From: oetiker Date: Thu, 11 May 2006 11:11:04 +0000 (+0000) Subject: make DNAN and DINF faster by caching the result of the first calculation -- pascal... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=397ab83fcf2e89174bb294dc2e48d08a1119d689;p=rrdtool-all.git 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@826 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_nan_inf.c b/program/src/rrd_nan_inf.c index 22886c4b..2a5ac145 100644 --- a/program/src/rrd_nan_inf.c +++ b/program/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; +}