You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/04/07 12:43:33 UTC

[commons-numbers] 01/09: BigFraction: Removed validation of arguments in internal function

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 db98ddf465f685a2ae0ec265feb6de8fe62f3f67
Author: aherbert <ah...@apache.org>
AuthorDate: Tue Apr 7 09:21:50 2020 +0100

    BigFraction: Removed validation of arguments in internal function
    
    This method is only called internally and the arguments are always
    valid.
---
 .../apache/commons/numbers/fraction/BigFraction.java    | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index 2f9c1d0..a3c3242 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -628,6 +628,9 @@ public final class BigFraction
      * least significant bits used for the significand, the next more
      * significant bits for the exponent, and next more significant bit for the
      * sign.
+     *
+     * <p>Warning: The arguments are not validated.
+     *
      * @param exponentLength the number of bits allowed for the exponent; must be
      *                       between 1 and 32 (inclusive), and must not be greater
      *                       than {@code 63 - significandLength}
@@ -638,16 +641,14 @@ public final class BigFraction
      *                          {@code 63 - exponentLength} (inclusive)
      * @return the bits of an IEEE 754 binary floating-point representation of
      * this fraction encoded in a {@code long}, as described above.
-     * @throws IllegalArgumentException if the arguments do not meet the
-     *         criteria described above
      */
     private long toFloatingPointBits(int exponentLength, int significandLength) {
-        if (exponentLength < 1 ||
-            significandLength < 1 ||
-            exponentLength > Math.min(32, 63 - significandLength)) {
-            throw new IllegalArgumentException("exponent length: " + exponentLength +
-                                               "; significand length: " + significandLength);
-        }
+        // Assume the following conditions:
+        //assert exponentLength >= 1;
+        //assert exponentLength <= 32;
+        //assert significandLength >= 1;
+        //assert significandLength <= 63 - exponentLength;
+
         if (numerator.signum() == 0) {
             return 0L;
         }