Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9828199A5 for ; Mon, 27 Feb 2012 01:22:10 +0000 (UTC) Received: (qmail 93913 invoked by uid 500); 27 Feb 2012 01:22:10 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 93837 invoked by uid 500); 27 Feb 2012 01:22:10 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 93828 invoked by uid 99); 27 Feb 2012 01:22:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Feb 2012 01:22:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Feb 2012 01:22:09 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 0A58533B80E for ; Mon, 27 Feb 2012 01:21:49 +0000 (UTC) Date: Mon, 27 Feb 2012 01:21:49 +0000 (UTC) From: "Travis Hanna (Commented) (JIRA)" To: issues@commons.apache.org Message-ID: <128113208.21798.1330305709043.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <634448096.20986.1330264129437.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (MATH-754) Additional Fraction Constructor MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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 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