bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/27685] New: Wrong result in java.math.BigInteger.modPow()


From: michael at hausl dot com
Subject: [Bug classpath/27685] New: Wrong result in java.math.BigInteger.modPow()
Date: 19 May 2006 19:52:38 -0000

java.math.BigInteger.modPow() returns the inverse if the the exponent is
negative:

  public GNUBigInteger modPow(GNUBigInteger exponent, GNUBigInteger m) {
    if (m.isNegative() || m.isZero())
      throw new ArithmeticException("non-positive modulo");

    if (exponent.isNegative())
      return modInverse(m);
...

This is wrong!
The following would be correct:

  if (exponent.isNegative()) {
    return modInverse(m).modPow(m, exponent.negate());
  }

See http://en.wikipedia.org/wiki/Modular_exponentiation for explanation.


-- 
           Summary: Wrong result in java.math.BigInteger.modPow()
           Product: classpath
           Version: 0.91
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael at hausl dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27685





reply via email to

[Prev in Thread] Current Thread [Next in Thread]