summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorTom Lane2009-07-16 17:43:52 +0000
committerTom Lane2009-07-16 17:43:52 +0000
commitc43feefa806c81d68115ed03a7f723720cefad31 (patch)
tree6fd7b6a6b70656c57f483c2e361f8ec73185358d /src/port
parentfe1cc1e730cf5bdf4576aeab7fafd1da4b41285b (diff)
Add erand48() to the set of functions supported by our src/port/ library,
and extend configure to test for it properly instead of hard-wiring an assumption that everybody but Windows has the rand48 functions. (We do cheat to the extent of assuming that probing for erand48 will do for the entire rand48 family.) erand48() is unused as of this commit, but a followon patch will cause GEQO to depend on it. Andres Freund, additional hacking by Tom
Diffstat (limited to 'src/port')
-rw-r--r--src/port/erand48.c (renamed from src/port/rand.c)44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/port/rand.c b/src/port/erand48.c
index 8559ef8c175..ce623e2e965 100644
--- a/src/port/rand.c
+++ b/src/port/erand48.c
@@ -1,16 +1,13 @@
-/*
- * $PostgreSQL: pgsql/src/port/rand.c,v 1.6 2009/06/11 14:49:15 momjian Exp $
+/*-------------------------------------------------------------------------
*
- *-------------------------------------------------------------------------
+ * erand48.c
+ *
+ * This file supplies versions of erand48(), lrand48(), and srand48()
+ * for machines that lack them. (These are all the members of the drand48
+ * family that Postgres currently requires. We name the file after erand48
+ * because that is the one that configure tests for.)
*
- * rand.c
- * Missing rand implementations for Win32
*
- *-------------------------------------------------------------------------
- */
-#include "c.h"
-
-/*
* Copyright (c) 1993 Martin Birgmeier
* All rights reserved.
*
@@ -21,7 +18,17 @@
* This software is provided ``as is'', and comes with no warranties
* of any kind. I shall in no event be liable for anything that happens
* to anyone/anything when using this software.
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgsql/src/port/erand48.c,v 1.1 2009/07/16 17:43:52 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
*/
+
+#include "c.h"
+
+#include <math.h>
+
#define RAND48_SEED_0 (0x330e)
#define RAND48_SEED_1 (0xabcd)
#define RAND48_SEED_2 (0x1234)
@@ -30,17 +37,18 @@
#define RAND48_MULT_2 (0x0005)
#define RAND48_ADD (0x000b)
-unsigned short _rand48_seed[3] = {
+static unsigned short _rand48_seed[3] = {
RAND48_SEED_0,
RAND48_SEED_1,
RAND48_SEED_2
};
-unsigned short _rand48_mult[3] = {
+static unsigned short _rand48_mult[3] = {
RAND48_MULT_0,
RAND48_MULT_1,
RAND48_MULT_2
};
-unsigned short _rand48_add = RAND48_ADD;
+static unsigned short _rand48_add = RAND48_ADD;
+
static void
_dorand48(unsigned short xseed[3])
@@ -62,6 +70,16 @@ _dorand48(unsigned short xseed[3])
xseed[2] = (unsigned short) accu;
}
+
+double
+erand48(unsigned short xseed[3])
+{
+ _dorand48(xseed);
+ return ldexp((double) xseed[0], -48) +
+ ldexp((double) xseed[1], -32) +
+ ldexp((double) xseed[2], -16);
+}
+
long
lrand48(void)
{