commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C. Scott Ananian" <csc...@cscott.net>
Subject Re: [lang] [math] org.apache.commons.lang.math.Fraction class
Date Thu, 03 Jun 2004 21:50:00 GMT
On Thu, 3 Jun 2004, Stephen Colebourne wrote:

> This presumes that everyone wants a reduced fraction. I believe that there
> are use cases for holding an unreduced one. The main one that strikes me is
> education.

The org.apache.commons.math.Fraction class is not targetted at education.
It's intended to be useful for working programmers.

If people complain about the deprecation, then the methods can be
undeprecated.  I doubt that will be the case.

> Somewhere along the line I've lost the reason why we should deprecate
> unreduced fractions. They are a valid representation of a fraction (so long
> as the internal calculations are done properly), so why not allow them?

The primary reason is programmer convenience.  Fractions will overflow
unless simplified regularly.  Further, the user will 'expect' that
1/2==2/4.  Maintaining in 'simplified form' also allows more predictable
overflow behavior.  By making this the actual behavior, potential bugs are
eliminated, and the user is not surprised.

Again, it's not like the deprecation can't be removed during alpha, beta,
or after release or some vocal existing user appears.

> BTW, the 2/4 != 1/2 is consistent with the JDK - classes like BigDecimal
> IIRC will have similar 'odd' behaviour, eg 0.500 != 0.5.

In BigDecimal these numbers are arguably different: they have different
precisions and thus round differently.  For example:
   divide(0.5,2) != divide(0.500,2)

Fraction is not intended to be used in this manner.  Fractions
are not rounded.  Computing with an unsimplified fraction may result in
overflow when a simplified fraction will not, but that is not a
specifically-desired behavior (nor is it a well-specified one).

Is there any other example of such behavior in the JDK?
  --scott

Clinton Seattle Chechnya East Timor genetic plutonium NRA cryptographic
colonel Panama cracking Sabana Seca WTO global action network corporate globalization
                         ( http://cscott.net/ )

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message