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

java.lang.Math.abs(float) works wrong with pozitive zero parameter

XMLWordPrintable

    • 1.2beta3
    • sparc
    • solaris_2.5, solaris_2.5.1
    • Verified



      Name: dsC58869 Date: 12/02/97



      The method java.lang.Math.abs(float floatPozitiveZero) works
      wrong with pozitive zero parameter.
      It returns NEGATIVE zero instead pozitive zero
      (see Java Language Specification 20.11.23).


      This bug was introduced in JDK1.2.

      ==== Here is the test demonstrating the bug ====

      public class Test{
          public static void main(String[] args){
      float floatPozitiveZero = 0.0F;
      System.out.println(java.lang.Math.abs(floatPozitiveZero));
      if((new Float(java.lang.Math.abs(floatPozitiveZero))).equals(new Float(0.0))){
      System.out.println("OKAY");
      return;
      }
      if((new Float(java.lang.Math.abs(floatPozitiveZero))).equals(new Float(-0.0))){
      System.out.println("failed: abs(positiveZero) equals negativeZero");
      return;
      }
      System.out.println("failed: see JLS 20.11.23");
      return;
          }
      }

      ==== Here is the output of the test ====

      -0.0
      failed: abs(positiveZero) equals negativeZero

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

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

      Name: dsC58869 Date: 01/14/98



      The method java.lang.Math.abs(double) has the same problem.

      see also bug 4098041

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

            apalanissunw Anand Palaniswamy (Inactive)
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: