From d4496916864889169544529df498207bfd2e37c5 Mon Sep 17 00:00:00 2001 From: Dave Beckett Date: Sun, 21 Aug 2011 18:44:22 -0700 Subject: Compile a local lround() if it is not present. --- src/snprintf.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/snprintf.c') diff --git a/src/snprintf.c b/src/snprintf.c index be9ad495..f28f40a9 100644 --- a/src/snprintf.c +++ b/src/snprintf.c @@ -11,6 +11,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + #include "raptor2.h" #include "raptor_internal.h" @@ -28,6 +32,24 @@ #define trunc(x) (((x) < 0) ? ceil((x)) : floor((x))) #endif +#ifndef HAVE_LROUND +static long +raptor_lround(double d) +{ + /* Add +/- 0.5 then then round towards zero. */ + d = floor(d); + + if(isnan(d) || d > (double)LONG_MAX || d < (double)LONG_MIN) { + errno = ERANGE; + /* Undefined behaviour, so we could return anything. */ + /* return tmp > 0.0 ? LONG_MAX : LONG_MIN; */ + } + return (long)d; +} +#define lround(x) raptor_lround(x) +#endif + + /* Convert a double to xsd:decimal representation. * Returned is a pointer to the first character of the number * in buffer (don't free it). -- cgit v1.2.1