type_promotion.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #ifndef ECVL_TYPE_PROMOTION_H_
15 #define ECVL_TYPE_PROMOTION_H_
16 
17 #include <limits>
18 #include <type_traits>
19 
20 #include "ecvl/core/datatype.h"
21 
22 namespace ecvl {
23 
24 template<typename T, typename U>
26  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic");
27  static_assert(std::is_arithmetic<U>::value, "U must be arithmetic");
28  using type = typename std::conditional_t<(std::numeric_limits<T>::digits < std::numeric_limits<U>::digits), U, T>;
29 };
30 
31 template<typename T, typename U>
33 
34 
35 template<typename T, typename U>
37  using type = typename
38  std::conditional_t<std::is_floating_point<T>::value && std::is_floating_point<U>::value, larger_arithmetic_type_t<T, U>,
39  std::conditional_t<std::is_floating_point<T>::value, T,
40  std::conditional_t<std::is_floating_point<U>::value, U,
42 };
43 
44 template<typename T, typename U>
46 
47 
48 template<typename T, typename U>
51 
52  using type = typename
53  std::conditional_t<(sizeof(T) == 8u || sizeof(U) == 8u), double,
54  std::conditional_t<std::is_floating_point<superior_type>::value, superior_type,
55  std::conditional_t<(std::numeric_limits<superior_type>::digits < std::numeric_limits<std::int16_t>::digits), std::int16_t,
56  std::conditional_t<(std::numeric_limits<superior_type>::digits < std::numeric_limits<std::int32_t>::digits), std::int32_t,
57  std::conditional_t<(std::numeric_limits<superior_type>::digits < std::numeric_limits<std::int64_t>::digits), std::int64_t, double>>>>>;
58 };
59 
60 template<typename T, typename U>
62 
63 template<DataType DT, DataType DU>
65 
66 #define PROMOTE_OPERATION(op_name, op_symbol) \
67 template<typename T, typename U> \
68 promote_superior_type_t<T, U> Promote ## op_name(T lhs, U rhs) { \
69  using dsttype = promote_superior_type_t<T, U>; \
70  return static_cast<dsttype>(lhs) op_symbol static_cast<dsttype>(rhs); \
71 }
72 
77 
78 } // namespace ecvl
79 
80 #endif // ECVL_TYPE_PROMOTION_H_
void Mul(const Image &src1, const Image &src2, Image &dst, DataType dst_type=DataType::none, bool saturate=true)
Definition: arithmetic.h:122
typename promote_superior_type< T, U >::type promote_superior_type_t
typename std::conditional_t< std::is_floating_point< T >::value &&std::is_floating_point< U >::value, larger_arithmetic_type_t< T, U >, std::conditional_t< std::is_floating_point< T >::value, T, std::conditional_t< std::is_floating_point< U >::value, U, larger_arithmetic_type_t< T, U > >> > type
#define PROMOTE_OPERATION(op_name, op_symbol)
typename std::conditional_t<(sizeof(T)==8u||sizeof(U)==8u), double, std::conditional_t< std::is_floating_point< superior_type >::value, superior_type, std::conditional_t<(std::numeric_limits< superior_type >::digits< std::numeric_limits< std::int16_t >::digits), std::int16_t, std::conditional_t<(std::numeric_limits< superior_type >::digits< std::numeric_limits< std::int32_t >::digits), std::int32_t, std::conditional_t<(std::numeric_limits< superior_type >::digits< std::numeric_limits< std::int64_t >::digits), std::int64_t, double > >> >> type
void Add(const Image &src1, const Image &src2, Image &dst, DataType dst_type=DataType::none, bool saturate=true)
Adds two source Images storing the result into a destination Image.
Definition: arithmetic.h:69
void Sub(const Image &src1, const Image &src2, Image &dst, DataType dst_type=DataType::none, bool saturate=true)
Definition: arithmetic.h:118
typename TypeInfo< DT >::basetype TypeInfo_t
Definition: datatype.h:67
promote_superior_type_t< TypeInfo_t< DT >, TypeInfo_t< DU > > promote_superior_type_dt
typename larger_arithmetic_type< T, U >::type larger_arithmetic_type_t
void Div(const Image &src1, const Image &src2, Image &dst, DataType dst_type=DataType::none, bool saturate=true)
Definition: arithmetic.h:126
typename arithmetic_superior_type< T, U >::type arithmetic_superior_type_t
arithmetic_superior_type_t< T, U > superior_type
typename std::conditional_t<(std::numeric_limits< T >::digits< std::numeric_limits< U >::digits), U, T > type