From dev-return-169058-archive-asf-public=cust-asf.ponee.io@commons.apache.org Mon Dec 3 19:02:03 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id B485118067A for ; Mon, 3 Dec 2018 19:02:02 +0100 (CET) Received: (qmail 72120 invoked by uid 500); 3 Dec 2018 18:02:01 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 71669 invoked by uid 99); 3 Dec 2018 18:02:01 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2018 18:02:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A37BC18BEC6 for ; Mon, 3 Dec 2018 18:02:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.798 X-Spam-Level: * X-Spam-Status: No, score=1.798 tagged_above=-999 required=6.31 tests=[DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id vNI-n3wFSwfq for ; Mon, 3 Dec 2018 18:01:59 +0000 (UTC) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 0A6AB60D6C for ; Mon, 3 Dec 2018 18:01:59 +0000 (UTC) Received: by mail-lf1-f48.google.com with SMTP id a16so9869006lfg.3 for ; Mon, 03 Dec 2018 10:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=DpjI/E5YQqzXByJ8RYA3MbxiZQikKHQeB6DOndFvYr8=; b=OvArRktIc9BfWs/0kVffInE4jIeocY4tTXjl86arTlqv4mDZXR7qNgboP7FMtD3Kzb MyXv1mpTiJuU/lGSWOTvmVMxx0/PzctcgeZQdfZu5mo+hGV6WK2scssh+ljlqEhsR14X fExFYJS34ZHaDaXhMzi+iIYd6CxdIoCP1aeNul9iQtpOmRQygObaFJ1vP7NDCDZxGuqv ca6fRajKTVZPtsXhiI7dUYa9/Wc8puofHKdibCBnQikL/iWwbogefsDfJ+WTY/8goUcG nhpIwRx7Acrxisq9vsayyNJSZ1BnvXCWpWytGjSZtYA7LEt8tm4fDNwHaKCAd1h48peN MJRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=DpjI/E5YQqzXByJ8RYA3MbxiZQikKHQeB6DOndFvYr8=; b=DiPm1bTacJX3Ei9misG3+zqSCq0JrfPMzkzHfVUE7WBm/b72/cOAgQaQGaMnNUx7nF Q8FyLDp255PLRMVuGSDHY2VpRg0+v5A00Lfi54dq8wVC4SMWaT/6AbrOYq0Dcl+VA2qK qiiiFDGNWhAo2QyFPaxg8fX4En8fx4vP3ylwQ8XGOd338YCTp/ufSPX900kpfQK+qWcl Fq3Q8HhIbBgHVj8tniiDFAb7i1R0XxngzJYtRUb4l3UWqP2Yfby841JM1hoZcgAaw2za J3eehpEnqxihDYOn1xoyJxTA6grqg3cPdNZ6QAVQYwpMcL4NzXwfmJgD2sy7YHAqlKN7 RITg== X-Gm-Message-State: AA+aEWaceuwVLq4xPzXsKKJdG8gMRUI+KO8it+bCZ4CLZNnQS8S1CsAt F2R/SOaWhNmlZQXmi01bp7gcQ9np1j2lz1WxyaNbbg== X-Google-Smtp-Source: AFSGD/UyZG4ky5uelNqrClNiNkLV37g3b/u5vOfUFNmTqxgI7ZkDXUf6uvMqJ6jGQu3Tgimb2J18QyU/1OeE7/em2mA= X-Received: by 2002:a19:982:: with SMTP id 124mr9475436lfj.138.1543860111688; Mon, 03 Dec 2018 10:01:51 -0800 (PST) MIME-Version: 1.0 References: <9281bc880faa3ea84b7a206bf470cede@scarlet.be> In-Reply-To: <9281bc880faa3ea84b7a206bf470cede@scarlet.be> From: Eric Barnhill Date: Mon, 3 Dec 2018 10:01:39 -0800 Message-ID: Subject: Re: [numbers] Fraction() and Knuth 4.5.1 -- overflow, BigInteger, long, and rounding To: Commons Developers List Content-Type: multipart/alternative; boundary="0000000000008a48da057c21f196" --0000000000008a48da057c21f196 Content-Type: text/plain; charset="UTF-8" > > > Does this mean that computations can "unpredictably" overflow > (or throw an exception)? > The ArithmeticUtils() methods mulAndCheck and addAndCheck throw exceptions if there is overflow during primitive operations. That is the "check" part of the method name. > Is it acceptable, or should we enclose the problematic code in > a "try" block and redo the computation with "BigInteger" when > necessary? > > What is the performance hit of using "BigFraction" rather than > "Fraction"? > I once used BigDecimal for a project, it is great code but the performance is nothing close to using primitives. > Are there use-cases that would need the ultimate performance from > "Fraction" while not worry about overflow? > You would need a greatest common factor between the two fractions that was larger than 64 bits. Again, BigFraction is there for anyone worried about such a case and there is no significant performance hit to switching over to BigFraction compared to a Fraction class that was using BigInteger under the hood. But I suspect there would be a substantial performance gain if longs were being used under the hood for the Fraction class for the more common use case of smaller fractions. If it would be best practice, a bit of microbenchmarking could be done to check. A FractionOverflowException could be specifically tailored to this use case and the error message can suggest using BigFraction. Or as you suggest, the catch block could silently or with warning return a BigFraction. If we have class inheritance straight, and both Fraction and BigFraction have the exact same interface, this could be an elegant solution. Eric --0000000000008a48da057c21f196--