You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Travis Hanna (Created) (JIRA)" <ji...@apache.org> on 2012/02/26 14:48:49 UTC

[jira] [Created] (MATH-754) Additional Fraction Constructor

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
             Fix For: 3.0
         Attachments: math.patch

I'm writing some code who's output includes 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

        

[jira] [Updated] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Travis Hanna updated MATH-754:
------------------------------

    Description: 
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.

  was:
I'm writing some code who's output includes 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.

    
> 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

        

[jira] [Resolved] (MATH-754) Additional Fraction Constructor

Posted by "Gilles (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gilles resolved MATH-754.
-------------------------

    Resolution: Won't Fix

This issue was based on a wrong assumption.

If you wish, please propose the enhancements (create Fraction objects based on various user criteria) on the "dev" ML.
                
> 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Commented) (JIRA)" <ji...@apache.org>.
    [ 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Gilles (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217136#comment-13217136 ] 

Gilles commented on MATH-754:
-----------------------------

bq. [...] in commons-math 2.2, Fraction is declared final. [...]

I don't see this in the code!

bq. [...] I do have one counter argument. [...]

I'm not sure that it's really the same kind of limitation, but I agree that where to draw the line is also a matter of taste...
You should then start a discussion on the "dev" ML.

bq. Maybe there should be a separate class that is responsible for converting doubles to Fractions to keep the Fraction class clean?

That would be nice. I'm pretty sure that other people will also be interested in this approach. I think that the "factory" pattern will be quite appropriate for implementing this functionality.

                
> 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Gilles (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216767#comment-13216767 ] 

Gilles commented on MATH-754:
-----------------------------

Hello.

At first glance, I'm not favorable to this addition. The reason is that IMHO Commons Math is a library that models mathematical objects and that the preconditions are dictated by the inherent limitations of those objects (or their numerical implementation). In the case which you present here, the limitation is imposed by the caller and has nothing to do with the called code ("Fraction").
One way to deal with your high-level requirement is to create a class that will inherit from CM "Fraction"; the constructor of your class will thus check the precondition that is now specific to the object which this new class is meant to model (a fraction with a controlled set of denominators).

Whether that new class will be a useful addition to the library is another issue.

                
> 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Gilles (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216856#comment-13216856 ] 

Gilles commented on MATH-754:
-----------------------------

What's the problem with a class? That's usually how you solve this kind of problem in OO programming: Instances of this class will be returned by a constructor that will make sure that the requirement is satisfied, and, as "Fraction" objects, they will be used transparently by any method that expects an argument of type "Fraction".

                
> 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

        

[jira] [Closed] (MATH-754) Additional Fraction Constructor

Posted by "Luc Maisonobe (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe closed MATH-754.
------------------------------


changing status to closed as 3.0 has been released
                
> 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13217185#comment-13217185 ] 

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

That's strange.  I don't see the final declaration either when I look in SVN but I swear I got a compile-time error when I tried to extend the class.  I'll confirm the version number that we're using and figure out where the discrepancy comes from.  Perhaps I made an error (accidentally imported a Fraction class from some other library, misinterpreted the error message, etc.)

I can submit a factory class for consideration.  It seems like 3.0 development is nearing a close though.  Should I attach another patch to this issue or would I be better off creating a new Jira issue and marking it 3.1?  
                
> 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13216783#comment-13216783 ] 

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

I'll think on this a bit.  I haven't considered having an entire class dedicated to representing a fraction with constrained denominators.  I'm not sure if it would be useful or not.  My initial instinct is that it's probably not very useful.
                
> 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

        

[jira] [Updated] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Travis Hanna updated MATH-754:
------------------------------

    Attachment: math.patch

Patch which adds new constructor to Fraction. Includes unit test and new error message. French error message should be reviewed by a native French speaker. It's machine generated.
                
> 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 who's output includes 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

        

[jira] [Commented] (MATH-754) Additional Fraction Constructor

Posted by "Travis Hanna (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13218836#comment-13218836 ] 

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

I see why I thought the Fraction class was final.  I was accidentally pulling in the fraction class from commons-lang (org.apache.commons.lang.math.Fraction).
                
> 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