Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4237470

BigInteger: 0.modPow(-1,2) no longer throws ArithmeticException in JDK 1.3

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: mgC56079 Date: 05/12/99



      The spec for BigInteger.modPow says:
          Returns a BigInteger whose value is
          <tt>(this<sup>exponent</sup> mod m)</tt>.
          (Unlike <tt>pow</tt>, this method permits negative exponents.)

      0^-1 is a division by zero and should result in an ArithmeticException.
      JDK 1.2.x works correctly. JDK 1.3 build C returns 0 which is incorrect.

      Here is a minimized test:
      ---------- BigIntegerTest.java ----------
      import java.math.*;
      class BigIntegerTest {

          public static void main(String[] args) {
              BigInteger b = new BigInteger("0");
              BigInteger p = new BigInteger("-1");
              BigInteger m = new BigInteger("2");
              System.out.println(b.modPow(p, m));
          }

      }
      ---------- Sample run (JDK1.2.1 FCS, correct) ----------
      % java BigIntegerTest
      Exception in thread "main" java.lang.ArithmeticException: BigInteger not invertible
      at java.math.BigInteger.modInverse(Compiled Code)
      at java.math.BigInteger.modPow(Compiled Code)
      at BigIntegerTest.main(Compiled Code)
      ---------- Sample run (JDK1.3S, wrong) ----------
      % java BigIntegerTest
      0

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mmcclosksunw Michael Mccloskey (Inactive)
              Reporter:
              gorsunw Gor Gor (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: