maths: add relatively_equal comparator
This commit is contained in:
parent
84f8600f85
commit
5d02171a6f
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2010-2014 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2010-2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef __MATHS_HPP
|
||||
@ -81,6 +81,13 @@ namespace util {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Comparisons
|
||||
inline bool
|
||||
relatively_equal (float a, float b, float percentage)
|
||||
{
|
||||
return std::abs (1 - b / a ) < percentage;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
inline bool
|
||||
almost_equal (float a, float b)
|
||||
{
|
||||
return ieee_single::almost_equal (a, b);
|
||||
|
Loading…
Reference in New Issue
Block a user