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

Double.scalb fails for higher exponents.

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      This bug occurs accross all versions i tried including 11

      A DESCRIPTION OF THE PROBLEM :
      Comparing
      System.out.println("pow 2^max: "+Math.pow (2, 127));
      System.out.println("sca 2^max: "+Math.scalb(1, 127));
      yields
      pow 2^max: 1.7014118346046923E38
      sca 2^max: 1.7014118E38

      but even worse,
      System.out.println("pow 2^max: "+Math.pow (2, 128));
      System.out.println("sca 2^max: "+Math.scalb(1, 128));
      yields
      pow 2^max: 3.4028236692093846E38
      sca 2^max: Infinity
      Wheras pow works until Double.MAX_EXPONENT, scalb continues to fail.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just write a class with main method containing the two lines in the description.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      2^127 shall be the same with pow and with scalb and i have good reasons to suspect,
      that scalb is wrong.
      2^128 until 2^Double.MAX_EXPONENT shall be finite as it is for pow, but not for scalb.

      Note: scalb for float seems ok.
      ACTUAL -
      lower exponents until 127 inaccurate result, 128 to Double.MAX_EXPONENT infinite result.

      ---------- BEGIN SOURCE ----------
      see above.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      well, use the cumbersome pow. but this is not as exact.
      I need in particular scalb(1,...) i.e. powers of 2 which shall be exact using scalb but not for pow.
      So, for high precision computing: no workaround.
      Well long to double.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: