Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ConstantsComparator.cpp
Go to the documentation of this file.
2
5
10
11namespace storm {
12namespace utility {
13
14template<typename ValueType, typename Enable>
15bool ConstantsComparator<ValueType, Enable>::isOne(ValueType const& value) const {
16 return isEqual(value, storm::utility::one<ValueType>());
19template<typename ValueType, typename Enable>
20bool ConstantsComparator<ValueType, Enable>::isZero(ValueType const& value) const {
21 return isEqual(value, storm::utility::zero<ValueType>());
22}
23
24template<typename ValueType, typename Enable>
25bool ConstantsComparator<ValueType, Enable>::isEqual(ValueType const& value1, ValueType const& value2) const {
26 return value1 == value2;
27}
28
29template<typename ValueType, typename Enable>
30bool ConstantsComparator<ValueType, Enable>::isConstant(ValueType const& value) const {
31 return storm::utility::isConstant(value);
32}
33
34template<typename ValueType, typename Enable>
35bool ConstantsComparator<ValueType, Enable>::isLess(ValueType const& value1, ValueType const& value2) const {
36 return value1 < value2;
37}
38
39template<typename ValueType>
42 storm::NumberTraits<ValueType>::IsExact
43 ? storm::utility::zero<ValueType>()
44 : storm::utility::convertNumber<ValueType>(storm::settings::getModule<storm::settings::modules::GeneralSettings>().getPrecision())) {
45 // Intentionally left empty
46}
47
48template<typename ValueType>
49ConstantsComparator<ValueType, ConstantsComparatorEnablePrecision<ValueType>>::ConstantsComparator(ValueType const& precision, bool const& relative)
50 : precision(precision), relative(relative) {
51 // Intentionally left empty
52}
53
54template<typename ValueType>
56 return isEqual(value, storm::utility::one<ValueType>());
57}
58
59template<typename ValueType>
61 return isEqual(value, storm::utility::zero<ValueType>());
62}
63
64template<typename ValueType>
65bool ConstantsComparator<ValueType, ConstantsComparatorEnablePrecision<ValueType>>::isEqual(ValueType const& value1, ValueType const& value2) const {
66 if (value1 == value2) {
67 return true;
68 } else if (storm::utility::isZero(precision)) {
69 return false;
70 } else {
71 ValueType absDiff = storm::utility::abs<ValueType>(value1 - value2);
72 if (relative) {
73 return absDiff <= precision * (storm::utility::abs(value1) + storm::utility::abs(value2));
74 } else {
75 return absDiff <= precision;
76 }
77 }
78}
79
80template<typename ValueType>
84
85template<typename ValueType>
89
90template<typename ValueType>
91bool ConstantsComparator<ValueType, ConstantsComparatorEnablePrecision<ValueType>>::isLess(ValueType const& value1, ValueType const& value2) const {
92 return value1 < value2 - precision;
93}
94
95// Explicit instantiations.
96template class ConstantsComparator<double>;
97template class ConstantsComparator<int>;
99
100#ifdef STORM_HAVE_CARL
101#if defined(STORM_HAVE_CLN)
103#endif
104
105#if defined(STORM_HAVE_GMP)
107#endif
108
111template class ConstantsComparator<Interval>;
112#endif
113} // namespace utility
114} // namespace storm
bool isOne(ValueType const &value) const
bool isZero(ValueType const &value) const
bool isEqual(ValueType const &value1, ValueType const &value2) const
bool isConstant(ValueType const &value) const
bool isLess(ValueType const &value1, ValueType const &value2) const
bool isOne(ValueType const &a)
Definition constants.cpp:36
bool isConstant(ValueType const &)
Definition constants.cpp:66
bool isZero(ValueType const &a)
Definition constants.cpp:41
ValueType abs(ValueType const &number)
ValueType zero()
Definition constants.cpp:26
bool isInfinity(ValueType const &a)
Definition constants.cpp:71
TargetType convertNumber(SourceType const &number)
Definition constants.cpp:98
LabParser.cpp.
Definition cli.cpp:18