tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
round.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_ROUND_HPP
4#define TETL_CMATH_ROUND_HPP
5
6#include <etl/_config/all.hpp>
7
8#include <etl/_3rd_party/gcem/gcem.hpp>
12
13namespace etl {
14
15namespace detail {
16
17template <typename T>
18[[nodiscard]] constexpr auto round(T arg) noexcept -> T
19{
20 if (not is_constant_evaluated()) {
21 if constexpr (is_same_v<T, float>) {
22#if __has_builtin(__builtin_roundf)
23 return __builtin_roundf(arg);
24#endif
25 }
26 if constexpr (is_same_v<T, double>) {
27#if __has_builtin(__builtin_round)
28 return __builtin_round(arg);
29#endif
30 }
31 }
32 return detail::gcem::round(arg);
33}
34
35} // namespace detail
36
39
45[[nodiscard]] constexpr auto round(float arg) noexcept -> float { return etl::detail::round(arg); }
46[[nodiscard]] constexpr auto roundf(float arg) noexcept -> float { return etl::detail::round(arg); }
47[[nodiscard]] constexpr auto round(double arg) noexcept -> double { return etl::detail::round(arg); }
48[[nodiscard]] constexpr auto round(long double arg) noexcept -> long double { return etl::detail::round(arg); }
49[[nodiscard]] constexpr auto roundl(long double arg) noexcept -> long double { return etl::detail::round(arg); }
50[[nodiscard]] constexpr auto round(integral auto arg) noexcept -> double { return etl::detail::round(double(arg)); }
51
53
54} // namespace etl
55
56#endif // TETL_CMATH_ROUND_HPP
The concept integral<T> is satisfied if and only if T is an integral type.
Definition integral.hpp:13
constexpr auto roundf(float arg) noexcept -> float
Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away fro...
Definition round.hpp:46
constexpr auto round(float arg) noexcept -> float
Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away fro...
Definition round.hpp:45
constexpr auto roundl(long double arg) noexcept -> long double
Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away fro...
Definition round.hpp:49
constexpr auto arg(complex< T > const &z) noexcept -> T
Definition arg.hpp:15
Definition adjacent_find.hpp:8
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:16
constexpr bool is_same_v
Definition is_same.hpp:11