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
13namespace storm {
14namespace utility {
15
16template<typename ValueType>
17ConstantsComparator<ValueType>::ConstantsComparator(ValueType const& precision, bool relative) : precision(precision), relative(relative) {
18 // Intentionally left empty
19}
20
21template<typename ValueType>
22bool ConstantsComparator<ValueType>::isOne(ValueType const& value) const {
23 return isEqual(value, storm::utility::one<ValueType>());
24}
25
26template<typename ValueType>
27bool ConstantsComparator<ValueType>::isZero(ValueType const& value) const {
28 return isEqual(value, storm::utility::zero<ValueType>());
29}
30
31template<typename ValueType>
32bool ConstantsComparator<ValueType>::isEqual(ValueType const& value1, ValueType const& value2) const {
33 if (std::is_same<ValueType, storm::RationalFunction>() || std::is_same<ValueType, storm::Polynomial>()) {
34 STORM_LOG_ASSERT(storm::utility::isZero(precision), "Precision for rational functions must be zero.");
35 return value1 == value2;
36 } else {
37 if (value1 == value2) {
38 return true;
39 } else if (storm::utility::isZero(precision)) {
40 return false;
41 } else {
42 return storm::utility::isApproxEqual(value1, value2, precision, relative);
43 }
44 }
45}
46
47template<typename ValueType>
48bool ConstantsComparator<ValueType>::isLess(ValueType const& value1, ValueType const& value2) const {
49 STORM_LOG_ASSERT(!relative, "Relative precision and constants comparator is currently not supported.");
50 return value1 < value2 - precision;
51}
52
53// Explicit instantiations.
54template class ConstantsComparator<double>;
55template class ConstantsComparator<int>;
57
58#if defined(STORM_HAVE_CLN)
60#endif
61
62#if defined(STORM_HAVE_GMP)
64#endif
65
68} // namespace utility
69} // 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:54
bool isZero(ValueType const &a)
Definition constants.cpp:39