<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lapy3.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_LAPY3_HH
13#define TLAPACK_LAPY3_HH
14
16
17namespace tlapack {
18
31template <TLAPACK_REAL TX,
32 TLAPACK_REAL TY,
33 TLAPACK_REAL TZ,
34 enable_if_t<(
35 /* Requires: */
36 is_real<TX> && is_real<TY> && is_real<TZ>),
37 int> = 0>
38real_type<TX, TY, TZ> lapy3(const TX& x, const TY& y, const TZ& z)
39{
40 // using
42
43 // constants
44 const real_t zero(0);
45 const TX xabs = abs(x);
46 const TY yabs = abs(y);
47 const TZ zabs = abs(z);
48 const real_t w = max(xabs, max(yabs, zabs));
49
50 return (w == zero)
51 // W can be zero for max(0,nan,0)
52 // adding all three entries together will make sure
53 // NaN will not disappear.
54 ? xabs + yabs + zabs
55 : w * sqrt((xabs / w) * (xabs / w) + (yabs / w) * (yabs / w) +
56 (zabs / w) * (zabs / w));
57}
58
59} // namespace tlapack
60
61#endif // TLAPACK_LAPY3_HH
#define TLAPACK_REAL
Macro for tlapack::concepts::Real compatible with C++17.
Definition concepts.hpp:918
real_type< TX, TY, TZ > lapy3(const TX &x, const TY &y, const TZ &z)
Finds , taking care not to cause unnecessary overflow or unnecessary underflow.
Definition lapy3.hpp:38
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