<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lapy2.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
7//
8// This file is part of <T>LAPACK.
9// <T>LAPACK is free software: you can redistribute it and/or modify it under
10// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
11
12#ifndef TLAPACK_LAPY2_HH
13#define TLAPACK_LAPY2_HH
14
15namespace tlapack {
16
26template <TLAPACK_REAL TX,
27 TLAPACK_REAL TY,
28 enable_if_t<(
29 /* Requires: */
30 is_real<TX> && is_real<TY>),
31 int> = 0>
32real_type<TX, TY> lapy2(const TX& x, const TY& y)
33{
34 // using
36
37 // constants
38 const real_t one(1);
39 const real_t zero(0);
40 const TX xabs = abs(x);
41 const TY yabs = abs(y);
42
43 real_t w, z;
44 if (xabs > yabs) {
45 w = xabs;
46 z = yabs;
47 }
48 else {
49 w = yabs;
50 z = xabs;
51 }
52
53 return (z == zero) ? w : w * sqrt(one + (z / w) * (z / w));
54}
55
56} // namespace tlapack
57
58#endif // TLAPACK_LAPY2_HH
#define TLAPACK_REAL
Macro for tlapack::concepts::Real compatible with C++17.
Definition concepts.hpp:918
real_type< TX, TY > lapy2(const TX &x, const TY &y)
Finds , taking care not to cause unnecessary overflow.
Definition lapy2.hpp:32
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