Java Epsilon epsilonFloor(double d)

Here you can find the source of epsilonFloor(double d)

Description

protect the floor function from the vagaries of floating point precision.

License

Open Source License

Parameter

Parameter Description
d the double that we would like the floor value for

Return

the floor after adding epsilon

Declaration

public static double epsilonFloor(double d) 

Method Source Code

//package com.java2s;
/*// w  ww.  j  av  a2s  .c o m
 * Copyright 2002 (C) Bryan McRoberts <merton_monk@yahoo.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 */

public class Main {
    static final private double epsilon = 0.0001d;

    /**
     * protect the floor function from the vagaries of floating point precision.
     * @param d the double that we would like the floor value for
     * @return the floor after adding epsilon
     */
    public static double epsilonFloor(double d) {
        return Math.floor(d + epsilon);
    }
}

Related

  1. epsilonEquals(final double a, final double b, final double epsilon)
  2. epsilonEquals(final float x, final float y)
  3. epsilonEquals(float f1, float f2, float epsilon)
  4. epsilonEquals(float p_180185_0_, float p_180185_1_)
  5. epsilonEquals(float v1, float v2)
  6. epsilonZero(double input)