diff options
author | Dave Beckett <dave@dajobe.org> | 2011-08-21 18:44:22 -0700 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2011-08-21 18:44:22 -0700 |
commit | d4496916864889169544529df498207bfd2e37c5 (patch) | |
tree | 8201664374d60ee4ea73f7572b54459b70adfeb0 /src | |
parent | 43f1c50372d3e0c2237028d447a7684ce9f08b87 (diff) | |
download | raptor-d4496916864889169544529df498207bfd2e37c5.tar.gz |
Compile a local lround() if it is not present.
Diffstat (limited to 'src')
-rw-r--r-- | src/snprintf.c | 22 |
1 files changed, 22 insertions, 0 deletions
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 <raptor_config.h> #endif +#ifdef WIN32 +#include <win32_raptor_config.h> +#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). |