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

BigInteger square root and power not in sync?

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      | Welcome to JShell -- Version 18
      | For an introduction type: /help intro

      jshell> BigInteger b = BigInteger.valueOf(Long.MAX_VALUE);
      b ==> 9223372036854775807

      jshell> b.sqrt();
      $2 ==> 3037000499

      jshell> 3037000499L*3037000499L
      $3 ==> 9223372030926249001

      jshell> 9223372036854775807L-9223372030926249001L
      $4 ==> 5928526806

      jshell> BigInteger c = b.sqrt();
      c ==> 3037000499

      jshell> c.pow(2);
      $6 ==> 9223372030926249001

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      As with smaller integers:

      jshell> BigInteger b = BigInteger.valueOf(16);
      b ==> 16

      jshell> b.sqrt();
      $9 ==> 4

      jshell> 4*4
      $10 ==> 16

      jshell> BigInteger c = b.sqrt();
      c ==> 4

      jshell> c.pow(2);
      $12 ==> 16


            rgiulietti Raffaello Giulietti
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: