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

Math.pow yields different results upon repeated calls

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u80, 8u25, 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • Introduced In Build:
      b03
    • Introduced In Version:
    • Resolved In Build:
      b48
    • CPU:
      x86_64
    • OS:
      linux

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_25"
        Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
        Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


        FULL OS VERSION :
        Linux host 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        The function Math.pow() returns slightly different results upon repeated calls with exactly the same input parameters. It seems as if the implementation (floating point precision) is switched internally at some point during execution.

        A mathematical function must return consistent and reproducible results within one VM instance.

        also see http://stackoverflow.com/questions/26746623/math-pow-yields-different-results-upon-repeated-calls



        THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No

        THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

        REGRESSION. Last worked in version 8u11

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the example code given below.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        It should print nothing, but it prints:
        Math.pow()
        i=15573
        x=2.862738293257239E7
        p=2.8627382932572395E7

        REPRODUCIBILITY :
        This bug can be reproduced often.

        ---------- BEGIN SOURCE ----------
        import java.util.function.BiFunction;

        public class PowerTest {

            private static final int N = 1000000;
            private static final double base = 5350.456329377186;
            private static final double exp = 2.0;

            private static double eval(final BiFunction<Double, Double, Double> f) {
                return f.apply(base, exp);
            }

            private void loop(final String s, final BiFunction<Double, Double, Double> f) {
                double x = eval(f);
                for (int i = 0; i < N; i++) {
                    final double p = eval(f);
                    if (x != p) {
                        System.out.println(s + "\ni=" + i + "\nx=" + x + "\np=" + p);
                    }
                    x = p;
                }
            }

            public void mathPow() {
                loop("Math.pow()", Math::pow);
            }

            public void strictMathPow() {
                loop("StrictMath.pow()", StrictMath::pow);
            }

            public static void main(final String[] args) {
                final PowerTest pt = new PowerTest();
                pt.mathPow();
                pt.strictMathPow();
            }
        }

        ---------- END SOURCE ----------

          Issue Links

            Activity

            webbuggrp Webbug Group created issue -
            aroy Abhijit Roy (Inactive) made changes -
            Field Original Value New Value
            Project Java Incidents [ 10301 ] JDK [ 10100 ]
            Key JI-9016330 JDK-8063086
            aroy Abhijit Roy (Inactive) made changes -
            Affects Version/s 8u25 [ 16502 ]
            Affects Version/s 8u25 [ 16842 ]
            Subcomponent runtime [ 543 ] runtime [ 192 ]
            Component/s hotspot [ 10304 ]
            Component/s hotspot [ 10707 ]
            dholmes David Holmes made changes -
            Subcomponent runtime [ 192 ] compiler [ 208 ]
            twisti Christian Thalinger made changes -
            Assignee Roland Westrelin [ roland ]
            neliasso Nils Eliasson made changes -
            Link This issue relates to JDK-7198295 [ JDK-7198295 ]
            neliasso Nils Eliasson made changes -
            Fix Version/s 9 [ 14949 ]
            Priority P4 [ 4 ] P3 [ 3 ]
            neliasso Nils Eliasson made changes -
            Status New [ 10000 ] Open [ 1 ]
            roland Roland Westrelin made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Understanding Cause Known [ 10000 ]
            hgupdate HG Updates made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Understanding Cause Known [ 10000 ]
            Resolved In Build team [ 17324 ]
            Resolution Fixed [ 1 ]
            hgupdate HG Updates made changes -
            Resolved In Build team [ 17324 ] master [ 18256 ]
            hgupdate HG Updates made changes -
            Resolved In Build master [ 18256 ] b48 [ 17519 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8083214 [ JDK-8083214 ]
            csahu Cheleswer Sahu (Inactive) made changes -
            Link This issue backported by JDK-8156727 [ JDK-8156727 ]
            csahu Cheleswer Sahu (Inactive) made changes -
            Link This issue duplicates JDK-8156944 [ JDK-8156944 ]
            idergali Ilya Dergalin (Inactive) made changes -
            Affects Version/s 9 [ 14949 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8158431 [ JDK-8158431 ]
            avorobye Alexander Vorobyev (Inactive) made changes -
            Comment [ A comment with security level 'Confidential' was removed. ]
            avorobye Alexander Vorobyev (Inactive) made changes -
            Affects Version/s 7u80 [ 16320 ]
            idergali Ilya Dergalin (Inactive) made changes -
            Introduced In Build b03 [ 17453 ]
            Introduced In Version 7u80 [ 16320 ]
            mcastegr Mattis Castegren (Inactive) made changes -
            Link This issue backported by JDK-8158920 [ JDK-8158920 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8159659 [ JDK-8159659 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8159662 [ JDK-8159662 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8162086 [ JDK-8162086 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8163634 [ JDK-8163634 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8167741 [ JDK-8167741 ]
            hgupdate HG Updates made changes -
            Link This issue backported by JDK-8168165 [ JDK-8168165 ]
            christos Christos Zoulas made changes -
            Link This issue relates to JDK-8189172 [ JDK-8189172 ]

              People

              • Assignee:
                roland Roland Westrelin
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: