/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Generator/Phokhara/Phokhara-00-00-14/src/ranlxd.c File Reference

#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

Go to the source code of this file.

Classes

struct  vec_t
struct  dble_vec_t

Defines

#define BASE   0x1000000
#define MASK   0xffffff
#define STEP(pi, pj)

Functions

static void error (int no)
static void update ()
static void define_constants ()
void rlxd_init (int level, int seed)
void ranlxd (double r[], int n)
int rlxd_size (void)
void rlxd_get (int state[])
void rlxd_reset (int state[])

Variables

static int init = 0
static int pr
static int prm
static int ir
static int jr
static int is
static int is_old
static int next [96]
static double one_bit
static vec_t carry
union {
   dble_vec_t   vec [12]
   int   num [96]
x


Define Documentation

#define BASE   0x1000000

Definition at line 353 of file ranlxd.c.

#define MASK   0xffffff

Definition at line 354 of file ranlxd.c.

#define STEP ( pi,
pj   ) 

Definition at line 376 of file ranlxd.c.


Function Documentation

static void define_constants (  )  [static]

Definition at line 478 of file ranlxd.c.

00479 {
00480    int k;
00481 
00482    one_bit=ldexp(1.0,-24);
00483 
00484    for (k=0;k<96;k++)
00485    {
00486       next[k]=(k+1)%96;
00487       if ((k%4)==3)
00488          next[k]=(k+5)%96;
00489    }   
00490 }

static void error ( int  no  )  [static]

Definition at line 411 of file ranlxd.c.

00412 {
00413    switch(no)
00414    {
00415       case 0:
00416          printf("Error in rlxd_init\n");
00417          printf("Arithmetic on this machine is not suitable for ranlxd\n");
00418          break;
00419       case 1:
00420          printf("Error in subroutine rlxd_init\n");
00421          printf("Bad choice of luxury level (should be 1 or 2)\n");
00422          break;
00423       case 2:
00424          printf("Error in subroutine rlxd_init\n");
00425          printf("Bad choice of seed (should be between 1 and 2^31-1)\n");
00426          break;
00427       case 3:
00428          printf("Error in rlxd_get\n");
00429          printf("Undefined state (ranlxd is not initialized)\n");
00430          break;
00431       case 4:
00432          printf("Error in rlxd_reset\n");
00433          printf("Arithmetic on this machine is not suitable for ranlxd\n");
00434          break;
00435       case 5:
00436          printf("Error in rlxd_reset\n");
00437          printf("Unexpected input data\n");
00438          break;
00439    }         
00440    printf("Program aborted\n");
00441    exit(0);
00442 }

void ranlxd ( double  r[],
int  n 
)

Definition at line 563 of file ranlxd.c.

References rlxd_init(), update(), and x.

00564 {
00565    int k;
00566 
00567    if (init==0)
00568       rlxd_init(0,1);
00569 
00570    for (k=0;k<n;k++) 
00571    {
00572       is=next[is];
00573       if (is==is_old)
00574          update();
00575       r[k]=one_bit*((double)(x.num[is+4])+one_bit*(double)(x.num[is]));      
00576    }
00577 }

void rlxd_get ( int  state[]  ) 

Definition at line 586 of file ranlxd.c.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, carry, ers::error, pr, rlxd_size(), and x.

00587 {
00588    int k;
00589 
00590    if (init==0)
00591       error(3);
00592 
00593    state[0]=rlxd_size();
00594 
00595    for (k=0;k<96;k++)
00596       state[k+1]=x.num[k];
00597 
00598    state[97]=carry.c1;
00599    state[98]=carry.c2;
00600    state[99]=carry.c3;
00601    state[100]=carry.c4;
00602 
00603    state[101]=pr;
00604    state[102]=ir;
00605    state[103]=jr;
00606    state[104]=is;
00607 }

void rlxd_init ( int  level,
int  seed 
)

Definition at line 493 of file ranlxd.c.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, carry, define_constants(), ers::error, pr, and x.

00494 {
00495    int i,k,l;
00496    int ibit,jbit,xbit[31];
00497    int ix,iy;
00498 
00499    if ((INT_MAX<2147483647)||(FLT_RADIX!=2)||(FLT_MANT_DIG<24)||
00500        (DBL_MANT_DIG<48))
00501       error(0);
00502 
00503    define_constants();
00504    
00505    if (level==1)
00506       pr=202;
00507    else if (level==2)
00508       pr=397;
00509    else
00510       error(1);
00511    
00512    i=seed;
00513 
00514    for (k=0;k<31;k++) 
00515    {
00516       xbit[k]=i%2;
00517       i/=2;
00518    }
00519 
00520    if ((seed<=0)||(i!=0))
00521       error(2);
00522 
00523    ibit=0;
00524    jbit=18;
00525 
00526    for (i=0;i<4;i++)
00527    {
00528       for (k=0;k<24;k++)
00529       {
00530          ix=0;
00531 
00532          for (l=0;l<24;l++) 
00533          {
00534             iy=xbit[ibit];
00535             ix=2*ix+iy;
00536          
00537             xbit[ibit]=(xbit[ibit]+xbit[jbit])%2;
00538             ibit=(ibit+1)%31;
00539             jbit=(jbit+1)%31;
00540          }
00541 
00542          if ((k%4)!=i)
00543             ix=16777215-ix;
00544 
00545          x.num[4*k+i]=ix;
00546       }
00547    }
00548 
00549    carry.c1=0;
00550    carry.c2=0;
00551    carry.c3=0;
00552    carry.c4=0;
00553 
00554    ir=0;
00555    jr=7;
00556    is=91;
00557    is_old=0;
00558    prm=pr%12;
00559    init=1;
00560 }

void rlxd_reset ( int  state[]  ) 

Definition at line 610 of file ranlxd.c.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, carry, define_constants(), ers::error, pr, rlxd_size(), and x.

00611 {
00612    int k;
00613 
00614    if ((INT_MAX<2147483647)||(FLT_RADIX!=2)||(FLT_MANT_DIG<24)||
00615        (DBL_MANT_DIG<48))
00616       error(4);
00617 
00618    define_constants();
00619 
00620    if (state[0]!=rlxd_size())
00621       error(5);
00622 
00623    for (k=0;k<96;k++)
00624    {
00625       if ((state[k+1]<0)||(state[k+1]>=167777216))
00626          error(5);
00627 
00628       x.num[k]=state[k+1];
00629    }
00630 
00631    if (((state[97]!=0)&&(state[97]!=1))||
00632        ((state[98]!=0)&&(state[98]!=1))||
00633        ((state[99]!=0)&&(state[99]!=1))||
00634        ((state[100]!=0)&&(state[100]!=1)))
00635       error(5);
00636    
00637    carry.c1=state[97];
00638    carry.c2=state[98];
00639    carry.c3=state[99];
00640    carry.c4=state[100];
00641 
00642    pr=state[101];
00643    ir=state[102];
00644    jr=state[103];
00645    is=state[104];
00646    is_old=8*ir;
00647    prm=pr%12;
00648    init=1;
00649    
00650    if (((pr!=202)&&(pr!=397))||
00651        (ir<0)||(ir>11)||(jr<0)||(jr>11)||(jr!=((ir+7)%12))||
00652        (is<0)||(is>91))
00653       error(5);
00654 }

int rlxd_size ( void   ) 

Definition at line 580 of file ranlxd.c.

00581 {
00582    return(105);
00583 }

static void update (  )  [static]

Definition at line 445 of file ranlxd.c.

References pi, pr, STEP, and x.

00446 {
00447    int k,kmax,d;
00448    dble_vec_t *pmin,*pmax,*pi,*pj;
00449 
00450    kmax=pr;
00451    pmin=&x.vec[0];
00452    pmax=pmin+12;
00453    pi=&x.vec[ir];
00454    pj=&x.vec[jr];
00455       
00456    for (k=0;k<kmax;k++) 
00457    {
00458       STEP(pi,pj);
00459       pi+=1;
00460       pj+=1;
00461       if (pi==pmax)
00462          pi=pmin;      
00463       if (pj==pmax)
00464          pj=pmin; 
00465    }
00466 
00467    ir+=prm;
00468    jr+=prm;
00469    if (ir>=12)
00470       ir-=12;
00471    if (jr>=12)
00472       jr-=12;
00473    is=8*ir;
00474    is_old=is;
00475 }


Variable Documentation

vec_t carry [static]

Definition at line 368 of file ranlxd.c.

int init = 0 [static]

Definition at line 366 of file ranlxd.c.

int ir [static]

Definition at line 366 of file ranlxd.c.

int is [static]

Definition at line 366 of file ranlxd.c.

int is_old [static]

Definition at line 366 of file ranlxd.c.

int jr [static]

Definition at line 366 of file ranlxd.c.

int next[96] [static]

Definition at line 366 of file ranlxd.c.

int num[96]

Definition at line 373 of file ranlxd.c.

double one_bit [static]

Definition at line 367 of file ranlxd.c.

int pr [static]

Definition at line 366 of file ranlxd.c.

int prm [static]

Definition at line 366 of file ranlxd.c.

dble_vec_t vec[12]

Definition at line 372 of file ranlxd.c.

union { ... } x [static]


Generated on Tue Nov 29 23:16:02 2016 for BOSS_7.0.2 by  doxygen 1.4.7