Hello everyone, 

I'm writing here to get help with an application I
am developing using the Fraction class from org.apache.commons.math.
But, since I am French, my English is quite bad ! I apologize, for this
and I hope, you will understand me anyway. 

Here is my problem: 

I
need the rational numbers for my application but I have performances
issues. I found out, using profiling (visualVM), that most of the CPU
time was spent in the gcd() method since it is called every time a
Fraction is instantiated and that it's the harder part of the
computation. Moreover, a new instance is created each time an operation
(+ - * /) is called. That makes a lot of calls to gcd(). 

In my
application, most of the computations are : A + B * (C - D). Each time,
there are 3 operations so 3 calls to gcd(). 

My questions are: 

Is it
possible to force the library to call gcd() only once, at the end of the
formula ? 

If i manage to do that, will it be faster? Or will the lone
gcd() last the same time that the three previous gcd() together? 

Thank
you for your answers, and again, my apologies for the bad English. 

--

Léo Martel - Software Engineer
Institut Supérieur de l'Aéronautique et
de l'Espace (ISAE) 

 

Reply via email to