What are tags?
[ROOT] floating-point arithmetics
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > C/C++ Programming > [ROOT] floating-point arithmetics 5 January 2005 17:02:04

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

[ROOT] floating-point arithmetics

Giannis Doxaras 5 January 2005 17:02:04
 Hi all,
I am experiencing a problem with high precision integer arithmetic in ROOT.
After e^{20}, fmod() function seems to lose precision due to
floating point error I presume.
I wonder if there exists a class manipulating large integer, or
floating point arithmetic in general , something similar to GMP (GNU
Multiple Precision Arithmetic Library).
If not, it should be rather helpful, if such a feature was included
in forthcoming versions.
Friendly,


Doxaras John
University Of Athens
Division of Nuclear Physics & Elementary Particles
d0x@r@$


//Doxaras Ioannis University of Athens
//Division of Nuclear Physics and Elementary Particles

/*Algorithm for simulating Shor's procedure for factoring quantum
mechanicly a large composite number N into primes.
First we choose a random number [1...N-1] and using Eucleid's Algorithm
we check if the number we generated has no common devisors with N.
The distribution of co-prime number lower than N is determined [Hardy]
\phi(n)=m\prod_{p|m­}(1-\frac{1}{p}) were m=\prodp^{c}*/

void prime(Int_t numb)
{

gROOT->Reset();

Int_t rand = 7;
Int_t remainder;
Int_t quotient;
Int_t seed = 1;

gBenchmark->Start("­Prime");

//do
//{
gRandom = new TRandom3(seed);
rand = ceil(numb*gRandom->­Rndm());

//Eucleid's Algorithm

//remainder = &rand; //initialize
//quotient = &numb;

//while (remainder != 1)
//{
//quotient = quotient / remainder;
//remainder = fmod( quotient, remainder);
//}
// seed += 1;
//}while(quotient!=­ 0 || seed > 20);

cout << "The random number generated is: " << rand << endl;

//Create the Histograms
Int_t nbins = 128;
Int_t min = 0;
Int_t max = 127;
Double_t c2, c3;
TH1F * order = new TH1F("order","ORDER­",nbins,min,max);
TH1F * modulo = new TH1F("modulo","modu­lo",nbins,min,max);


for (Int_t k = 0; k < 128; k++ )
{
c2 = pow( rand , k );
c3 = fmod(c2, numb);
cout << "For: " << k << " show: " << c2 << " and " << c3 << endl;
order->Fill(k , k);
modulo->Fill(k, c3);
}


//Draw Options

TCanvas *c1 = new TCanvas("Order","",­200,10,700,780);
c1->SetFillColor(0)­;
c1->Divide(1,2);
order->GetXaxis()->­SetTitle("Potential orders of probabilistic algorithm");
order->GetXaxis()->­SetTitleFont(32);
order->GetXaxis()->­SetLabelFont(32);
order->GetXaxis()->­SetLabelSize(0.03);

c1->cd(1);
order->Draw(); // plot the spectrum
c1->cd(2);
modulo->Draw(); // plot the spectrum
c1->Update(); // update the canvas

gBenchmark->Show("P­rime");

}
Add comment
Rene Brun 5 January 2005 17:02:04 permanent link ]
 You can load the GMP library dynamically from an interactive ROOT session.
For example with gmp-4.1.4 installed in my home directory, I can do

root [0] gSystem.Load("/home­/brun/gmp-4.1.4/.lib­s/libgmp.so")

Now you can modify your prime.C file to include all the relevant
extern "C" void gmp_xxx
prototype declarations and the equivalent includes. Then do

root[1] .L prime.C+ (using ACLIC)
root[2] prime(4567)

I agree that it would be nice to call the GMP library directly from CINT.
This requires the dictionary for all GMP functions.
If somebody succeeds in building it, let me know.

Rene Brun

Giannis Doxaras wrote:>
Hi all,> I am experiencing a problem with high precision integer arithmetic in ROOT.> After e^{20}, fmod() function seems to lose precision due to> floating point error I presume.> I wonder if there exists a class manipulating large integer, or> floating point arithmetic in general , something similar to GMP (GNU> Multiple Precision Arithmetic Library).> If not, it should be rather helpful, if such a feature was included> in forthcoming versions.> Friendly,>
Doxaras John> University Of Athens> Division of Nuclear Physics & Elementary Particles> d0x@r@$>
-------------------­--------------------­--------------------­--------------------­-> Name: prime.C> prime.C Type: Plain Text (text/plain)> Encoding: quoted-printable


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > C/C++ Programming > [ROOT] floating-point arithmetics 5 January 2005 17:02:04

see also:
Firewall
A super huge form.
Script for downloading
пройди тесты:
see also:
Funny pictures
New Net for Skippy!
The top ten reasons why the television…

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .