

package edu.uci.jforestsx.util;

/**
 * @author Yasser Ganjisaffar <ganjisaffar at gmail dot com>
 */

public class FloatingPointUtil {
	
	// The small deviation allowed in double comparisons
	public static double SMALL = 1e-6;

	public static boolean lessThanOrEqual(double a, double b) {
		return (a - b < SMALL);
	}

	public static boolean greaterThanOrEqual(double a, double b) {
		return (b - a < SMALL);
	}

	public static boolean lessThan(double a, double b) {
		return (b - a > SMALL);
	}

	public static boolean greaterThan(double a, double b) {
		return (a - b > SMALL);
	}
	
	public static boolean equal(double a, double b) {
		return (a - b < SMALL) && (b - a < SMALL);
	}
	
	public static boolean equal(double a, double b, double epsilon) {
		return (a - b < epsilon) && (b - a < epsilon);
	}
}
