Mantid
Loading...
Searching...
No Matches
FloatingPointComparison.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//-----------------------------------------------------------------------------
8// Includes
9//-----------------------------------------------------------------------------
11#include "MantidKernel/System.h"
12
13#include <cmath>
14#include <limits>
15
16namespace Mantid::Kernel {
17
26template <typename TYPE> bool equals(const TYPE x, const TYPE y) {
27 return !(std::fabs(x - y) > std::numeric_limits<TYPE>::epsilon());
28}
29
38template <typename T> MANTID_KERNEL_DLL bool ltEquals(const T x, const T y) { return (equals(x, y) || x < y); }
39
48template <typename T> MANTID_KERNEL_DLL bool gtEquals(const T x, const T y) { return (equals(x, y) || x > y); }
49
51// Concrete instantiations
52template DLLExport bool equals<double>(const double, const double);
53template DLLExport bool equals<float>(const float, const float);
54template DLLExport bool ltEquals<double>(const double, const double);
55template DLLExport bool ltEquals<float>(const float, const float);
56template DLLExport bool gtEquals<double>(const double, const double);
57template DLLExport bool gtEquals<float>(const float, const float);
59} // namespace Mantid::Kernel
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
MANTID_KERNEL_DLL bool equals(const T x, const T y)
Test for equality of doubles using compiler-defined precision.
MANTID_KERNEL_DLL bool ltEquals(const T x, const T y)
Test whether x<=y within machine precision.
MANTID_KERNEL_DLL bool gtEquals(const T x, const T y)
Test whether x>=y within machine precision.