DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Calcular El Epsilon De La Libreria Gmp

09.22.2006
| 2228 views |
  • submit to reddit
        Este codio calcula el epsilon de la libreria gmp, variando en cada ciclo la presicion del numero.

#include <iostream>
#include <limits.h>
#include <gmpxx.h>

using namespace std;


int main(int argc, char **argv){
	unsigned long int i,j;
//	4294967295

	for (i=1;i<4294967295UL;i*=2){
		j=0;
		mpf_class epsilon(0.5,i);

		while(epsilon+1 != 1){
		//cout.precision(200000);
		//cout<<"Epsilon: "<<epsilon<<endl;
			epsilon /= 2;
			j++;
		};
		cout.precision(20);	
//	cout<<"Precision: "<<ULONG_MAX<<endl;
		cout<<"Epsilon Final: "<<epsilon<<" Numero de ciclos: "<<j<<" Precision: "<<i<<endl;
	}

	return 0;
}