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

BigDecimal movePointLeft() and movePointRight() do not follow their API spec

XMLWordPrintable

    • b06
    • generic
    • generic
    • Verified

      A DESCRIPTION OF THE PROBLEM :
      A previous bug report was filed as JDK-8183912 which was fixed and now causes these two functions to not allocate a new BigDecimal if called with n==0 argument. However, this behavior can be wrong according to the java docs for each function. The last sentence of movePointLeft() says "The BigDecimal returned by this call has value (this × 10-n) and scale max(this.scale()+n, 0)."

      Example:
          new BigDecimal("1e3").movePointLeft(0);
      result on jdk 17 is 1e3 (scale -3)
      However, the expected scale according to the java docs is max(this.scale()+n, 0) which is max(-3, 0) or scale of 0.
      Therefore the expected value is 1000 (scale 0). This behavior seems to be correct in older versions of Java.


      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: