commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Hanna (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-754) Additional Fraction Constructor
Date Mon, 27 Feb 2012 01:21:49 GMT

    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216977#comment-13216977
] 

Travis Hanna commented on MATH-754:
-----------------------------------

Oh, nothing is wrong with a subclass.  This is the way I would have solved it in the project
I'm working on but in commons-math 2.2, Fraction is declared final. Instead, I had to create
a little utility class to generate these fractions as a result.  I figured other people have
probably had the same problem so I thought I might submit a patch back to try and be helpful.

In my last comment, I was speculating on whether or not it would be useful to have a class
that represents a Fraction with a constrained denominator and maintains that constraint through
whatever operations you might perform on it.  My gut says it wouldn't be all that useful though
so I won't be creating one.

I think you have a valid point when you say I'm pushing higher level requirements down into
the Fraction class but I do have one counter argument.  These constructors all smell the same
to me:

public Fraction(double value, double epsilon, int maxIterations)
public Fraction(double value, double epsilon, Set<Integer> acceptableDenominators) 
public Fraction(double value, int maxDenominator)

There's really no clean way to create a fraction from a double.  In all three cases, higher
level requirements have seeped down into the library.  The amount of acceptable error and
performance constraints are both higher level requirements IMHO.  

I won't be offended if my patch is rejected or anything.  I just suspect other people using
the class probably have similar requirements.

Maybe there should be a separate class that is responsible for converting doubles to Fractions
to keep the Fraction class clean?
                
> Additional Fraction Constructor
> -------------------------------
>
>                 Key: MATH-754
>                 URL: https://issues.apache.org/jira/browse/MATH-754
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 3.0
>         Environment: All
>            Reporter: Travis Hanna
>            Priority: Minor
>              Labels: features, newbie, patch
>             Fix For: 3.0
>
>         Attachments: math.patch
>
>
> I'm writing some code which outputs fractional measurements meant for human consumption.
I need a constructor for Fraction which allows you to restrict the denominators to a finite
set. This is necessary due to the fact that real-world tools are only available with certain
fractions. For example, it's next to impossible to find a ruler with 1/7 inch marked :). 
> I'm attaching a patch which implements the functionality. I've attempted to mimic the
style of the existing code as much as possible. One caveat: I don't speak French so the french
error message is a computer-generated translation and probably very poor.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message