iterative-solver 0.0
scalar_traits.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_SCALAR_TRAITS_H_
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_SCALAR_TRAITS_H_
3
12#include <complex>
13#include <limits>
14#include <type_traits>
15
16namespace molpro::linalg {
17
18template <typename T>
19struct is_complex : std::false_type {};
20
21template <typename T>
22struct is_complex<std::complex<T>> : std::true_type {};
23
25template <typename T>
26struct real_type {
27 using type = T;
28};
29
30template <typename T>
31struct real_type<std::complex<T>> {
32 using type = T;
33};
34
42template <typename T>
44
53template <typename value_type>
54real_type_t<value_type> precision_scaled(double tolerance_for_double) {
55 using real_t = real_type_t<value_type>;
56 if constexpr (std::is_same_v<real_t, double>) {
57 return tolerance_for_double;
58 } else {
59 return real_t(tolerance_for_double) *
60 (std::numeric_limits<real_t>::epsilon() / real_t(std::numeric_limits<double>::epsilon()));
61 }
62}
63
64} // namespace molpro::linalg
65
66#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_SCALAR_TRAITS_H_
Definition: helper.h:14
typename real_type< T >::type real_type_t
The real type underlying T, i.e. T itself for a real type and U for std::complex<U>.
Definition: scalar_traits.h:43
real_type_t< value_type > precision_scaled(double tolerance_for_double)
Rescale a tolerance that was calibrated for IEEE double precision to the working precision.
Definition: scalar_traits.h:54
Definition: scalar_traits.h:19
T type
Definition: scalar_traits.h:32
The real type underlying a (possibly complex) scalar type.
Definition: scalar_traits.h:26
T type
Definition: scalar_traits.h:27