java.lang.Rational ...

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.
 
D

Daniel Pitts

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?
The 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.
Well, from my original post we wandered around the topic to its main
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>

[...]
They hopefully rely on the Binary GCD version, which is based on Euclids:

<http://en.wikipedia.org/wiki/Binary_GCD_algorithm>
Basically it optimizes for removing common powers of two.
 
A

Arne Vajhøj

And then start to fix the bugs in it.

Well - you *can* fix the bugs in it.

For a closed source library one options is very limited (unless
one pay the huge buck required to get a supplier to fix a bug ASAP).

Arne
 
A

Arne Vajhøj

Fortunately, code from Sun is bug-free.

<ducks behind twenty-centimeter wall of armor plate>

Not enough!

On this particular topic: is it possible to get a count
of unresolved bugs for Java 1.6 at the bug web site?

Arne
 
L

Lew

Basic mathematical entities is a rather small subset of all classes.

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 doubt there's a single package within Java's standard API that everyone
would agree is complete, whether it's java.util, java.math, java.io or even
java.lang. The best one can hope for, and what we actually have, is a robust
library that has most of what we need most of the time, and a thriving
third-party open-source marketplace that includes JScience and Apache Commons
to fill in some of the gaps, never mind the various for-pay libraries out there.

I 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:

Arne Vajhøj wrote:
"Rational is not a traditional basic type in programming like the above
[BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short]. ... And
no matter how much they chose to include then there will always be some that
think some functionality is missing."
 
E

Eric Sosman

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>

[...]
They hopefully rely on the Binary GCD version, which is based on 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.
 
J

John B. Matthews

Eric Sosman said:
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>

[...]
They hopefully rely on the Binary GCD version, which is based on
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.

Like BigInteger, JScience's LargeInteger (the component type of
Rational) takes a hybrid approach to GCD, using Euclid's algorithm
until the numbers are approximately the same length and the binary GCD
algorithm thereafter. I don't know why, but the binary's worst-case
time is O((log2 uv)^2), proportional to the square of the number of
bits in the parameters u and v.
 
M

Mike Schilling

Eric said:
Fortunately, code from Sun is bug-free.

No, but it is tested. In fact, wasn't that one of the Open Source
community's complains about Java, Sun's draconian requirement that to be
called "Java", code had to actually pass tests?
 
A

Arne Vajhøj

True but not highly relevant.

More or less the only thing relevant.
My point is that Sun cannot implement every useful class one can
imagine.

Which I don't think anyone has suggested, so why do you keep arguing
against it?
That holds true even within an arbitrary "rather small subset
of all classes."

I don't think it holds true if we limit it to classes that are
known by it least a billion people with the same semantics.
I would not agree that 'Rational' is so basic that it represents a
serious oversight on Sun's part to omit it.

I am not arguing that it is an oversight.

Given the relative small emphasize on mathematical stuff in
Java, then it seems to be somewhat in line with the overall
direction.

I am just arguing that it is not "any" class.

Arne
 
M

Martin Gregorie

I 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.
 
T

Tom Anderson

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.

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.

tom
 
M

Martin Gregorie

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.
Fair point.

I've seen complex numbers used that way in HP calculators and a few other
places but wasn't certain how widespread that usage is. Now I know.
 

Ask a Question

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.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top