// -*- mode: C++; tab-width: 4; indent-tabs-mode: t; -*- vim:ts=4:sw=4 // // Copyright(c) Chong Kai Xiong (descender) // // This file is part of The Plains of Usata. // // The Plains of Usata is licensed under the GNU General Public // License (GPL) version 2. For details, please see the COPYING file // included in the software distribution, or visit // http://www.fsf.org/licenses/gpl.html. // // $Id: policy.hpp,v 1.1 2005/01/04 15:29:21 Descender Exp $ #ifndef USATA_MATH_POLICY_HPP #define USATA_MATH_POLICY_HPP #include namespace usata { namespace math { //! \ingroup math //! \brief Policy class for scalar operations //! \param T Scalar type template struct ScalarPolicy { //! \brief Equality operator //! \param[in] lhs Left operand. //! \param[in] rhs Right operand. //! \return Equality. static bool equal_to(T lhs, T rhs) { return lhs == rhs; } }; //! \ingroup math //! \brief Policy class for float operations template <> struct ScalarPolicy { //! \brief Tolerance margin //! \note This will cause problems when working with large //! values due to the nature of the floating point //! representation. Expressing the margin in percentage //! is much better. static float margin; //! \brief Equality operator //! \param[in] lhs Left operand. //! \param[in] rhs Right operand. //! \return Equality. static bool equal_to(float lhs, float rhs) { return std::abs(lhs - rhs) <= margin; } }; static ScalarPolicy::margin = 0.001; } } #endif