M
Mike Schilling
Arne said:That is the good thing about multiple open source libraries covering
the same topic.
You can try them all and pick the one that fits your needs best.
And then start to fix the bugs in it.
Arne said:That is the good thing about multiple open source libraries covering
the same topic.
You can try them all and pick the one that fits your needs best.
And then start to fix the bugs in it.
They hopefully rely on the Binary GCD version, which is based on Euclids:John said:Albretch Mueller said:I found [it] a little weird that such a library does not have such a
method! I for one would need such a method.
I can't say I've ever seen a need to expose that operation. Can you
elaborate?Well, from my original post we wandered around the topic to its mainThe method the OP needs is called "normalize", it is private. It
looks like Rational does keep items reduced, which is a reasonable
assumption to make of a well-implemented Rational class.
point; namely, how do these libraries do their background cooking
with prime numbers
I think those libraries -must- keep the fractions reduced in fact
they should keep instead of the numbers themselves their
factorizations in order to run lcd and gcf algorithms without
dividing and modulo operations
The implementations I know typically rely on GCD via Euclid's
algorithm. I was intrigued to learn that the approach "never requires
more steps than five times the number of digits (base 10) of the
smaller integer."
<http://en.wikipedia.org/wiki/Euclidean_algorithm>
[...]
And then start to fix the bugs in it.
Fortunately, code from Sun is bug-free.
<ducks behind twenty-centimeter wall of armor plate>
Basic mathematical entities is a rather small subset of all classes.
They hopefully rely on the Binary GCD version, which is based on Euclids:John said:[...]
The implementations I know typically rely on GCD via Euclid's
algorithm. I was intrigued to learn that the approach "never requires
more steps than five times the number of digits (base 10) of the
smaller integer."
<http://en.wikipedia.org/wiki/Euclidean_algorithm>
[...]
<http://en.wikipedia.org/wiki/Binary_GCD_algorithm>
Basically it optimizes for removing common powers of two.
Eric Sosman said:They hopefully rely on the Binary GCD version, which is based onJohn said:[...]
The implementations I know typically rely on GCD via Euclid's
algorithm. I was intrigued to learn that the approach "never
requires more steps than five times the number of digits (base 10)
of the smaller integer."
<http://en.wikipedia.org/wiki/Euclidean_algorithm>
[...]
Euclids:
<http://en.wikipedia.org/wiki/Binary_GCD_algorithm>
Basically it optimizes for removing common powers of two.
FWIW, BigInteger's gcd() method uses a mixed strategy:
Euclid's algorithm while the two numbers are wildly different,
then the binary method once their lengths are within sixty-four
bits of each other. I haven't tried to figure out why it's
done this way.
Eric said:Fortunately, code from Sun is bug-free.
True but not highly relevant.
My point is that Sun cannot implement every useful class one can
imagine.
That holds true even within an arbitrary "rather small subset
of all classes."
I would not agree that 'Rational' is so basic that it represents a
serious oversight on Sun's part to omit it.
Rational is not a traditional basic type in programming like the
above.
In fact you can make the case that a Complex number class would be moreI would not agree that 'Rational' is so basic that it represents a
serious oversight on Sun's part to omit it. To quote one of our
smartest and most knowledgeable contributors:
In fact you can make the case that a Complex number class would be more
useful because these are often used to represent 2D co-ordinates in
mapping applications.
Fair point.They're used to do that in systems which have a complex type but lack a
point type.
It seems to me that if you're representing coordinates, you should use a
class which represents a coordinate, not one which represents a complex
number, and enabling the complex-for-float kludge would not be a
desirable thing.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.