@ -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
* Copyright ( c ) 1993 Martin Birgmeier
* All rights reserved .
* All rights reserved .
*
*
@ -21,7 +18,17 @@
* This software is provided ` ` as is ' ' , and comes with no warranties
* 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
* of any kind . I shall in no event be liable for anything that happens
* to anyone / anything when using this software .
* 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_0 (0x330e)
# define RAND48_SEED_1 (0xabcd)
# define RAND48_SEED_1 (0xabcd)
# define RAND48_SEED_2 (0x1234)
# define RAND48_SEED_2 (0x1234)
@ -30,17 +37,18 @@
# define RAND48_MULT_2 (0x0005)
# define RAND48_MULT_2 (0x0005)
# define RAND48_ADD (0x000b)
# define RAND48_ADD (0x000b)
unsigned short _rand48_seed [ 3 ] = {
static unsigned short _rand48_seed [ 3 ] = {
RAND48_SEED_0 ,
RAND48_SEED_0 ,
RAND48_SEED_1 ,
RAND48_SEED_1 ,
RAND48_SEED_2
RAND48_SEED_2
} ;
} ;
unsigned short _rand48_mult [ 3 ] = {
static unsigned short _rand48_mult [ 3 ] = {
RAND48_MULT_0 ,
RAND48_MULT_0 ,
RAND48_MULT_1 ,
RAND48_MULT_1 ,
RAND48_MULT_2
RAND48_MULT_2
} ;
} ;
unsigned short _rand48_add = RAND48_ADD ;
static unsigned short _rand48_add = RAND48_ADD ;
static void
static void
_dorand48 ( unsigned short xseed [ 3 ] )
_dorand48 ( unsigned short xseed [ 3 ] )
@ -62,6 +70,16 @@ _dorand48(unsigned short xseed[3])
xseed [ 2 ] = ( unsigned short ) accu ;
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
long
lrand48 ( void )
lrand48 ( void )
{
{