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

wrong work of the Math.max method on zeros

XMLWordPrintable

    • 1.1.1
    • sparc
    • solaris_2.4
    • Not verified



      Name: swC45995 Date: 10/22/96


      The Math.max method produces the negative zero when its first argument
      is a negative zero and the second is a positive zero. It contradicts
      the assertion of the Java Language Specification:

      "... methods Math.min (#20.11.27, #20.11.28) and Math.max (#20.11.31, #20.11.32) treat negative zero as being strictly smaller than positive zero." (#15.19.1)

      Thus, execution of the following test

      public class test
      {
      public static void main(String argv[])
      {
      float fNZ = -0.0f;
      float fPZ = +0.0f;
      double dNZ = -0.0d;
      double dPZ = +0.0d;

      System.out.println(fNZ);
      System.out.println(fPZ);
      System.out.println(Math.max(fNZ, fPZ));
      System.out.println(Math.max(fPZ, fNZ));

      System.out.println(dNZ);
      System.out.println(dPZ);
      System.out.println(Math.max(dNZ, dPZ));
      System.out.println(Math.max(dPZ, dNZ));
      }
      }

      produces the following output:

      -0
      0
      -0
      0
      -0
      0
      -0
      0

      instead of expected:

      -0
      0
      0
      0
      -0
      0
      0
      0

      ======================================================================

            mr Mark Reinhold
            wensunw Wen Wen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: