Exemple #1
0
real sqrtx2y2(const real& x, const real& y) throw()
// calculating sqrt(x^2 + y^2) in high accuracy. Blomquist 01.12.02
{
    real a,b,r;
    dotprecision dot;
    int exa,exb,ex;
    a = x;   b = y;
    exa = expo(a);  exb = expo(b);
    if (exb > exa)
    { // Permutation of a,b:
	r = a;  a = b;  b = r;
	ex = exa;  exa = exb;  exb = ex;
    }  // |a| >= |b|
    // a = |a| >= |b| > 0:
    ex = 511 - exa;   // scaling a with 2^ex --> expo(a) == 511, --> a*a and
    times2pown(a,ex); // b*b without overflow. An underflow of b*b will not
    times2pown(b,ex); // affect the accuracy of the result!
    dot = 0;
    accumulate(dot,a,a);
    accumulate(dot,b,b);
    r = rnd(dot);
    r = sqrt(r); // sqrt(...) declared in rmath.hpp
    times2pown(r,-ex); // back-scaling
    return r;
} // sqrtx2y2
Exemple #2
0
//exponentiation by squaring
int expo(int a, int b){
    if (b==1)
        return a;
    if (b==2)
        return a*a;

    if (b%2==0){
            return expo(expo(a,b/2),2);
    }
    else{
        return a*expo(expo(a,(b-1)/2),2);
    }
}
    		/**@ buildkill.p **/
    void /*PROCEDURE*/ buildkill(int itype, int ienv)  /***COMPILED***/   /*COMPILED*/
    	/** purpose: to compute timekill and nallts and timevec **/
    	/** called by inschedule, indrugs, inkill **/
    	/** calls buildsched and sortsched first **/
    /*VAR*/
     {
    	 integer itime, isched;
    	 struct drugandtime s; /*** DECLARATOR **/
    
    	buildsched();
    	sortsched();
        
  		if ( itype > 0 ) {
    	nallts = 1;
    	for (itime = 0; itime  <= MAXTIMES; itime ++)  {
    		timevec [itime] = ZERO;
  		timekill (itime, itype,ienv) = ZERO;
  		timesurv (itime, itype,ienv) = ONE;
  	}
  
  	drugkill (0, itype,ienv) = ZERO;
  
    	for (isched = 1; isched  <= nsched; isched ++) {
    		s=sched [isched] ;
    		if ( s.t != timevec [nallts])  {
    			nallts = nallts + 1;
    			timevec [nallts] = s.t;
    		}
  		timekill (nallts, itype,ienv) =  1 -
  				(1 - timekill (nallts, itype,ienv))
  				*expo (-drugkill (s.d,itype,ienv)* s.df  * 2.3025850929);
    /* added the dose factor to implement the reduction of dosage
    				*expo (-drugkill [s.d][ itype]* dosefactor[s.d]* 2.3025850929);*/
  			timesurv (nallts,itype,ienv) = 
  				timesurv (nallts, itype,ienv) *
 				expo (-drugkill(s.d, itype,ienv) * s.df * 2.3025850929);
    /* Made the above two changes on 14 Aug 1996 -- Sai
    				expo (-drugkill [s.d][ itype]* dosefactor[s.d] * 2.3025850929);*/
    	}
    

    /** the following assures that jointpgf is computed at the last time
      indicated in the EVAL schedule (except for TIMECOURSE and DOSERESPONSE) **/
    	nt = nallts;
    	if ( (ndoses [EVAL] >0) )
    		while ((doselist [EVAL][ ndoses [EVAL]] < timevec [nt])
    			&& (nt >= 0) )
    				nt = nt - 1;
 	}
    }
Exemple #4
0
int getValue() // return value of current hex in decimal
{
  int i = 255; // last index of char
  int curPow = 0;
  int totalVal = 0;
  
  while ( i >= 0)
  {
  	if ( hexBuff[ i] != '\0')
  	{
      int curDig = 0;
  	  char curChar = hexBuff[ i];

  	  if ( inUppercase( curChar))        // then it's an uppercase letter from A to F inclusive
  	  	curDig = 10 + (int) ( curChar - 'A');
  	  else                               // then it's a number
  	    curDig = (int) ( curChar - '0');

  	  totalVal += curDig * expo( 16, curPow);
  	  ++ curPow;
  	}
  	-- i;
  }
  return totalVal;
}
Exemple #5
0
// method to print the current symbol 
// mostly for debugging
void writesym() 
{
  fputs( symname[ sym][ 0], stdout);

  switch( sym) 
  {
    case ident:
      fputs( ": ", stdout);
      fputs( idbuff, stdout);
      break;
    case CHAR_SYM:
    case string:
      fputs( ": ", stdout);
      fputs( strbuff, stdout);
      break;
    case int_number: 
      printf( ": %d", intval);
      break;
    case hexint_number: 
      fputs(": ", stdout);
      fputs( hexBuff, stdout);
      break;
    case real_number:
      printf( ": %f", (intval + decimals/(expo(10.0f, numdigs))));
      break;
    default:
      break;
  } // end switch
  
  fputs( "\n", stdout);
} // end writesym
Exemple #6
0
real sqrt1mx2(const real& x) throw(STD_FKT_OUT_OF_DEF)
// sqrt(1-x2);  rel. Fehlerschranke:  eps = 3.700747E-16 = e(f)
// Blomquist, 19.06.04;
{ 
    real t=x,res;
    int ex;
    if (sign(t)<0) t = -t; // Argument t >=0;
    if (t>1) cxscthrow(STD_FKT_OUT_OF_DEF("real sqrt1mx2(const real&)"));
    // For argument t now it holds: 0 <= t <=1;
    ex = expo(t);
    if (ex<=-26) res = 1; // t < 2^(-26) --> res = 1
    else if (ex<=-15) {   // t < 2^(-15) --> res = 1-x2/2
	res = t*t;  
	times2pown(res,-1);
	res = 1 - res;
    } else {
	if (ex>=0) 
	{  // ex>=0 --> t>=0.5; 
	    res = 1-t;   // res: delta = 1-t;
	    t = res * res;
	    times2pown(res,1); // res: 2*delta
	    res = res - t;     // res: 1-x2 = 2*delta - delta2
	} else res = 1-t*t;    // res: Maschinenwert von 1-x2
	res = sqrt(res);       // res: Nullte Naeherung 
    }
    return res;
} // sqrt1mx2
Exemple #7
0
// Fonction calculant le determinant
float determinant(int dim, float M[dim][dim]){
    int colMatrice, j;
    int i = 0;
    float det = 0;
    if(dim == 1){
        return M[0][0];
    }else{
        dim--; // Decrementation de la dimension de la matrice pour le calcul du mineur
        float mineur[dim][dim]; // Le mineur de M

        for(colMatrice = 0; colMatrice < dim + 1; colMatrice++){ // Pour parcourir les colonne de M

            //Construction du mineur de M selon le colonne J
            for (i = 1; i < dim + 1; i++){
                for (j = 0; j < dim + 1; j++){
                    if (j != colMatrice){
                        if (j > colMatrice){
                            mineur[i - 1][j - 1] = M[i][j];
                        }else{
                            mineur[i - 1][j] = M[i][j];
                        }
                    }
                }
            }
            //Expression recursive calculant le determinant
            det = det + expo(-1,colMatrice) * M[0][colMatrice]*determinant(dim, mineur);
        }
        return det;
    }
}
Exemple #8
0
real expx2(const real& x)
// e^(+x^2);  rel. Fehlerschranke:  eps = 4.618958E-16 = e(f) gilt
// fuer alle |x| <= x0 = 26.64174755704632....
// x0 = 7498985273150791.0 / 281474976710656.0;
// Fuer |x| > x0 --> Programmabbruch
// Ausfuehrlich getestet;  Blomquist, 26.07.06;
{
    real t=x,u,v,res;
    int ex;
    if (t<0) t = -t;  // t >= 0;
    ex = expo(t);
    if (ex<=-26) res = 1;  // t < 2^(-26)
    else 
	if (ex<=-6)       // t < 2^(-6)
	{
	    u = t*t;  v = u;
	    times2pown(v,-1);  // v: 0.5*x^2
	    res = 1+u*( 1+v*(1+u/3) );
	} 
	else 
	{
	    sqr2uv(x,u,v);  // u := x*x und v aus S(2,53); 
                            // x^2 = u+v ist exakt!
	    res = exp(u);
	    v *= res;       // v*exp(+u)
	    res += v;
	}
    return res;
} // expx2
Exemple #9
0
Matrice
Matrice::co() const
{
	Matrice m2(n, m, 0);
	Matrice ret(n, m, 0);
	if (n != m) // si pas carré...
	{
		Erreur a(Erreur::ncarre);
		throw(a);
	}
	if (n == 1)
	{
		ret.lignes[0][0] = 1;
	}
	else
	{
		for (unsigned int i = 0;i<n;i++)
			for (unsigned int j = 0;j<n;j++)
			{
				m2 = supligne(*this, i, j);// sous_matrice
				ret.lignes[i][j] = expo(i + j)*m2.det();
			}
	}
	return ret;
}
Exemple #10
0
GEN
addir_sign(GEN x, long sx, GEN y, long sy)
{
  long e, l, ly;
  GEN z;

  if (!sx) return rcopy_sign(y, sy);
  e = expo(y) - expi(x);
  if (!sy)
  {
    if (e >= 0) return rcopy_sign(y, sy);
    z = itor(x, nbits2prec(-e));
    setsigne(z, sx); return z;
  }

  ly = lg(y);
  if (e > 0)
  {
    l = ly - divsBIL(e);
    if (l < 3) return rcopy_sign(y, sy);
  }
  else l = ly + nbits2extraprec(-e);
  z = (GEN)avma;
  y = addrr_sign(itor(x,l), sx, y, sy);
  ly = lg(y); while (ly--) *--z = y[ly];
  avma = (pari_sp)z; return z;
}
Exemple #11
0
real expmx2(const real& x) throw()
// e^(-x^2);  rel. Fehlerschranke:  eps = 4.618919E-16 = e(f) gilt
// fuer alle |x| <= expmx2_x0 = 26.61571750925....
// Fuer |x| > expmx2_x0 --> expmx2(x) = 0;
// Blomquist, 05.07.04;
{ 
    real t=x,u,v,res=0;
    int ex;
    if (t<0) t = -t;  // t >= 0;
    ex = expo(t);
    if (ex<=-26) res = 1;  // t < 2^(-26)
    else if (ex<=-6)       // t < 2^(-6)
    {
	u = t*t;  v = u; 
	times2pown(v,-1);  // v: 0.5*x2
	res = 1-u*( 1-v*(1-u/3) );
    } else if (t<=expmx2_x0) {
	sqr2uv(x,u,v);  // u:= x*x,v aus S(2,53); x2 = u+v (exakt!)
	res = exp(-u); 
	if (v!=0) { 
	    times2pown(res,500);  // Die Skalierung verhindert, dass 
	    v *= res; // v*exp(-u) in den denormalisierten Bereich faellt
	    res -= v;
	    times2pown(res,-500); // Rueckskalierung
	}
    }
    return res;
} // expmx2
Exemple #12
0
static GEN
addsr_sign(long x, GEN y, long sy)
{
  long e, l, ly, sx;
  GEN z;

  if (!x) return rcopy_sign(y, sy);
  if (x < 0) { sx = -1; x = -x; } else sx = 1;
  e = expo(y) - expu(x);
  if (!sy)
  {
    if (e >= 0) return rcopy_sign(y, sy);
    if (sx == -1) x = -x;
    return stor(x, nbits2prec(-e));
  }

  ly = lg(y);
  if (e > 0)
  {
    l = ly - divsBIL(e);
    if (l < 3) return rcopy_sign(y, sy);
  }
  else l = ly + nbits2extraprec(-e);
  z = (GEN)avma;
  y = addrr_sign(stor(x,l), sx, y, sy);
  ly = lg(y); while (ly--) *--z = y[ly];
  avma = (pari_sp)z; return z;
}
int main() {
    int t=scan();
    matrix A;
    A.a1=1;
    A.a2=1;
    A.a3=1;
    A.a4=0;
    A.a5=2;
    A.a6=3;
    A.a7=0;
    A.a8=3;
    A.a9=5;
    while(t--) {
        ll n=0;
        glli(n);
        if(n==0) {
            printf("0\n");
            continue;
        }
        if(n==1) {
            printf("2\n");
            continue;
        }

        matrix tmp=expo(A,n);

        printf("%lld\n",((tmp.a2+tmp.a3)%MOD));
    }
    return 0;
}
int RAIDProcess::msgDelay() {
	RAIDProcessState *myState = (RAIDProcessState*) getState();
	double ldelay;

	// Hard coded for now... add to ssl later
	sourcedist = UNIFORM;
	first = 1;
	second = 2;

	switch (sourcedist) {
	case UNIFORM: {
		Uniform uniform(first, second, myState->getGen());
		ldelay = uniform();
		break;
	}
	case NORMAL: {
		Normal normal(first, second, myState->getGen());
		ldelay = normal();
		break;
	}
	case BINOMIAL: {
		Binomial binomial((int) first, second, myState->getGen());
		ldelay = binomial();
		break;
	}
	case POISSON: {
		Poisson poisson(first, myState->getGen());
		ldelay = poisson();
		break;
	}
	case EXPONENTIAL: {
		NegativeExpntl expo(first, myState->getGen());
		ldelay = expo();
		break;
	}
	case FIXED:
		ldelay = (int) first;
		break;
	default:
		ldelay = 0;
		cerr << "Improper Distribution for a Source Object!!!" << "\n";
		break;
	}
	return ((int) ldelay);

}
Exemple #15
0
int main( void )
{
	int	n = 3;
	
	for (int k = 0; k <= 5; k++)
		printf( "  %d     %d   \n", k, expo( n, k ) );
	printf( "\n" );
}
Exemple #16
0
float euler2(int x) {
	float resp = 0;
	for (int i = 1; i <= 15; i++)
	{
		resp = resp + (expo(x, i) / fatorial(i - 1));
	}
	return resp;

}
lld expo(lld a, lld n, lld p)
{
	if(n==0)
		return 1;
	lld ex=expo(a,n/2,p);
	if(n%2==1)
		return (((ex*ex)%p)*a)%p;
	else
		return (ex*ex)%p;
}
lld expo(lld a, lld n, lld m)
{
	if(n==0)
		return 1;
	lld p=expo(a,n/2,m);
	if(n%2==0)
		return (p*p)%m;
	else
		return (((p*p)%m)*a)%m;
}
Exemple #19
0
int expo(int base,int x,int y) {
	int x_,y_,xp;
	x_ = mod(x,base);
	y_ = mod(y,base);
	if (y_ == 0) return 1;
	xp = expo(base,x_,y_/2);
	if (y_ % 2 == 0) {
		return mod(xp * xp,base);
	}
	return mod(x_ * xp * xp,base);
}
matrix expo(matrix B,ll n) {
    if(n==1) {
        return B;
    }
    matrix C=expo(B,n/2);
    C=multiply(C,C);
    if(n%2==1) {
        return multiply(B,C);
    }
    return C;
}
Exemple #21
0
double
expo (void)
{
  double e;
  e = factor ();
  if (ch == '^')
    {
      next;
      e = pow (e, expo ());
    }
  return e;
}
/* This function converts the strings to integers */
int string_to_integer(char *s){
  int expn;          /* The power of 10 with which to multiply values */
  int len_temp;      /* To temporarily store length value */
  int num_temp;      /* To temporarily store the number */
  int i = 0;         /* Counter integer for conversion loop */
  int j = 0;         /* Counter integer for the -vity loop */
  int neg = 1;       /* To capture the -vity or +vity */
  int total = 0;     /* Where the numbers get added to get the actual
                        numerical values*/

  len_temp = length_of_number(s);  /* Call to function for length */
  /* for ridiculously long numbers */
  if(len_temp > 10){
    return 0;
  }
  expn = expo(len_temp);           /* Call to function for exponent */

  /* Loop to determine +vity or -vity */
  while(*(s + j) != '\0'){
    if(*(s + j) == '-'){
      if(*(s + (j + 1)) > '9' || *(s + (j + 1)) < '0'){
        /* To stop the search for numbers in the string */
        break;
      }
      neg *= -1;
    }
    j++;
  }

  while(*(s + i) != '\0'){
    /* Assign the value of (s + i) to an int variable */
    num_temp = *(s + i) - 48;
    if(num_temp >=0 && num_temp <= 9){
      num_temp *= expn;          /* Multiply by expn so that if the number
                                    is 9 then it becomes 90 (for string '98')*/
      expn /= 10;                /* Divide the exponent by 10 so that the
                                    next number (8 in string '98) is
                                    only multiplied by 1 */
      /* To check if the number is going to be greater than an int
         can hold */
      if(total == 2147483640 && num_temp > 7 && neg == 1){
        return 0;
      }
      total += num_temp;         /* Add the value to total */

    }
    i++;                         /* Increase the counter */
  }

  total *= neg;                   /* To convert the number to -ve */
  return total;
}
Exemple #23
0
double exponential (double k)
{
	int n;								/*n es el contador de tÈrminos*/
	double f;							/*f es el valor del tÈrmino*/
	for (n=0;n<15;n++)				/*se aproximar· hasta el tÈrmino 15*/
	{
		double c= expo(k,n);			/*se eleva la base x al exponente n*/
		long d= fact(n);				/*se busca el factorial n*/
		double t= divt (c,d);			/*se dividen los resultados previos*/
		f=f+t;							/*se van sumando los tÈrminos sucesivos*/
	}
	return f;
}
Exemple #24
0
real sqrtp1m1(const real& x) throw()
// sqrtp1m1(x) = sqrt(x+1)-1;
// Blomquist, 05.08.03; 
{
    real y = x;
    int ex = expo(x);
    if (ex<=-50) times2pown(y,-1);  // |x|<2^(-50); fast division by 2 
    else if (ex>=105) y = sqrt(x);  // x >= 2^(+104) = 2.02824...e+31
    else if (ex>=53) y = sqrt(x)-1; // x >= 2^(+52)  = 4.50359...e+15
    else if (x>-0.5234375 && x<=sqrtp1m1_s ) y = x / (sqrt(x+1) + 1);
    else y = sqrt(x+1)-1;
    return y;
}
Exemple #25
0
int _tmain(int argc, _TCHAR* argv[])
{
	float a = fatorial(4);
	printf("Fatorial: %f", a);
	float b = euler();
	printf("\nEuler: %f", b);
	float c = euler2(2);
	printf("\nEuler 2: %f", c);
	float d = expo(4, 3);
	printf("\nExpo: %f", d);
	printf("\n\n");
	return 0;
}
Exemple #26
0
bool AutoCorrection::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    int type = settings()["AutoCorrectionFilter"].toInt();

    switch (type)
    {
        case AutoLevelsCorrection:
        {
            AutoLevelsFilter autolevels(&image(), &image());
            autolevels.startFilterDirectly();
            image().putImageData(autolevels.getTargetImage().bits());
            break;
        }
        case NormalizeCorrection:
        {
            NormalizeFilter normalize(&image(), &image());
            normalize.startFilterDirectly();
            image().putImageData(normalize.getTargetImage().bits());
            break;
        }
        case EqualizeCorrection:
        {
            EqualizeFilter equalize(&image(), &image());
            equalize.startFilterDirectly();
            image().putImageData(equalize.getTargetImage().bits());
            break;
        }
        case StretchContrastCorrection:
        {
            StretchFilter stretch(&image(), &image());
            stretch.startFilterDirectly();
            image().putImageData(stretch.getTargetImage().bits());
            break;
        }
        case AutoExposureCorrection:
        {
            AutoExpoFilter expo(&image(), &image());
            expo.startFilterDirectly();
            image().putImageData(expo.getTargetImage().bits());
            break;
        }
    }

    return (savefromDImg());
}
Exemple #27
0
double
term (void)
{
  double t;
  t = expo ();
  for (;;)
    switch (ch)
      {
      case '*':
	next;
	t *= expo ();
	break;
      case '/':
	next;
	t /= expo ();
	break;
      case '%':
	next;
	t = fmod (t, expo ());
	break;
      default:
	return t;
      }
}
Exemple #28
0
void T_inicializa(int tam_pagina){

	long int tam_p_bytes = tam_pagina*1024;
	int num_bits = Log2( tam_p_bytes);
	int num_bits_tabela = 32-num_bits;
	int i;
	long int tamanho_tabela;
	tamanho_tabela = expo(2 , num_bits_tabela);

	TABELA_PAGINA = (int*)malloc(sizeof(int) * tamanho_tabela);

	for(i=0;i<tamanho_tabela;i++)
		TABELA_PAGINA[i] = -1;

}
bool miller_rabin(lld n, lld a)
{
	if(n==2)
		return true;
	/*let n be the test value and 2<=a<=n-1. I find n-1=2^s*d. (a^d)%n=+1 or -1, return true; else check for (a^(2^i*d))%n=-1 for atleast one 2<=i<=s-1. If yes return true.*/
	  
	lld s,d,test;
	if(a>n-1)
		return true;
	d=n-1;
	s=0;
	while(d%2==0)
		s++, d=d/2;
	test=expo(a,d,n);
	if(test==1 || test==n-1)
		return true;
	while(s--)
	{
		test=expo(a,(1<<s)*d,n);
		if(test==n-1)
			return true;
	}
	return false;
}
int string_to_integer (char *s)
{
  int i;
  int number = 1;    
  int l;  
  int e; 
  int n; 
  int tmp = 0; 
  /*holds the length of the number*/
  l = length(s);
   if(l > 10)
    {
      return 0; 
    }
  /*Holds the power of the number*/
  e = expo(l);
   for (i = 0 ; s[i]; i++)
    {
      /*Converts the numbert to a digit*/
       number = (s[i] - 48);
      /*checks if the number is between the numeric values*/ 
      if (number >= 0 && number <= 9)
	{ 
    	  /*Increases number by its power*/
	  number = number * e;
	  /*reduces the power by 10*/
	  e = e/10 ; 
	  /*Checks for numbers bigger that the INT_MAX*/
	  if (tmp == 2147483640 && number > 7 && negative(s) != -1)
	    {
	      return 0 ; 
	    }
	  number += tmp;
	  /*Temporary stores the value of the number so that it can change and latter by added to itself*/
	  tmp = number;
	  /*checks for space after each number*/
	  if (s[i +1] == ' ')
            {
	      n = negative (s);
	      number *= n;
              break;
	    }  
	}
    }
  n = negative (s); 
  number *= n;
 return  number; 
}