Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ConstantsComparator.cpp
Go to the documentation of this file.
2
3#include <type_traits>
4
10
11namespace storm {
12namespace utility {
14template<typename ValueType>
15ConstantsComparator<ValueType>::ConstantsComparator(ValueType const& precision, bool relative) : precision(precision), relative(relative) {
16 // Intentionally left empty
17}
18
19template<typename ValueType>
20bool ConstantsComparator<ValueType>::isOne(ValueType const& value) const {
21 return isEqual(value, storm::utility::one<ValueType>());
22}
23
24template<typename ValueType>
25bool ConstantsComparator<ValueType>::isZero(ValueType const& value) const {
26 return isEqual(value, storm::utility::zero<ValueType>());
27}
28
29template<typename ValueType>
30bool ConstantsComparator<ValueType>::isEqual(ValueType const& value1, ValueType const& value2) const {
31 if (std::is_same<ValueType, storm::RationalFunction>() || std::is_same<ValueType, storm::Polynomial>()) {
32 STORM_LOG_ASSERT(storm::utility::isZero(precision), "Precision for rational functions must be zero.");
33 return value1 == value2;
34 } else {
35 if (value1 == value2) {
36 return true;
37 } else if (storm::utility::isZero(precision)) {
38 return false;
39 } else {
40 return storm::utility::isApproxEqual(value1, value2, precision, relative);
41 }
42 }
43}
44
45template<typename ValueType>
46bool ConstantsComparator<ValueType>::isLess(ValueType const& value1, ValueType const& value2) const {
47 STORM_LOG_ASSERT(!relative, "Relative precision and constants comparator is currently not supported.");
48 return value1 < value2 - precision;
49}
50
51// Explicit instantiations.
52template class ConstantsComparator<double>;
53template class ConstantsComparator<int>;
55
56#if defined(STORM_HAVE_CLN)
58#endif
59
60#if defined(STORM_HAVE_GMP)
62#endif
63
66} // namespace utility
67} // namespace storm
bool isLess(ValueType const &value1, ValueType const &value2) const
bool isOne(ValueType const &value) const
ConstantsComparator(ValueType const &precision, bool relative=false)
bool isZero(ValueType const &value) const
bool isEqual(ValueType const &value1, ValueType const &value2) const
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
bool isApproxEqual(ValueType const &a, ValueType const &b, ValueType const &precision, bool relative)
Definition constants.cpp:53
bool isZero(ValueType const &a)
Definition constants.cpp:38