approximately Equals - Android java.lang

Android examples for java.lang:Float

Description

approximately Equals

Demo Code


//package com.java2s;

public class Main {
    public static boolean approximatelyEquals(float input, float target,
            float tolerance) {
        tolerance = Math.abs(tolerance);
        return input <= target + tolerance && input >= target - tolerance;
    }// w  w w.  ja v  a2s. c o  m

    public static boolean approximatelyEquals(int input, int target,
            int tolerance) {
        tolerance = Math.abs(tolerance);
        return input <= target + tolerance && input >= target - tolerance;
    }

    public static boolean approximatelyEquals(long input, long target,
            long tolerance) {
        tolerance = Math.abs(tolerance);
        return input <= target + tolerance && input >= target - tolerance;
    }
}

Related Tutorials