Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6626

Add a BigInteger.power(Biginteger) method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.2
    • 2.3.8
    • groovy-jdk
    • None

    Description

      Using the ** operator with a BigInteger as second argument provides in some cases inaccurate results. These results are inconsistent with using a corresponding plain Integer argument.

      Examples:

      assert 2G ** 63G == 2G ** 63
                |      |     |
                |      false 9223372036854775808
                9223372036854775807
      
      assert 13G ** 15G == 13G ** 15
                 |      |      |
                 |      false  51185893014090757
                 51185893014090760
      
      

      More examples can be produced with

      for (int base = 1; base < 32; base ++) {
          for (int exp = 1; exp < 128; exp++) {
              BigInteger baseI = new BigInteger(base);
              BigInteger expI = new BigInteger(exp);
              if (baseI ** expI != baseI ** exp)
                  println "assert ${base}G ** ${exp}G == ${base}G ** ${exp}"
          }
      }
      

      Attachments

        Activity

          People

            pschumacher Pascal Schumacher
            mahool Mike Hoolehan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: