tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
hypot.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_HYPOT_HPP
4#define TETL_CMATH_HYPOT_HPP
5
6#include <etl/_config/all.hpp>
7
10#include <etl/_cmath/sqrt.hpp>
12
13namespace etl {
14
15namespace detail {
16
17inline constexpr struct hypot {
18 template <typename Float>
19 [[nodiscard]] constexpr auto operator()(Float x, Float y) const noexcept -> Float
20 {
21 if (etl::isinf(x) or etl::isinf(y)) {
23 }
24 if (etl::isnan(x) or etl::isnan(y)) {
26 }
27 return etl::sqrt(x * x + y * y);
28 }
29
30 template <typename Float>
31 [[nodiscard]] constexpr auto operator()(Float x, Float y, Float z) const noexcept -> Float
32 {
33 if (etl::isinf(x) or etl::isinf(y) or etl::isinf(z)) {
35 }
36 if (etl::isnan(x) or etl::isnan(y) or etl::isnan(z)) {
38 }
39 return etl::sqrt(x * x + y * y + z * z);
40 }
41
42} hypot;
43
44} // namespace detail
45
48
57[[nodiscard]] constexpr auto hypot(float x, float y) noexcept -> float { return etl::detail::hypot(x, y); }
58
59[[nodiscard]] constexpr auto hypotf(float x, float y) noexcept -> float { return etl::detail::hypot(x, y); }
60
61[[nodiscard]] constexpr auto hypot(double x, double y) noexcept -> double { return etl::detail::hypot(x, y); }
62
63[[nodiscard]] constexpr auto hypot(long double x, long double y) noexcept -> long double
64{
65 return etl::detail::hypot(x, y);
66}
67
68[[nodiscard]] constexpr auto hypotl(long double x, long double y) noexcept -> long double
69{
70 return etl::detail::hypot(x, y);
71}
72
73[[nodiscard]] constexpr auto hypot(float x, float y, float z) noexcept -> float { return etl::detail::hypot(x, y, z); }
74
75[[nodiscard]] constexpr auto hypot(double x, double y, double z) noexcept -> double
76{
77 return etl::detail::hypot(x, y, z);
78}
79
80[[nodiscard]] constexpr auto hypot(long double x, long double y, long double z) noexcept -> long double
81{
82 return etl::detail::hypot(x, y, z);
83}
84
86
87} // namespace etl
88
89#endif // TETL_CMATH_HYPOT_HPP
constexpr auto hypotf(float x, float y) noexcept -> float
Computes the square root of the sum of the squares of x and y, without undue overflow or underflow at...
Definition hypot.hpp:59
constexpr auto hypotl(long double x, long double y) noexcept -> long double
Computes the square root of the sum of the squares of x and y, without undue overflow or underflow at...
Definition hypot.hpp:68
constexpr auto sqrt(float arg) noexcept -> float
Computes the square root of arg.
Definition sqrt.hpp:14
constexpr auto hypot(float x, float y) noexcept -> float
Computes the square root of the sum of the squares of x and y, without undue overflow or underflow at...
Definition hypot.hpp:57
Definition adjacent_find.hpp:8
constexpr auto isinf(half arg) noexcept -> bool
Definition half.hpp:54
constexpr auto isnan(half arg) noexcept -> bool
Definition half.hpp:60
static constexpr auto infinity() noexcept -> T
Definition numeric_limits.hpp:46
static constexpr auto quiet_NaN() noexcept -> T
Definition numeric_limits.hpp:47