/*
This file is part of [PROGRAM NAME] - [What it does in brief]
Copyright (c) 2001 [Author]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
/**
 *  Description of the Class
 *
 * @author     Marc Champesme
 * @version    24 avril 2004
 */
public strictfp class GMath {

	/**
	 *  Description of the Field
	 */
	public final static double EPSILON_DEFAUT = 1.0e-4;

	private static double epsilon = EPSILON_DEFAUT;


	/**
	 *  Sets the epsilon attribute of the GMath class
	 *
	 * @param  epsilon  The new epsilon value
	 */
	/*@
	  @ ensures getEpsilon() == epsilon;
	  @
	  @*/
	public static void setEpsilon(double epsilon) {
		GMath.epsilon = epsilon;
	}// -- setEpsilon()


	/**
	 *  Gets the epsilon attribute of the GMath class
	 *
	 * @return    The epsilon value
	 */
	//@ pure
	public static double getEpsilon() {
		return epsilon;
	}// -- getEpsilon()


	/**
	 *  Description of the Method
	 *
	 * @param  d1  Description of the Parameter
	 * @param  d2  Description of the Parameter
	 * @return     Description of the Return Value
	 */
	/*@
          @ ensures \result <==> epsEquals(d1, d2, getEpsilon());
	  @ pure
          @*/
	public static boolean epsEquals(double d1, double d2) {

		return epsEquals(d1, d2, getEpsilon());
	}// -- epsEquals()


	/**
	 *  Tell whether relative difference of the two arguments is within
	 *  the given epsilon.
	 *
	 * @param  d1   Description of the Parameter
	 * @param  d2   Description of the Parameter
	 * @param  eps  Description of the Parameter
	 * @return      Description of the Return Value
	 */
	/*@
          @ ensures \result <==>
          @      d1 == d2
          @      || StrictMath.abs(\nowarn(d1 - d2))
          @            <= StrictMath.max(StrictMath.abs(d1),
          @                              StrictMath.abs(d2))
          @               * epsilon;
	  @ pure
          @*/
	public static boolean epsEquals(double d1, double d2, double epsilon) {
		return (d1 == d2)
				 || (StrictMath.abs(d1 - d2)
				 <= StrictMath.max(StrictMath.abs(d1),
				StrictMath.abs(d2))
				 * epsilon);
	}// -- epsEquals()


}// -- end class GMath

