Skip to content
Snippets Groups Projects
Commit d9f05fa0 authored by Tim Keil's avatar Tim Keil
Browse files

[FloatCmp] Fix bug in FloatCmp::ge and ::le

parent 8d5fe824
No related branches found
No related tags found
No related merge requests found
......@@ -198,6 +198,100 @@ cmp_gt(const XType& xx, const YType& yy)
return true;
} // ... cmp_gt(...)
template <Dune::FloatCmp::CmpStyle style, class T>
typename std::enable_if<is_arithmetic<T>::value, bool>::type cmp_ge(const T& xx, const T& yy, const T& eps)
{
return std::greater<T>()(xx, yy) || Dune::FloatCmp::eq<T, style>(xx, yy, eps);
}
template <Dune::FloatCmp::CmpStyle style, class T>
bool cmp_ge(const std::complex<T>& xx, const std::complex<T>& yy, const T& eps)
{
return cmp_ge<style>(real(xx), real(yy), eps) && cmp_ge<style>(imag(xx), imag(yy), eps);
}
template <Dune::FloatCmp::CmpStyle style, class XType, class YType, class EpsType>
typename std::enable_if<is_vector<XType>::value && is_vector<YType>::value
&& std::is_same<typename VectorAbstraction<XType>::S, EpsType>::value
&& std::is_same<typename VectorAbstraction<YType>::S, EpsType>::value,
bool>::type
cmp_ge(const XType& xx, const YType& yy, const EpsType& eps)
{
const auto sz = xx.size();
if (yy.size() != sz)
return false;
for (size_t ii = 0; ii < sz; ++ii)
if (!(cmp_ge<style>(xx[ii], yy[ii], eps)))
return false;
return true;
} // ... cmp_ge(...)
template <Dune::FloatCmp::CmpStyle style, class XType, class YType, class EpsType>
typename std::enable_if<is_matrix<XType>::value && is_matrix<YType>::value
&& std::is_same<typename MatrixAbstraction<XType>::S, EpsType>::value
&& std::is_same<typename MatrixAbstraction<YType>::S, EpsType>::value,
bool>::type
cmp_ge(const XType& xx, const YType& yy, const EpsType& eps)
{
const auto rows = MatrixAbstraction<XType>::rows(xx);
const auto cols = MatrixAbstraction<XType>::cols(xx);
if (MatrixAbstraction<YType>::rows(yy) != rows || MatrixAbstraction<YType>::cols(yy) != cols)
return false;
for (size_t ii = 0; ii < rows; ++ii)
for (size_t jj = 0; jj < cols; ++jj)
if (!cmp_ge<style>(
MatrixAbstraction<XType>::get_entry(xx, ii, jj), MatrixAbstraction<YType>::get_entry(yy, ii, jj), eps))
return false;
return true;
} // ... cmp_ge(...)
template <Dune::FloatCmp::CmpStyle style, class T>
typename std::enable_if<is_arithmetic<T>::value, bool>::type cmp_le(const T& xx, const T& yy, const T& eps)
{
return std::less<T>()(xx, yy) || Dune::FloatCmp::eq<T, style>(xx, yy, eps);
}
template <Dune::FloatCmp::CmpStyle style, class T>
bool cmp_le(const std::complex<T>& xx, const std::complex<T>& yy, const T& eps)
{
return cmp_le<style>(real(xx), real(yy), eps) && cmp_le<style>(imag(xx), imag(yy), eps);
}
template <Dune::FloatCmp::CmpStyle style, class XType, class YType, class EpsType>
typename std::enable_if<is_vector<XType>::value && is_vector<YType>::value
&& std::is_same<typename VectorAbstraction<XType>::S, EpsType>::value
&& std::is_same<typename VectorAbstraction<YType>::S, EpsType>::value,
bool>::type
cmp_le(const XType& xx, const YType& yy, const EpsType& eps)
{
const auto sz = xx.size();
if (yy.size() != sz)
return false;
for (size_t ii = 0; ii < sz; ++ii)
if (!(cmp_le<style>(xx[ii], yy[ii], eps)))
return false;
return true;
} // ... cmp_le(...)
template <Dune::FloatCmp::CmpStyle style, class XType, class YType, class EpsType>
typename std::enable_if<is_matrix<XType>::value && is_matrix<YType>::value
&& std::is_same<typename MatrixAbstraction<XType>::S, EpsType>::value
&& std::is_same<typename MatrixAbstraction<YType>::S, EpsType>::value,
bool>::type
cmp_le(const XType& xx, const YType& yy, const EpsType& eps)
{
const auto rows = MatrixAbstraction<XType>::rows(xx);
const auto cols = MatrixAbstraction<XType>::cols(xx);
if (MatrixAbstraction<YType>::rows(yy) != rows || MatrixAbstraction<YType>::cols(yy) != cols)
return false;
for (size_t ii = 0; ii < rows; ++ii)
for (size_t jj = 0; jj < cols; ++jj)
if (!cmp_le<style>(
MatrixAbstraction<XType>::get_entry(xx, ii, jj), MatrixAbstraction<YType>::get_entry(yy, ii, jj), eps))
return false;
return true;
} // ... cmp_le(...)
template <class T>
typename std::enable_if<is_arithmetic<T>::value, bool>::type cmp_lt(const T& xx, const T& yy)
{
......@@ -245,7 +339,6 @@ cmp_lt(const XType& xx, const YType& yy)
return true;
} // ... cmp_gt(...)
template <class FirstType, class SecondType, class ToleranceType, Style style>
struct Call
{
......@@ -271,12 +364,12 @@ struct Call
static bool ge(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& /**/)
{
return dune_float_cmp_eq<internal::ConvertStyle<style>::value>(first, second, rtol) || cmp_gt(first, second);
return cmp_ge<internal::ConvertStyle<style>::value>(first, second, rtol);
}
static bool le(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& /**/)
{
return dune_float_cmp_eq<internal::ConvertStyle<style>::value>(first, second, rtol) || cmp_lt(first, second);
return cmp_le<internal::ConvertStyle<style>::value>(first, second, rtol);
}
};
......@@ -303,14 +396,14 @@ struct Call<FirstType, SecondType, ToleranceType, Style::numpy>
return !float_cmp_eq(first, second, rtol, atol) && cmp_lt(first, second);
}
static bool ge(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& atol)
static bool ge(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& /**/)
{
return float_cmp_eq(first, second, rtol, atol) || cmp_gt(first, second);
return cmp_ge(first, second, rtol);
}
static bool le(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& atol)
static bool le(const FirstType& first, const SecondType& second, const ToleranceType& rtol, const ToleranceType& /**/)
{
return float_cmp_eq(first, second, rtol, atol) || cmp_lt(first, second);
return cmp_le(first, second, rtol);
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment