initial check-in, version 0.5.0

This commit is contained in:
Rich Felker 2011-02-12 00:22:29 -05:00
commit 0b44a0315b
1021 changed files with 45711 additions and 0 deletions

14
src/prng/__rand48_step.c Normal file
View file

@ -0,0 +1,14 @@
#include <stdlib.h>
#include <inttypes.h>
uint64_t __rand48_step(unsigned short *xi, unsigned short *lc)
{
uint64_t a, x;
x = xi[0] | xi[1]<<16 | xi[2]+0ULL<<32;
a = lc[0] | lc[1]<<16 | lc[2]+0ULL<<32;
x = a*x + lc[3];
xi[0] = x;
xi[1] = x>>16;
xi[2] = x>>32;
return x & 0xffffffffffffull;
}

1
src/prng/__seed48.c Normal file
View file

@ -0,0 +1 @@
unsigned short __seed48[7] = { 0, 0, 0, 0xe66d, 0xdeec, 0x5, 0xb };

19
src/prng/drand48.c Normal file
View file

@ -0,0 +1,19 @@
#include <stdlib.h>
#include <inttypes.h>
uint64_t __rand48_step(unsigned short *xi, unsigned short *lc);
extern unsigned short __seed48[7];
double erand48(unsigned short s[3])
{
union {
uint64_t u;
double f;
} x = { 0x3ff0000000000000ULL | __rand48_step(s, __seed48+3)<<4 };
return x.f - 1.0;
}
double drand48(void)
{
return erand48(__seed48);
}

9
src/prng/lcong48.c Normal file
View file

@ -0,0 +1,9 @@
#include <stdlib.h>
#include <string.h>
extern unsigned short __seed48[7];
void lcong48(unsigned short p[7])
{
memcpy(__seed48, p, sizeof __seed48);
}

15
src/prng/lrand48.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdlib.h>
#include <inttypes.h>
uint64_t __rand48_step(unsigned short *xi, unsigned short *lc);
extern unsigned short __seed48[7];
long nrand48(unsigned short s[3])
{
return __rand48_step(s, __seed48+3) >> 17;
}
long lrand48(void)
{
return nrand48(__seed48);
}

15
src/prng/mrand48.c Normal file
View file

@ -0,0 +1,15 @@
#include <stdlib.h>
#include <inttypes.h>
uint64_t __rand48_step(unsigned short *xi, unsigned short *lc);
extern unsigned short __seed48[7];
long jrand48(unsigned short s[3])
{
return __rand48_step(s, __seed48+3) >> 16;
}
long mrand48(void)
{
return jrand48(__seed48);
}

13
src/prng/rand.c Normal file
View file

@ -0,0 +1,13 @@
#include <stdlib.h>
static unsigned seed;
void srand(unsigned s)
{
seed = s-1;
}
int rand(void)
{
return (seed = (seed+1) * 1103515245 + 12345 - 1)+1 & 0x7fffffff;
}

6
src/prng/rand_r.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdlib.h>
int rand_r(unsigned *seed)
{
return (*seed = *seed * 1103515245 + 12345) & 0x7fffffff;
}

8
src/prng/random.c Normal file
View file

@ -0,0 +1,8 @@
#include <stdlib.h>
/* FIXME */
long random()
{
return rand();
}

12
src/prng/seed48.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdlib.h>
#include <string.h>
extern unsigned short __seed48[7];
unsigned short *seed48(unsigned short *s)
{
static unsigned short p[3];
memcpy(p, __seed48, sizeof p);
memcpy(__seed48, s, sizeof p);
return p;
}

6
src/prng/srand48.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdlib.h>
void srand48(long seed)
{
seed48((unsigned short [3]){ 0x330e, seed, seed>>16 });
}

8
src/prng/srandom.c Normal file
View file

@ -0,0 +1,8 @@
#include <stdlib.h>
/* FIXME */
void srandom(unsigned seed)
{
return srand(seed);
}