OTB  9.0.0
Orfeo Toolbox
otbNumericTraits.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef OtbNumericTraits_h
22 #define OtbNumericTraits_h
23 
24 #include <limits>
25 #include <cmath>
26 #include <type_traits>
27 #include <algorithm>
28 
29 namespace otb
30 {
31 
32 template <typename I, typename O>
33 constexpr auto common_lowest() {
34  using C = std::common_type_t<I,O>;
35  return
36  std::is_unsigned<I>::value ? I{}
37  : std::is_unsigned<O>::value ? O{}
38  : std::max<C>(
39  static_cast<C>(std::numeric_limits<I>::lowest()),
40  static_cast<C>(std::numeric_limits<O>::lowest())
41  );
42 }
43 
44 template <typename I, typename O>
45 constexpr auto common_highest() {
46  using C = std::common_type_t<I,O>;
47  return std::min<C>(
48  static_cast<C>(std::numeric_limits<I>::max()),
49  static_cast<C>(std::numeric_limits<O>::max()));
50 }
51 
52 } // Namespace otb
53 
54 #endif // OtbNumericTraits_h
otb::common_lowest
constexpr auto common_lowest()
Definition: otbNumericTraits.h:33
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::common_highest
constexpr auto common_highest()
Definition: otbNumericTraits.h:45