Here you can find the source of floatEqual(float f1, float f2)
Parameter | Description |
---|---|
f1 | The first float to compare |
f2 | The second float to compare |
public static boolean floatEqual(float f1, float f2)
//package com.java2s; /*//from w w w . j a va 2s . c o m * Copyright 2011 Calytrix Technologies * * This file is part of Calytrix Disco. * * Calytrix Disco is free software; you can redistribute it and/or modify * it under the terms of the Common Developer and Distribution License (CDDL) * as published by Sun Microsystems. For more information see the LICENSE file. * * Use of this software is strictly AT YOUR OWN RISK!!! * If something bad happens you do not have permission to come crying to me. * (that goes for your lawyer as well) * */ public class Main { public static final double FP_EQUALITY_THRESHOLD = 1e-5; /** * Returns whether the two specified float value are equal. The two values * will be considered equal if the absolute difference between the values * is within a predefined threshold. * * @param f1 The first float to compare * @param f2 The second float to compare * * @return true if the two values are equal, otherwise false */ public static boolean floatEqual(float f1, float f2) { float absDiff = Math.abs(f1 - f2); return absDiff < FP_EQUALITY_THRESHOLD; } }