From 1b19b28a0db4ec242af21b52ce5092b716c69482 Mon Sep 17 00:00:00 2001 From: Stefan Pranger Date: Mon, 15 Mar 2021 23:43:58 +0100 Subject: [PATCH] added less-/greater-equal utility functions --- src/storm/utility/constants.h | 74 ++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/src/storm/utility/constants.h b/src/storm/utility/constants.h index e5fceec44..f381a0555 100644 --- a/src/storm/utility/constants.h +++ b/src/storm/utility/constants.h @@ -24,7 +24,7 @@ namespace storm { namespace storage { template class MatrixEntry; } - + template struct NumberTraits; @@ -35,41 +35,79 @@ namespace storm { struct ElementLess { typedef std::less type; }; - + struct DoubleLess { bool operator()(double a, double b) const { return (a == 0.0 && b > 0.0) || (b - a > 1e-17); } }; - + template<> struct ElementLess { typedef DoubleLess type; }; + template + struct ElementLessEqual { + typedef std::less_equal type; + }; + + struct DoubleLessEqual { + bool operator()(double a, double b) const { + return (a == 0.0 && b >= 0.0) || (b - a >= 1e-17); + } + }; + + template<> + struct ElementLessEqual { + typedef DoubleLessEqual type; + }; + template struct ElementGreater { typedef std::greater type; }; - + struct DoubleGreater { bool operator()(double a, double b) const { return (b == 0.0 && a > 0.0) || (a - b > 1e-17); } }; - + template<> struct ElementGreater { typedef DoubleGreater type; }; + + template + struct ElementGreaterEqual { + typedef std::greater_equal type; + }; + + struct DoubleGreaterEqual { + bool operator()(double a, double b) const { + return (b == 0.0 && a >= 0.0) || (a - b >= 1e-17); + } + }; + + template<> + struct ElementGreaterEqual { + typedef DoubleGreaterEqual type; + }; } - + template using ElementLess = typename detail::ElementLess::type; template using ElementGreater = typename detail::ElementGreater::type; + template + using ElementLessEqual = typename detail::ElementLessEqual::type; + + template + using ElementGreaterEqual = typename detail::ElementGreaterEqual::type; + template ValueType one(); @@ -84,7 +122,7 @@ namespace storm { template bool isZero(ValueType const& a); - + template bool isNan(ValueType const& a); @@ -93,7 +131,7 @@ namespace storm { template bool isAlmostOne(ValueType const& a); - + template bool isConstant(ValueType const& a); @@ -105,7 +143,7 @@ namespace storm { template TargetType convertNumber(SourceType const& number); - + template std::pair asFraction(ValueType const& number); @@ -114,28 +152,28 @@ namespace storm { template storm::storage::MatrixEntry& simplify(storm::storage::MatrixEntry& matrixEntry); - + template storm::storage::MatrixEntry&& simplify(storm::storage::MatrixEntry&& matrixEntry); template std::pair minmax(std::vector const& values); - + template ValueType minimum(std::vector const& values); - + template ValueType maximum(std::vector const& values); - + template< typename K, typename ValueType> std::pair minmax(std::map const& values); - + template< typename K, typename ValueType> ValueType minimum(std::map const& values); - + template ValueType maximum(std::map const& values); - + template ValueType pow(ValueType const& value, int_fast64_t exponent); @@ -147,7 +185,7 @@ namespace storm { template ValueType sqrt(ValueType const& number); - + template ValueType abs(ValueType const& number); @@ -183,7 +221,7 @@ namespace storm { template IntegerType mod(IntegerType const& first, IntegerType const& second); - + template std::string to_string(ValueType const& value); }