summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrei Elkin <aelkin@mysql.com>2009-02-24 16:35:45 +0200
committerAndrei Elkin <aelkin@mysql.com>2009-02-24 16:35:45 +0200
commitb75cf4b26668975e01f1870557ea0c46fce8568f (patch)
tree063e4efcbc216ba64a34b9b0001d8f39fb222367 /include
parent1e1f4c221cedc5a2fdb236f327cc75c953e8e753 (diff)
parent0091ab20886f069bd95ad8b1b6a329909bbbd288 (diff)
downloadmariadb-git-b75cf4b26668975e01f1870557ea0c46fce8568f.tar.gz
merging from 5.0-bt rep to a local branch
Diffstat (limited to 'include')
-rw-r--r--include/config-win.h9
-rw-r--r--include/my_base.h1
-rw-r--r--include/my_global.h35
3 files changed, 34 insertions, 11 deletions
diff --git a/include/config-win.h b/include/config-win.h
index eba699159c7..ab463a7c142 100644
--- a/include/config-win.h
+++ b/include/config-win.h
@@ -31,7 +31,6 @@ functions */
#include <sys/locking.h>
#include <windows.h>
-#include <math.h> /* Because of rint() */
#include <fcntl.h>
#include <io.h>
#include <malloc.h>
@@ -223,13 +222,6 @@ typedef uint rf_SetTimer;
#define inline __inline
#endif /* __cplusplus */
-inline double rint(double nr)
-{
- double f = floor(nr);
- double c = ceil(nr);
- return (((c-nr) >= (nr-f)) ? f :c);
-}
-
#ifdef _WIN64
#define ulonglong2double(A) ((double) (ulonglong) (A))
#define my_off_t2double(A) ((double) (my_off_t) (A))
@@ -281,7 +273,6 @@ inline ulonglong double2ulonglong(double d)
#define HAVE_FLOAT_H
#define HAVE_LIMITS_H
#define HAVE_STDDEF_H
-#define HAVE_RINT /* defined in this file */
#define NO_FCNTL_NONBLOCK /* No FCNTL */
#define HAVE_ALLOCA
#define HAVE_STRPBRK
diff --git a/include/my_base.h b/include/my_base.h
index 9240b01a9f1..e45a73d68ed 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -377,6 +377,7 @@ enum ha_base_keytype {
#define HA_ERR_TABLE_READONLY 161 /* The table is not writable */
#define HA_ERR_AUTOINC_READ_FAILED 162/* Failed to get the next autoinc value */
#define HA_ERR_AUTOINC_ERANGE 163 /* Failed to set the row autoinc value */
+/* You must also add numbers and description to extra/perror.c ! */
#define HA_ERR_LAST 163 /*Copy last error nr.*/
/* Add error numbers before HA_ERR_LAST and change it accordingly. */
diff --git a/include/my_global.h b/include/my_global.h
index 845ae042a42..3f872bfc855 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -484,8 +484,39 @@ typedef unsigned short ushort;
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
#ifndef HAVE_RINT
-#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
-#endif
+/**
+ All integers up to this number can be represented exactly as double precision
+ values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
+*/
+#define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
+
+/**
+ rint(3) implementation for platforms that do not have it.
+ Always rounds to the nearest integer with ties being rounded to the nearest
+ even integer to mimic glibc's rint() behavior in the "round-to-nearest"
+ FPU mode. Hardware-specific optimizations are possible (frndint on x86).
+ Unlike this implementation, hardware will also honor the FPU rounding mode.
+*/
+
+static inline double rint(double x)
+{
+ double f, i;
+ f = modf(x, &i);
+ /*
+ All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
+ no need to check it.
+ */
+ if (x > 0.0)
+ i += (double) ((f > 0.5) || (f == 0.5 &&
+ i <= (double) MAX_EXACT_INTEGER &&
+ (longlong) i % 2));
+ else
+ i -= (double) ((f < -0.5) || (f == -0.5 &&
+ i >= (double) -MAX_EXACT_INTEGER &&
+ (longlong) i % 2));
+ return i;
+}
+#endif /* HAVE_RINT */
/* Define some general constants */
#ifndef TRUE