From commits-return-72761-apmail-commons-commits-archive=commons.apache.org@commons.apache.org Thu Apr 9 09:25:58 2020 Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 1194619D92 for ; Thu, 9 Apr 2020 09:25:57 +0000 (UTC) Received: (qmail 28526 invoked by uid 500); 9 Apr 2020 09:25:55 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 28179 invoked by uid 500); 9 Apr 2020 09:25:55 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 28012 invoked by uid 99); 9 Apr 2020 09:25:55 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Apr 2020 09:25:55 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1DF658B69F; Thu, 9 Apr 2020 09:25:55 +0000 (UTC) Date: Thu, 09 Apr 2020 09:25:58 +0000 To: "commits@commons.apache.org" Subject: [commons-numbers] 04/04: Fraction: Add thrown exception to pow javadoc. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: aherbert@apache.org In-Reply-To: <158642435498.21646.2433932466597864275@gitbox.apache.org> References: <158642435498.21646.2433932466597864275@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: commons-numbers X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 424c6c359b230554acf29afebf6c375e12b84d1d X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20200409092555.1DF658B69F@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit 424c6c359b230554acf29afebf6c375e12b84d1d Author: aherbert AuthorDate: Thu Apr 9 10:22:21 2020 +0100 Fraction: Add thrown exception to pow javadoc. Add test to the demonstrate exception due to overflow. --- .../src/main/java/org/apache/commons/numbers/fraction/Fraction.java | 1 + .../test/java/org/apache/commons/numbers/fraction/FractionTest.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index 8f41989..fa7b377 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -642,6 +642,7 @@ public final class Fraction * * @param exponent exponent to which this {@code Fraction} is to be raised. * @return thisexponent. + * @throws ArithmeticException if the intermediate result would overflow. */ @Override public Fraction pow(final int exponent) { diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java index 082b884..2a5d5f1 100644 --- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java +++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java @@ -376,6 +376,11 @@ public class FractionTest { Fraction c = Fraction.of(0, -11); assertFraction(0, -1, c.pow(Integer.MAX_VALUE)); + + Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(Integer.MAX_VALUE).pow(2)); + Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(1, Integer.MAX_VALUE).pow(2)); + Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(Integer.MAX_VALUE).pow(-2)); + Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(1, Integer.MAX_VALUE).pow(-2)); } @Test