示例#1
0
文件: evalf.cpp 项目: mulab/mU
var Evalf(Var x, size_t y)
{
	size_t z = mpf_get_default_prec();
	mpf_set_default_prec((uint)(LOG_2_10 * y));
	var r = Evalf(x);
	mpf_set_default_prec(z);
	if(FltQ(r)) mpf_set_prec(CFlt(r),(uint)(LOG_2_10 * y));
	return r;
}
示例#2
0
文件: hilbert.c 项目: blynn/pbc
static void precision_init(int prec) {
  int i;
  mpf_t f0;

  mpf_set_default_prec(prec);
  mpf_init2(epsilon, 2);
  mpf_init2(negepsilon, 2);
  mpf_init(recipeulere);
  mpf_init(pi);
  mpf_init(eulere);

  mpf_set_ui(epsilon, 1);
  mpf_div_2exp(epsilon, epsilon, prec);
  mpf_neg(negepsilon, epsilon);

  mpf_init(f0);
  mpf_set_ui(eulere, 1);
  mpf_set_ui(f0, 1);
  for (i=1;; i++) {
    mpf_div_ui(f0, f0, i);
    if (mpf_cmp(f0, epsilon) < 0) {
      break;
    }
    mpf_add(eulere, eulere, f0);
  }
  mpf_clear(f0);

  mpf_ui_div(recipeulere, 1, eulere);

  compute_pi(prec);
}
示例#3
0
文件: t-get_d.c 项目: AllardJ/Tomato
void
test_denorms (int prc)
{
#ifdef _GMP_IEEE_FLOATS
  double d1, d2;
  mpf_t f;
  int i;

  mpf_set_default_prec (prc);

  mpf_init (f);

  d1 = 1.9;
  for (i = 0; i < 820; i++)
    {
      mpf_set_d (f, d1);
      d2 = mpf_get_d (f);
      if (d1 != d2)
        abort ();
      d1 *= 0.4;
    }

  mpf_clear (f);
#endif
}
示例#4
0
int main(int argc, char **argv)
{
	unsigned bits;
	double start, end;
	mpf_t e;
	
	if(argc < 2) {
		usage(argv);
	}
	bits = atoi(argv[1]);
	if(bits == 0) {
		usage(argv);
	}
	
	printf("Calculating e...");
	fflush(stdout);
	
	start = currentTime();
	
	mpf_set_default_prec(bits);
	mpf_init(e);
	
	calculateE(bits, e);
	
	end = currentTime();
	
	printf("\ne = ");
	mpf_out_str(stdout, 10, 0, e);
	printf("\n");
	printf("total elapsed time : %.2f seconds\n", end - start);
	return 0;
}
示例#5
0
int main(int argc, char** argv[]) {
    NLSystemContext ctx;
    bool inBounds;
    uint32 i;

    //Set default precision for GNU MP:
    mpf_set_default_prec(256);

    //Initialize our bigFloat arrays:
    initArray(state, in_systemVars, 39);
    initArray(minBounds, in_minBounds, 39);
    initArray(maxBounds, in_maxBounds, 39);

    //Initialize our NLSystemContext:
    initNLSystemContext(&ctx, state, minBounds, maxBounds, 39);

    //Run the main non-linear function:
    Jianmin(&ctx);

    //Check to make sure the system stayed within constraints:
    inBounds = checkBounds(&ctx, 39);

    if(inBounds == false) {
        printf("\nThe system strayed outside of its constraints! Please check your math.\n");
    }
    
    //free up the memory GNU MP allocated behind the scenes:
    clearArray(state, 39);
    clearArray(minBounds, 39);
    clearArray(maxBounds, 39);

    return 0;
}
示例#6
0
int libgretl_mpi_init (int self, int np, int dcmt)
{
    int err;

    libset_init();

    /* let geneval know */
    set_mpi_rank_and_size(self, np);

    /* load MPI library functions */
    err = gretl_MPI_init();
    if (err) {
	return err;
    }

    if (dcmt && np > 1) {
	/* use DCMT for multiple RNGs */
	gretl_dcmt_init(np, self, 4172);
    } else {
	/* just use one RNG */
	gretl_rand_init();
    }

    gretl_xml_init();
    gretl_stopwatch_init();
    mpf_set_default_prec(get_mp_bits());

    /* be relatively quiet by default */
    set_gretl_echo(0);
    set_gretl_messages(0);

    return 0;
}
示例#7
0
文件: mp-topsin.c 项目: linas/anant
int main (int argc, char * argv[])
{
    mpf_t a_k;
    int prec, nbits;

    prec = 120;

    /* Set the precision (number of binary bits) */
    /* We need more bits than what what is available, for intermediate calcs */
    nbits = 3.3*prec;
    mpf_set_default_prec (nbits+200);

    mpf_init(a_k);

    printf("#\n# The topsin series a_k\n#\n");

    int k;
    double akprev=0.0;
    for (k=0; k<95001; k++)
    {
        topsin_series(a_k, k, prec);
        double ak = mpf_get_d(a_k);

        printf("%d	%20.16g	%20.16g\n", k, ak, ak+akprev);
        akprev = ak;
    }

    return 0;
}
示例#8
0
int main ( int argc, const char *argv[] ) {

    mpf_set_default_prec ( 65536 );

    try {

        std::cin.imbue ( std::locale ( std::locale(), new cf_reader ) );

        const std::string mixed ( argc > 1 ? argv[1] : "" );

        const Commons::Math::gmp_rational &r ( Commons::Math::cf (
                std::istream_iterator<Commons::Math::gmp_rational::integer_type> ( std::cin ),
                std::istream_iterator<Commons::Math::gmp_rational::integer_type>() ) );

        if ( mixed == "-m" || mixed == "--mixed" ) {

            std::string ms ( r.str ( true ) );
            std::cout << ms.replace ( ms.find_first_of ( ' ' ), 1u, "+" ) << std::endl;

        } else {
            std::cout << r << std::endl;
        }

    } catch ( const std::exception &e ) {
        std::cerr << "Error: " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
int main(void)
{
    mpf_set_default_prec(300000);
    mpf_class x0, y0, resA, resB, Z;

    x0 = 1;
    y0 = 0.5;
    Z  = 0.25;
    mpf_sqrt(y0.get_mpf_t(), y0.get_mpf_t());

    int n = 1;
    for (int i = 0; i < 8; i++) {
        agm(resA, resB, x0, y0);
        Z -= n * (resA - x0) * (resA - x0);
        n *= 2;

        agm(x0, y0, resA, resB);
        Z -= n * (x0 - resA) * (x0 - resA);
        n *= 2;
    }

    x0 = x0 * x0 / Z;
    gmp_printf ("%.100000Ff\n", x0.get_mpf_t());
    return 0;
}
示例#10
0
int main (void) {
	mpf_set_default_prec (300000);
	mpf_t x0, y0, resA, resB, Z, var;

	mpf_init_set_ui (x0, 1);
	mpf_init_set_d (y0, 0.5);
	mpf_sqrt (y0, y0);
	mpf_init (resA);
	mpf_init (resB);
	mpf_init_set_d (Z, 0.25);
	mpf_init (var);

	int n = 1;
	for(int i=0; i<8; i++){
		agm(x0, y0, resA, resB);
		mpf_sub(var, resA, x0);
		mpf_mul(var, var, var);
		mpf_mul_ui(var, var, n);
		mpf_sub(Z, Z, var);
		n += n;
		agm(resA, resB, x0, y0);
		mpf_sub(var, x0, resA);
		mpf_mul(var, var, var);
		mpf_mul_ui(var, var, n);
		mpf_sub(Z, Z, var);
		n += n;
	}
	mpf_mul(x0, x0, x0);
	mpf_div(x0, x0, Z);
	gmp_printf ("%.100000Ff\n", x0);
	return 0;
}
示例#11
0
pade_interpolator::pade_interpolator(const alps::params &p){
  pade_mu_=p["PADE_NUMERATOR_DEGREE"];
  pade_nu_=p["PADE_DENOMINATOR_DEGREE"];
  if(pade_mu_+pade_nu_ +1 != p["NDAT"]) throw std::runtime_error("Ill defined interpolation: please make sure that numerator degree + denominator degree + 1 = # of data points");
  mpf_set_default_prec(p["FLOAT_PRECISION"]|256);
  find_epsilon();
}
示例#12
0
int main( int argc, char** argv )
{
    unsigned bits;
    double start, end;

    if ( argc < 2 ) {
        usage( argv );
    }
    bits = atoi( argv[1] );
    if ( bits == 0 ) {
        usage( argv );
    }

    printf( "Calculating pi..." );
    fflush( stdout );

    start = currentTime( );

    mpf_set_default_prec( bits );
    mpf_class pi;

    calculatePi( bits, pi );

    end = currentTime( );

    printf( "\npi = " );
    mpf_out_str( stdout, 10, 0, pi.get_mpf_t( ) );
    printf( "\n" );
    printf( "total elapsed time : %.2f seconds\n", end - start );
    return 0;
}
示例#13
0
void KNumber::setDefaultFloatPrecision(unsigned int prec)
{
  // Need to transform decimal digits into binary digits
  unsigned long int bin_prec = static_cast<unsigned long int>
    (double(prec) * M_LN10 / M_LN2 + 1);

  mpf_set_default_prec(bin_prec);
}
示例#14
0
void libgretl_init (void)
{
    libset_init();
    gretl_rand_init();
    gretl_xml_init();
    gretl_stopwatch_init();
    mpf_set_default_prec(get_mp_bits());
}
示例#15
0
文件: misc.c 项目: aliddell/cadenza
void setPrec(int prec)
/***************************************************************\
* USAGE: set default precision                                  *
\***************************************************************/
{
  mpf_set_default_prec(prec);

  return;
}
示例#16
0
/* Constructor and destructor for Lambda fractal. */
static lambda_t* constructor_lambda(const ordinal_number_t iteration_steps, long long int prec, const char args[])
{
	lambda_t* context;
	char*     real_param;
	char*     imaginary_param;
	char*     args_help;
	
	/* Get memory for the fractal context. */
	if (!(context=malloc(sizeof(lambda_t)))) return NULL;

	mpf_set_default_prec(sizeof(char)*prec);

	mpf_init(Re(context->lambda));
	mpf_init(Im(context->lambda));

	/* Set the fractal context. */
	context->iteration_steps=iteration_steps;
	
	if(args!=NULL)
	{
		if (strchr(args, ',')==NULL)
		{
			real_param=malloc(sizeof(char)*(prec+1));	
			sscanf(args,"%s",real_param);
			mpf_set_str(Re(context->lambda),real_param,10);
			mpf_set_str(Im(context->lambda),"0",10);
			free(real_param);
		}
		else
		{
			args_help=malloc(sizeof(args));
			strcpy(args_help,args);
			real_param=strtok(args_help,",");
			imaginary_param=strtok(NULL,"\0");

			mpf_set_str(Re(context->lambda),real_param,10);
			mpf_set_str(Im(context->lambda),imaginary_param,10);
			free(args_help);
		}
	}
	else
	{
		mpf_set_si(Re(context->lambda),1);
		mpf_set_si(Im(context->lambda),0);
	}

	context->prec=prec;

 	#ifdef DEBUG 
	gmp_fprintf(stderr,"Lambda parameter: %F.10f,%F.10f\n",Re(context->lambda),Im(context->lambda));
	#endif

	/* Return the handle. */
	return context;
}
void gmp_monte_carlo_par (int numthr, int numpts)
{
/*Para realizar o metodo Monte Carlo foi utilizado uma circunferencia
de raio igual a 1 (para facilitar a comparacao que verifica se o ponto
esta dentro da circunferencia) inscrita em uma quadrado de lado igual a 2.
Foi considerado apenas o primeiro quadrante, pois assim as coordenadas dos
pontos variam de 0 a 1. */
    int i =0;
    mpf_t pi;
    mpf_t intern_points, total_points, ratio;
    pthread_t tabela_thr[1000];

    /*Variavel que armazena quantos pontos vao ficar dentro da circunferencia*/

    /*A precisao padrao sera no minimo 10.000.000*log10.*/
    mpf_set_default_prec (34000000);
	

    /*O objeto mpf_t deve ser inicializado antes de receber algum valor.*/
    mpf_init(pi),mpf_init(intern_points),mpf_init(total_points),mpf_init(ratio);
	
	
    /* Inicializa a semente para calcular o valor aleatorio*/
    srand (time(NULL));
	/* Para uma quantidade de quase 1 bi de pontos*/
	i=0;
	if(numthr>1000) numthr=1000;
	while(i<numthr)
	{
	  //printf("\nIniciando Thread: %d", i);
	  mpf_init(param[i].intern_points);
	  mpf_init(param[i].total_points);
	  param[i].numpoints=numpts;
	  pthread_create(&tabela_thr[i], NULL, (void*)&montecarlo_thr, (void*) & param[i]);
	  i++;
	}
	i=0;
	while(i<numthr){
	  pthread_join(tabela_thr[i], NULL);
	  mpf_add(intern_points,intern_points,param[i].intern_points);
	  mpf_add(total_points,total_points,param[i].total_points);
	  i++;
	}
	
	/*calculando o valor de pi
        pi = 4* (double) intern_points /total_points */

	mpf_div (ratio,intern_points,total_points);  /*ratio = intern_points / total_points*/
	mpf_mul_ui (pi,ratio,4);                 /* pi = 4*ratio*/
	mpf_out_str (stdout,10,10000000,pi);
     
}
示例#18
0
文件: my.c 项目: macroxue/const-pi
void my_out_str_raw(FILE *fp, unsigned long digits, mpf_t f, unsigned long offset)
{
    unsigned long d;

    if (digits <= LINE_SIZE*NUM_BLOCKS) {
        unsigned long cursor = offset % LINE_SIZE;
        for (d = 0; d < digits; ) {
            mpf_set_prec_raw(f, (int)((digits-d)*BITS_PER_DIGIT+1));
            mpf_mul_ui(f, f, UNIT_MOD);
            unsigned long i = mpf_get_ui(f);
            mpf_sub_ui(f, f, i);

            utoa(i, UNIT_SIZE);
            *out_ptr++ = ' ';
            d += UNIT_SIZE;
            cursor += UNIT_SIZE;
            if (cursor == LINE_SIZE) {
                cursor = 0;
                *out_ptr++ = ':';
                *out_ptr++ = ' ';
                utoa(offset + d, 0);
                *out_ptr++ = '\n';
                if ((offset + d) % (LINE_SIZE*10) == 0)
                    flush_out(fp);
            }
        }
    } else {
        mpf_t block, mod;
        unsigned long num_units = (digits + UNIT_SIZE-1)/UNIT_SIZE;
        unsigned long block_size =  (num_units + NUM_BLOCKS-1)/NUM_BLOCKS*UNIT_SIZE;
        mpf_set_default_prec((int)(block_size*BITS_PER_DIGIT+1));
        mpf_init(block);
        mpf_init_set_ui(mod, 10);
        mpf_pow_ui(mod, mod, block_size);

        for (d = 0; d < digits; d += block_size) {
            unsigned long size = block_size < digits - d ? block_size : digits - d;
            mpf_set_prec_raw(block, (int)(size*BITS_PER_DIGIT+1));
            mpf_set(block, f);
            my_out_str_raw(fp, size, block, offset+d);
            if (block_size < digits - d) {
                mpf_set_prec_raw(f, (int)((digits-d)*BITS_PER_DIGIT+1));
                mpf_mul(f, f, mod);
                mpf_floor(trunk, f);
                mpf_sub(f, f, trunk);
            }
        }
        mpf_clear(block);
        mpf_clear(mod);
    }
}
示例#19
0
/* New calculate function. */
ordinal_number_t cache_calculator(render_t* handle,const view_position_t render_position)
{
	/* Volatile data. */
	ordinal_number_t* help;
	complex_number_t  complex_position;
	view_position_t   shift;
	real_number_t     scaling_factor;
	mpf_t             help_mpf;
	mpf_t             help_two;

	mpf_set_default_prec(sizeof(char)*handle->prec);
	mpf_init(help_mpf);
	mpf_init(Re(complex_position));
	mpf_init(Im(complex_position));
	mpf_init(scaling_factor);
	mpf_init(help_two);

	/* Check if the point has been calculated already. */
	help=handle->points+render_position.y*handle->geometry.width+render_position.x;
	if(*help==0)
	{
		/* Has not been calculated till now, calculate the iteration. */

		/* Precalculate scaling factor and center shift for speed reasons. */
		mpf_div_ui(scaling_factor,handle->scale,handle->geometry.width);
		shift.x=handle->geometry.width/2;
		shift.y=handle->geometry.height/2;

		/* Calculate the iteration. */
		mpf_set_si(help_two,(render_position.x-shift.x));
		mpf_mul(help_mpf,scaling_factor,help_two);
		mpf_add(complex_position.real_part,help_mpf,handle->center.real_part);

		mpf_set_si(help_two,(render_position.y-shift.y));
		mpf_mul(help_mpf,scaling_factor,help_two);
		mpf_sub(Im(complex_position),Im(handle->center),help_mpf);

		*help=(*handle->fractal_facility->facility.fractal.calculate_function)(handle->fractal,&complex_position);
	}

	mpf_clear(help_mpf);
	mpf_clear(Re(complex_position));
	mpf_clear(Im(complex_position));
	mpf_clear(scaling_factor);
	mpf_clear(help_two);
	

	/* Return the iteration. */
	return(*help);
	//return(0);
}
int main(int argc, char **argv)
{

	int d = 20; //dokladnosc
	int n = 0; //ilosc liczb
	int p = 1; //okres

	if(argc > 1)
	{
		d = atoi(argv[1]);
	}
	double bits_per_digit = 3.32192809488736234789; //log2(10)
	//mpf_set_default_prec((21+d)*bits_per_digit + 1);
	//bo d dotyczy tego co po kropce, a z przodu moze byc jeszcze jakies ok. 20 cyfr dla 2^64
	//a jednak wincyj niz 20, jak w wariancji w przykladzie 4, jest jakies 40 przed kropka..
	//no i jak to oszacowac? moze po prostu od razu 100, po co sie rozdrabniac?
	mpf_set_default_prec((100+d)*bits_per_digit + 1);

	std::string sxn;
	mpf_class xn;xn = 0;
	mpf_class xn_sum; xn_sum = 0;
	mpf_class xn_2sum; xn_2sum = 0;

	std::vector<float> XXX;
	float closeInaf;
	while(std::cin >> sxn)
	{
		xn = sxn;
		xn_sum += xn;
		xn_2sum += (xn*xn);
		closeInaf = (float)xn.get_d();
		XXX.push_back(closeInaf);
		if(n!= 0 && XXX[n-p] != closeInaf)
		{
			p++;
		}
		n+=1;
	}

	mpf_class avg = xn_sum / n;
	mpf_class vari = (xn_2sum / n) - avg*avg;

	std::cout.setf(std::ios_base::fixed);

	std::cout << fixed(avg, d) << std::endl;
	//std::cout << avg.get_str(exp, 10, (size_t)d) << std::endl;
	std::cout << fixed(vari, d) << std::endl;
	std::cout << p << "\n";
	return 0;
}
示例#21
0
/* Constructor and destructor for recurse render function. */
static render_t* constructor(
		const complex_number_t   center,
		const view_dimension_t   geometry,
		const real_number_t      scale,
		const plugin_facility_t* fractal_facility,
		const plugin_facility_t* output_facility,
		const void*              fractal,
		const void*              output,
		const char               args[],
		long long int            prec)
{
	render_t*        context;

	/* Check if parameter was given, */
	if(args==NULL)
	{
		fprintf(stderr,"You have to specify render parameters\n");
		exit(EXIT_FAILURE);
	}

	#ifdef DEBUG
	fprintf(stderr,"Render parameter is: %s\n",args);
	#endif
	
	/* Get memory for the fractal context. */
	if (!(context=malloc(sizeof(render_t)))) return NULL;

	
	VARCOPY(context->prec,prec);
	mpf_set_default_prec(sizeof(char)*prec);
	
		
	/* Set the fractal context. */
	mpf_init(context->center.real_part);
	mpf_init(context->center.imaginary_part);
	mpf_init(context->scale);

	mpf_set(context->center.real_part,Re(center));
	mpf_set(context->center.imaginary_part,Im(center));
	VARCOPY(context->geometry,geometry);
	mpf_set(context->scale,scale);
	VARCOPY(context->fractal_facility,fractal_facility);
	VARCOPY(context->output_facility,output_facility);
	VARCOPY(context->fractal,fractal);
	VARCOPY(context->output,output);
	sscanf(args,"%d", &context->param);

	/* Return the handle. */
	return context;
}
示例#22
0
int main (int argc, char *argv[]) {
    mpf_t sq_me, sq_out, test;
    mpf_set_default_prec (10000);
    mpf_init(sq_me);
    mpf_init(sq_out);
    mpf_init(test);
    mpf_set_str (sq_me, argv[1], 10);

    mpf_sqrt(sq_out, sq_me);
    mpf_mul(test,sq_out,sq_out);

    gmp_printf ("Input:       %Ff\n\n", sq_me);
    gmp_printf ("Square root: %.200Ff\n\n", sq_out);
    gmp_printf ("Re-squared:  %Ff\n\n", test);

    return 0;
}
示例#23
0
// The Brent-Salamin algorithm
int main(int argc, char* argv[]) {
  if (argc < 2) return -1;
  int n = (int)strtol(argv[1], NULL, 10);
  mpf_set_default_prec(1000);
  mpf_t a, b, t, c, sum;
  // a=1
  mpf_init_set_ui(a, 1);
  mpf_init_set_ui(sum, 0);
  mpf_init(b);
  mpf_init(t);
  mpf_init(c);
  mpf_init(sum);

  // b=1/sqrt(2)
  mpf_sqrt_ui(b, 2);
  mpf_ui_div(b, 1, b);

  // n次迭代的误差小于\frac{2^{n+9}}{20^{2n+1}}
  for (int i = 1; i <= n; ++i) {
    // t=(a+b)/2
    mpf_add(t, a, b);
    mpf_div_ui(t, t, 2);
    // b=sqrt(a*b);
    mpf_mul(b, a, b);
    mpf_sqrt(b, b);
    // a=t
    mpf_swap(t, a);
    mpf_mul(t, a, a);
    mpf_mul(c, b, b);
    mpf_sub(c, t, c);
    mpf_mul_2exp(c, c, i + 1);
    mpf_add(sum, sum, c);
  }
  mpf_mul(t, a, a);
  mpf_mul_ui(t, t, 4);
  mpf_ui_sub(sum, 1, sum);
  mpf_div(t, t, sum);
  mpf_out_str(stdout, 10, 0, t);
  printf("\n");
  mpf_clear(a);
  mpf_clear(b);
  mpf_clear(t);
  mpf_clear(c);
  mpf_clear(sum);
  return 0;
}
示例#24
0
文件: pi.c 项目: Karikaturist/WPC
int main(void) {


  int i ;
  char buf[4096] ;
  mpf_t x, y , result ;
  mpf_set_default_prec(LIMIT);
  mpf_init ( x );
  mpf_init ( y );
  mpf_init (result) ;




   mpf_set_str(result, "1" , 10 );

   for ( i = 1 ; i < LIMIT ; i++ ) {
     sprintf ( buf , "%d" , (2*i + 1) ) ;
     mpf_set_str(x, buf , 10 );
     mpf_ui_div (y, 1, x) ;
     if ( i % 2 ) {
       mpf_sub ( x , result , y ) ;
       mpf_set (result , x) ;
     }
     else {
       mpf_add ( x , result , y ) ;
       mpf_set (result , x) ;
     }
   }

   mpf_mul_ui (x, result, 4 )  ;


   printf("\n pi = " ) ;
   mpf_out_str (stdout , 10, 0, x) ;
   printf ("\n") ;


   mpf_clear (x);
   mpf_clear (y);
   mpf_clear (result);

   return EXIT_SUCCESS;

}
int main(void)
{
	clock_t begin, end;
	mpf_set_default_prec(BITS_PER_DIGIT*DIGITS);
	//mpf_set_default_prec(4096);
	begin = clock();
	mpf_init(x);
	mpf_init(y);
	mpf_init(p);
	mpf_init(aux1);
	mpf_init(aux2);
	mpf_init(sqrtx);
	mpf_init(invsqrtx);
	/* x = sqrt(2)*/
	mpf_set_ui(x, 2);
	mpf_sqrt(x, x);
	/* y = sqrt(sqrt(2)) = sqrt(x)*/
	mpf_sqrt(y, x);
	/* p = 2 + sqrt(2) = 2 + x*/
	mpf_add_ui(p, x, 2);
	for (i=0; i<24; i++)
	{
		mpf_sqrt(sqrtx, x);
		mpf_ui_div(invsqrtx, 1, sqrtx);
		pthread_create(&t1, NULL, thread1, NULL);
		pthread_create(&t2, NULL, thread2, NULL);
		pthread_join(t1, NULL);
		pthread_join(t2, NULL);
		mpf_div(p, aux1, aux2);
        
        //Para ver os valores de pi a cada iteracao
        //mpf_out_str(stdout, 10, DIGITS, p);
	}
	mpf_out_str(stdout, 10, DIGITS, p);
	mpf_clear(x);
	mpf_clear(y);
	mpf_clear(p);
	mpf_clear(aux1);
	mpf_clear(aux2);
	mpf_clear(sqrtx);
	mpf_clear(invsqrtx);
	end = clock();
	printf("Took %lfs\n", (double)(end-begin)/CLOCKS_PER_SEC);
	pthread_exit(0);
}
示例#26
0
int main(int argc,char *argv[])
{
    mpf_t mpfVal,mpf1;
    unsigned long i;

    mpf_set_default_prec(9000);
    mpf_init_set_ui(mpf1,1);
    printf ("%ld\n",mpf_get_default_prec());

    for (i=997; i>=997; i--) {
        mpf_init(mpfVal);
        mpf_div_ui(mpfVal,mpf1,i);
        printf("%ld: ",i);
        (void) mpf_out_str(stdout,10,2000,mpfVal);

        mpf_clear(mpfVal);
    }
}
示例#27
0
文件: mp-topsin.c 项目: linas/anant
int main (int argc, char * argv[])
{
    mpf_t a_k;
    int prec, nbits;

    prec = 50;

    /* Set the precision (number of binary bits) */
    /* We need more bits than what what is available, for intermediate calcs */
    nbits = 3.3*prec;
    mpf_set_default_prec (nbits+200);

    mpf_init(a_k);

    // a_1 should be -2pi
    topsin_series(a_k, 1, prec);
    double twopi = mpf_get_d(a_k);
    twopi += 2.0*M_PI;
    if (fabs(twopi) > 1.0e-16) printf("Error  at k=1: %g\n", twopi);

    // a_2 should be +2pi
    topsin_series(a_k, 2, prec);
    twopi = mpf_get_d(a_k);
    twopi -= 2.0*M_PI;
    if (fabs(twopi) > 1.0e-16) printf("Error  at k=2: %g\n", twopi);

    // a_3 should be 2pi (3-2pi^2) / 3 = -35.05851693322

    double x;
    bool fail = false;
    for (x=0.95; x>-0.95; x -= 0.018756)
    {
        bool result = sum_test(x, prec);
        fail = fail || result;
        printf(".");
        fflush(stdout);
    }
    printf("\n");

    if (fail) printf("Error: test failed\n");
    else printf("Success: test worked\n");

    return 0;
}
int main (void) {
	mpf_set_default_prec (65568);
	mpf_t x0, y0, resA, resB;

	mpf_init_set_ui (y0, 1);
	mpf_init_set_d (x0, 0.5);
	mpf_sqrt (x0, x0);
	mpf_init (resA);
	mpf_init (resB);

	for(int i=0; i<7; i++){
		agm(x0, y0, resA, resB);
		agm(resA, resB, x0, y0);
	}
	gmp_printf ("%.20000Ff\n", x0);
	gmp_printf ("%.20000Ff\n\n", y0);

	return 0;
}
/**
 * void initAttributes()
 * 
 * Descricao:
 * 	Inicializa as variaveis globas e atribui os valores iniciais necessarios para a execucao do algoritmo
 * 	Gauss-Legendre.
 * 
 * Parametros de entrada:
 * 	-
 * 
 * Parametros de retorno:
 * 	-
 */
void initAttributes(){
  
  /* Atribui como precisao default 10 milhoes de casas decimais. A funcao mpf_set_default_prec() tem como parametro de entrada
   * a precisao desejada em bits, ou seja, e necessario utilizar a conversao (log de 2 na base 10)*10 milhoes para obter o valor correto. */
  mpf_set_default_prec((log(10)/log(2))*10000000);

  int i;
  mpf_t sqrt2; 	// Variavel auxiliar para o calculo de b0    
  mpf_t b0;  	// Variavel auxiliar para o calculo de b0
  
  n_count = 0;

  /* Arrays de variaveis utilizadas pelo algoritmo. Como o algoritmo converge para o valor correto do "pi" com 45 milhoes de casas decimais
   * em apenas 25 iteracoes, serao utilizado arrays com 25 posicoes */
  a_n = (mpf_t*) malloc(25*sizeof(mpf_t));
  b_n = (mpf_t*) malloc(25*sizeof(mpf_t));
  t_n = (mpf_t*) malloc(25*sizeof(mpf_t));
  p_n = (mpf_t*) malloc(25*sizeof(mpf_t));
  pi = (mpf_t*) malloc(25*sizeof(mpf_t));  
  
  for(i=0; i<25; i++){
    mpf_init(a_n[i]);
    mpf_init(b_n[i]);
    mpf_init(p_n[i]);
    mpf_init(t_n[i]);
    mpf_init(pi[i]);    
  }
  
  /* Atribuicao dos valores iniciais */
  mpf_init(sqrt2);
  mpf_init(b0);
  mpf_sqrt_ui(sqrt2, 2);
  mpf_ui_div(b0, 1, sqrt2);  
  
  mpf_set_d(a_n[n_count], 1.0);
  mpf_set(b_n[n_count], b0);
  mpf_set_d(t_n[n_count], 0.25);
  mpf_set_d(p_n[n_count], 1.0);
  
}
示例#30
0
	FractalTexture::FractalTexture()
#ifndef ROE_FRACTAL_GMP_USE_C
	: m_xUpLt(ROE_FRACTAL_GMP_PREC)
	, m_yUpLt(ROE_FRACTAL_GMP_PREC)
	, m_xCenter(ROE_FRACTAL_GMP_PREC)
	, m_yCenter(ROE_FRACTAL_GMP_PREC)
	, m_width  (ROE_FRACTAL_GMP_PREC)
	, m_height (ROE_FRACTAL_GMP_PREC)
	, m_xPos   (ROE_FRACTAL_GMP_PREC)
	, m_yPos   (ROE_FRACTAL_GMP_PREC)
	, xPos     (ROE_FRACTAL_GMP_PREC)
	, yPos     (ROE_FRACTAL_GMP_PREC)
	, xPos2    (ROE_FRACTAL_GMP_PREC)
	, yPos2    (ROE_FRACTAL_GMP_PREC)
	, tmp      (ROE_FRACTAL_GMP_PREC)
#endif
	{
#ifdef ROE_FRACTAL_USE_GMP
		mpf_set_default_prec(ROE_FRACTAL_GMP_PREC); //setting the default precision
#endif
#ifdef ROE_FRACTAL_GMP_USE_C
		gmpcInit({&m_xUpLt,&m_yUpLt,&m_xCenter,&m_yCenter,&m_width,&m_height});
		gmpcInit({&m_xPos,&m_yPos,&xPos,&yPos,&xPos2,&yPos2,&tmp});
		setPrecision(ROE_FRACTAL_GMP_PREC);
		mpf_set_d(m_xCenter, 0.0);
		mpf_set_d(m_yCenter, 0.0);
		mpf_set_d(m_width  , 4.0);
		mpf_set_d(m_height , 4.0);
#else
		setPrecision(ROE_FRACTAL_GMP_PREC);
		m_width = 4;
		m_height = 4;
		m_xCenter = 0.0;
		m_yCenter = 0.0;
#endif
		
		updateCorners();
		m_innerR = m_innerG = m_innerB = 0; //black inner color
		texture.data = nullptr;
	}