summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-19 20:45:04 +0300
committerVasile Vilvoiu <vasi@vilvoiu.ro>2021-07-19 20:45:04 +0300
commit78225142a8b3c0f95090b089eef32c244ed03551 (patch)
treebe9549960e69faedaf33c6af7d4044a93892c47f
parente7ae5b72e4dd261f7e2fa0bff56fe1971939da2b (diff)
ValueMap constructor sanity checks.
-rw-r--r--src/value-map.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/value-map.cpp b/src/value-map.cpp
index 8a547c4..2627ed3 100644
--- a/src/value-map.cpp
+++ b/src/value-map.cpp
@@ -5,9 +5,16 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#include "value-map.hpp"
+#include <cmath>
ValueMap::ValueMap(double lower, double upper, const std::string& unit) : lower_(lower), upper_(upper), unit_(unit)
{
+ if (std::isnan(lower) || std::isnan(upper) || std::isinf(lower) || std::isinf(upper)) {
+ throw std::runtime_error("bounds cannot be nan or inf");
+ }
+ if (lower > upper) {
+ throw std::runtime_error("lower bound cannot exceed upper bound");
+ }
}
std::string
@@ -71,4 +78,5 @@ RealWindow DecibelValueMap::Map(const RealWindow &input)
std::string DecibelValueMap::GetUnit() const
{
return "dB" + unit_;
-} \ No newline at end of file
+}
+