Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-843

Precision.EPSILON: wrong documentation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0
    • 3.1

    Description

      The documentation of the Field EPSILON in class org.apache.commons.math3.util.Precision states, that EPSILON is the smallest positive number such that 1 - EPSILON is not numerically equal to 1, and its value is defined as 1.1102230246251565E-16.

      However, this is NOT the smallest positive number with this property.

      Consider the following program:

      public class Eps {
        public static void main(String[] args) {
          double e = Double.longBitsToDouble(0x3c90000000000001L);
      	double e1 = 1-e;
      	System.out.println(e);
      	System.out.println(1-e);
      	System.out.println(1-e != 1);
        }
      }
      

      The output is:

      % java Eps
      5.551115123125784E-17
      0.9999999999999999
      true
      

      This proves, that there are smaller positive numbers with the property that 1-eps != 1.

      I propose not to change the constant value, but to update the documentation. The value Precision.EPSILON is
      an upper bound on the relative error which occurs when a real number is
      rounded to its nearest Double floating-point number. I propose to update
      the api docs in this sense.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dgruntz Dominik Gruntz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified