tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
sqrt.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_CMATH_SQRT_HPP
5#define TETL_CMATH_SQRT_HPP
6
7#include <etl/_3rd_party/gcem/gcem.hpp>
8#include <etl/_concepts/integral.hpp>
9#include <etl/_concepts/same_as.hpp>
10#include <etl/_type_traits/is_constant_evaluated.hpp>
11
12namespace etl {
13
14namespace detail {
15
16inline constexpr struct sqrt {
17 template <typename Float>
18 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
19 {
21#if __has_builtin(__builtin_sqrtf)
22 if constexpr (etl::same_as<Float, float>) {
23 return __builtin_sqrtf(arg);
24 }
25#endif
26#if __has_builtin(__builtin_sqrt)
27 if constexpr (etl::same_as<Float, double>) {
28 return __builtin_sqrt(arg);
29 }
30#endif
31 }
32 return etl::detail::gcem::sqrt(arg);
33 }
34} sqrt;
35
36} // namespace detail
37
38/// \ingroup cmath
39/// @{
40
41/// Computes the square root of arg.
42/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
43[[nodiscard]] constexpr auto sqrt(float arg) noexcept -> float
44{
45 return etl::detail::sqrt(arg);
46}
47
48/// Computes the square root of arg.
49/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
50[[nodiscard]] constexpr auto sqrtf(float arg) noexcept -> float
51{
52 return etl::detail::sqrt(arg);
53}
54
55/// Computes the square root of arg.
56/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
57[[nodiscard]] constexpr auto sqrt(double arg) noexcept -> double
58{
59 return etl::detail::sqrt(arg);
60}
61
62/// Computes the square root of arg.
63/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
64[[nodiscard]] constexpr auto sqrt(long double arg) noexcept -> long double
65{
66 return etl::detail::sqrt(arg);
67}
68
69/// Computes the square root of arg.
70/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
71[[nodiscard]] constexpr auto sqrtl(long double arg) noexcept -> long double
72{
73 return etl::detail::sqrt(arg);
74}
75
76/// Computes the square root of arg.
77/// \details https://en.cppreference.com/w/cpp/numeric/math/sqrt
78template <integral T>
79[[nodiscard]] constexpr auto sqrt(T arg) noexcept -> double
80{
81 return etl::detail::sqrt(static_cast<double>(arg));
82}
83
84/// @}
85
86} // namespace etl
87
88#endif // TETL_CMATH_SQRT_HPP
constexpr auto sqrtl(long double arg) noexcept -> long double
Computes the square root of arg.
Definition sqrt.hpp:71
constexpr auto sqrt(long double arg) noexcept -> long double
Computes the square root of arg.
Definition sqrt.hpp:64
constexpr auto sqrt(T arg) noexcept -> double
Computes the square root of arg.
Definition sqrt.hpp:79
constexpr auto sqrt(double arg) noexcept -> double
Computes the square root of arg.
Definition sqrt.hpp:57
constexpr auto sqrtf(float arg) noexcept -> float
Computes the square root of arg.
Definition sqrt.hpp:50
constexpr auto sqrt(float arg) noexcept -> float
Definition sqrt.hpp:43
Definition adjacent_find.hpp:9
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:17