10#ifndef TLAPACK_RSCL_HH
11#define TLAPACK_RSCL_HH
21 enable_if_t<is_real<alpha_t>,
int> = 0>
74 enable_if_t<is_complex<alpha_t>,
int> = 0>
75void rscl(
const alpha_t& alpha, vector_t& x)
77 using real_t = real_type<alpha_t>;
79 const real_t safeMax = safe_max<real_t>();
80 const real_t safeMin = safe_min<real_t>();
84 const real_t alphaR = real(alpha);
85 const real_t alphaI = imag(alpha);
86 const real_t absR = abs(alphaR);
87 const real_t absI = abs(alphaI);
95 else if (alphaR == zero) {
100 scal(alpha_t(zero, -safeMax / alphaI), x);
102 else if (absI < safeMin) {
103 scal(alpha_t(zero, -safeMin / alphaI), x);
107 scal(alpha_t(zero, -one / alphaI), x);
118 real_t a = alphaR + alphaI * (alphaI / alphaR);
119 real_t b = alphaI + alphaR * (alphaR / alphaI);
121 if (abs(a) < safeMin || abs(b) < safeMin) {
123 scal(alpha_t(safeMin / a, -safeMin / b), x);
126 else if (abs(a) > safeMax || abs(b) > safeMax) {
130 scal(alpha_t(one / a, -one / b), x);
138 a = (safeMin * alphaR) +
139 safeMin * (alphaI * (alphaI / alphaR));
140 b = (safeMin * alphaI) +
141 alphaR * ((safeMin * alphaR) / alphaI);
145 a = (safeMin * alphaR) +
146 alphaI * ((safeMin * alphaI) / alphaR);
147 b = (safeMin * alphaI) +
148 safeMin * (alphaR * (alphaR / alphaI));
150 scal(alpha_t(one / a, -one / b), x);
153 scal(alpha_t(safeMax / a, -safeMax / b), x);
159 scal(alpha_t(one / a, -one / b), x);
constexpr bool isinf(const T &x) noexcept
Extends std::isinf() to complex numbers.
Definition utils.hpp:117
#define TLAPACK_COMPLEX
Macro for tlapack::concepts::Complex compatible with C++17.
Definition concepts.hpp:921
#define TLAPACK_VECTOR
Macro for tlapack::concepts::Vector compatible with C++17.
Definition concepts.hpp:906
#define TLAPACK_REAL
Macro for tlapack::concepts::Real compatible with C++17.
Definition concepts.hpp:918
void rscl(const alpha_t &alpha, vector_t &x)
Scale vector by the reciprocal of a constant, .
Definition rscl.hpp:22
void scal(const alpha_t &alpha, vector_t &x)
Scale vector by constant, .
Definition scal.hpp:30
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113