tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
norm.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_COMPLEX_NORM_HPP
5#define TETL_COMPLEX_NORM_HPP
6
7#include <etl/_complex/complex.hpp>
8#include <etl/_concepts/floating_point.hpp>
9#include <etl/_concepts/integral.hpp>
10
11namespace etl {
12
13/// \ingroup complex
14template <typename T>
15[[nodiscard]] constexpr auto norm(complex<T> const& z) noexcept -> T
16{
17 auto const x = z.real();
18 auto const y = z.imag();
19 return x * x + y * y;
20}
21
22/// \ingroup complex
23template <floating_point Float>
24[[nodiscard]] constexpr auto norm(Float f) noexcept -> complex<Float>
25{
26 return etl::norm(etl::complex<Float>(f));
27}
28
29/// \ingroup complex
30template <integral Integer>
31[[nodiscard]] constexpr auto norm(Integer i) noexcept -> complex<double>
32{
33 return etl::norm(etl::complex<double>(i));
34}
35
36} // namespace etl
37
38#endif // TETL_COMPLEX_NORM_HPP
constexpr auto norm(complex< T > const &z) noexcept -> T
Definition norm.hpp:15
constexpr auto norm(Integer i) noexcept -> complex< double >
Definition norm.hpp:31
constexpr auto norm(Float f) noexcept -> complex< Float >
Definition norm.hpp:24
Definition adjacent_find.hpp:9
A complex number.
Definition complex.hpp:20