ad_physics
DurationSquaredValidInputRange.hpp
Go to the documentation of this file.
1 /*
2  * ----------------- BEGIN LICENSE BLOCK ---------------------------------
3  *
4  * Copyright (C) 2018-2020 Intel Corporation
5  *
6  * SPDX-License-Identifier: MIT
7  *
8  * ----------------- END LICENSE BLOCK -----------------------------------
9  */
10 
18 #pragma once
19 
20 #include <cmath>
21 #include <limits>
23 #include "spdlog/fmt/ostr.h"
24 #include "spdlog/spdlog.h"
25 
39 inline bool withinValidInputRange(::ad::physics::DurationSquared const &input, bool const logErrors = true)
40 {
41  // check for generic numeric limits of the type
42  bool inValidInputRange = input.isValid() && (std::numeric_limits<::ad::physics::DurationSquared>::lowest() <= input)
44  if (!inValidInputRange && logErrors)
45  {
46  spdlog::error("withinValidInputRange(::ad::physics::DurationSquared)>> {} out of numerical limits [{}, {}]",
47  input,
50  }
51  // check for individual input range
52  if (inValidInputRange)
53  {
54  inValidInputRange
55  = (::ad::physics::DurationSquared(0.) <= input) && (input <= ::ad::physics::DurationSquared(10000.));
56  if (!inValidInputRange && logErrors)
57  {
58  spdlog::error("withinValidInputRange(::ad::physics::DurationSquared)>> {} out of valid input range [{}, {}]",
59  input,
61  ::ad::physics::DurationSquared(10000.)); // LCOV_EXCL_BR_LINE
62  }
63  }
64  return inValidInputRange;
65 }
std::numeric_limits<::ad::physics::DurationSquared >::lowest
static inline ::ad::physics::DurationSquared lowest()
Definition: DurationSquared.hpp:509
ad::physics::DurationSquared::isValid
bool isValid() const
Definition: DurationSquared.hpp:390
ad::physics::DurationSquared
DataType DurationSquared.
Definition: DurationSquared.hpp:67
withinValidInputRange
bool withinValidInputRange(::ad::physics::DurationSquared const &input, bool const logErrors=true)
check if the given DurationSquared is within valid input range
Definition: DurationSquaredValidInputRange.hpp:39
std::numeric_limits<::ad::physics::DurationSquared >::max
static inline ::ad::physics::DurationSquared max()
Definition: DurationSquared.hpp:516
DurationSquared.hpp