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

java.lang.Bignum.shiftLeft(), shiftRight() work wrong if scale != 0

XMLWordPrintable

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

      These methods work wrong if the number contains digits after decimal point.
      The scale for result is always set to 0.
      This behaviour is not compatible with specification.

      ==== Here is the minimized test demonstrating the bug ====
      import java.lang.Bignum;
      class java_lang_Bignum_shiftLeft {
        public static void main(String args[]) {
          Bignum b1=new Bignum("1.1");
          Bignum b2=b1.shiftLeft(1);
          Bignum b3=b1.shiftRight(1);
          System.out.println(b2); //should print "2.2" but prints "22"
          System.out.println(b3); //should print "0.5" but prints "5"
        }
      }
      ==== Here is the output of the test ====
      22
      5
      ==== Here is the part of java language specification ====
         public Bignum shiftRight(int shiftBits)

            Returns a new Bignum whose value is calculated by shifting this Bignum
            to the left by the number of bits given in shiftBits
            Parameters:
                  shiftBits - the number of bits to shift.
            Returns:
                  A new Bignum whose value is this Bignum / 2^shiftBits

       
        public Bignum shiftLeft(int shiftBits)

            Returns a new Bignum calculated by shifting this Bignum to the
            left by the number of bits given in shiftBits.
            Parameters:
                  shiftBits The number of bits to shift
            Returns:
                  A new Bignum whose value is this Bignum * 2^shiftBits

            mhapnersunw Mark Hapner (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: