org.mapfish.print.FloatingPointUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of print-lib Show documentation
Show all versions of print-lib Show documentation
Library for generating PDFs and images from online webmapping services
package org.mapfish.print;
/**
* Util class to test equality of floating points.
*/
public final class FloatingPointUtil {
private static final float EPSILON = 0.00000001F;
private FloatingPointUtil() {
}
/**
* Check the equality of two floats taking into consideration the precision issue of floating point
* arithmetic in Java.
*
* @param f1 Float 1.
* @param f2 Float 2.
* @return
*/
public static boolean equals(final float f1, final float f2) {
return Math.abs(f1 - f2) <= EPSILON;
}
/**
* Check the equality of two doubles taking into consideration the precision issue of floating point
* arithmetic in Java.
*
* @param d1 Double 1.
* @param d2 Double 2.
* @return
*/
public static boolean equals(final double d1, final double d2) {
return Math.abs(d1 - d2) <= EPSILON;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy