15 #ifndef ECL_MATH_FUZZY_HPP_
16 #define ECL_MATH_FUZZY_HPP_
36 namespace implementations {
47 template<
typename Scalar,
49 struct scalar_fuzzy_default_impl {};
56 template<
typename Scalar>
57 struct scalar_fuzzy_default_impl<Scalar, false>
61 template<
typename OtherScalar>
62 static inline bool isApprox(
const Scalar& x,
const OtherScalar& y,
const Precision& prec) {
64 return std::abs(x -
static_cast<Scalar
>(y)) <= std::min( std::abs(x), std::abs(
static_cast<Scalar
>(y))) * prec;
67 template<
typename OtherScalar>
68 static inline bool isApproxOrLessThan(
const Scalar& x,
const OtherScalar& y,
const Precision& prec) {
69 return x <= y ||
isApprox(x, y, prec);
78 template<
typename Scalar>
79 struct scalar_fuzzy_default_impl<Scalar, true> {
83 template<
typename OtherScalar>
84 static inline bool isApprox(
const Scalar& x,
const OtherScalar& y,
const Precision& prec) {
94 precision =
static_cast<OtherScalar
>(prec);
96 return std::abs(
static_cast<OtherScalar
>(x) - y) <= std::min( std::abs(
static_cast<OtherScalar
>(x)), std::abs(y)) * precision;
99 template<
typename OtherScalar>
100 static inline bool isApproxOrLessThan(
const Scalar& x,
const OtherScalar& y,
const Precision&) {
128 template<
typename Scalar>
129 struct scalar_fuzzy_impl : implementations::scalar_fuzzy_default_impl<Scalar, numeric_limits<Scalar>::is_integer> {};
153 template<
typename Scalar,
typename OtherScalar>
154 inline bool isApprox(
const Scalar& x,
const OtherScalar& y,
typename numeric_limits<Scalar>::Precision precision = numeric_limits<Scalar>::dummy_precision) {
171 template<
typename Scalar,
typename OtherScalar>
172 inline bool isApproxOrLessThan(
const Scalar& x,
const OtherScalar& y,
typename numeric_limits<Scalar>::Precision precision = numeric_limits<Scalar>::dummy_precision) {