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

javax.vecmath.Matrix4d allows negative number which can result in NaN upon sqrt(Negative)

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      A DESCRIPTION OF THE PROBLEM :
      My apologies in advance for what is probably my mistake. I'm looking at JRE1.8.0-241 javax.vecmath.Matrix4d (revision 127, 2008-02-28) at line 915+.

      914 ww = 0.25*(1.0 + tmp_rot[0] + tmp_rot[4] + tmp_rot[8]);
      915 if(!((ww<0?-ww:ww) < 1.0e-30)) {
      916 q1.w = (float)Math.sqrt(ww);
      917 ww = 0.25/q1.w;

      at line 915 ww can be negative, which means on 916 sqrt(negative) returns NaN. Oops?

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see test case below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      non-NaN values in B.
      ACTUAL -
      B.* is NaN

      ---------- BEGIN SOURCE ----------

      public class Matrix4dTest {
      @Test
      public void testQuatFail() {
      Matrix4d A = new Matrix4d(
      6.123233995736766E-17, 6.123233995736766E-17, 1.0, 44.5,
      -6.123233995736766E-17, -1.0, 6.123233995736766E-17, 1.3949339365687892E-16,
      1.0, -6.123233995736766E-17, -6.123233995736766E-17, 61.967099999999995,
      0.0, 0.0, 0.0, 1.0);
      Quat4d B= new Quat4d();
      A.get(B);
      assert(!Double.isNaN(B.x));
      assert(!Double.isNaN(B.y));
      assert(!Double.isNaN(B.z));
      assert(!Double.isNaN(B.w));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
              ww = 0.25*(1.0 + tmp_rot[0] + tmp_rot[4] + tmp_rot[8]);
              double wAbs = Math.abs(ww);
              if(wAbs >= 1.0e-30) {
                q1.w = Math.sqrt(wAbs);

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              sswsharm swati sharma
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: