3#ifndef TETL_CMATH_LRINT_HPP
4#define TETL_CMATH_LRINT_HPP
6#include <etl/_config/all.hpp>
8#include <etl/_concepts/integral.hpp>
9#include <etl/_type_traits/is_constant_evaluated.hpp>
10#include <etl/_type_traits/is_same.hpp>
15template <
typename T,
typename U>
16[[nodiscard]]
constexpr auto lrint_fallback(U arg)
noexcept -> T
18 return static_cast<T>(arg);
22[[nodiscard]]
constexpr auto lrint_impl(T arg)
noexcept ->
long
25 if constexpr (is_same_v<T,
float>) {
26#if __has_builtin(__builtin_lrintf)
27 return __builtin_lrintf(arg);
30 if constexpr (is_same_v<T,
double>) {
31#if __has_builtin(__builtin_lrint)
32 return __builtin_lrint(arg);
35 if constexpr (is_same_v<T,
long double>) {
36#if __has_builtin(__builtin_lrintl)
37 return __builtin_lrintl(arg);
41 return lrint_fallback<
long>(arg);
45[[nodiscard]]
constexpr auto llrint_impl(T arg)
noexcept ->
long long
48 if constexpr (is_same_v<T,
float>) {
49#if __has_builtin(__builtin_llrintf)
50 return __builtin_llrintf(arg);
53 if constexpr (is_same_v<T,
double>) {
54#if __has_builtin(__builtin_llrint)
55 return __builtin_llrint(arg);
58 if constexpr (is_same_v<T,
long double>) {
59#if __has_builtin(__builtin_llrintl)
60 return __builtin_llrintl(arg);
64 return lrint_fallback<
long long>(arg);
73 return detail::lrint_impl(arg);
80 return detail::lrint_impl(arg);
87 return detail::lrint_impl(arg);
94 return detail::lrint_impl(arg);
101 return detail::lrint_impl(arg);
107[[nodiscard]]
constexpr auto lrint(T arg)
noexcept ->
long
109 return lrint(static_cast<
double>(arg)
);
116 return detail::llrint_impl(arg);
123 return detail::llrint_impl(arg);
130 return detail::llrint_impl(arg);
137 return detail::llrint_impl(arg);
144 return detail::llrint_impl(arg);
150[[nodiscard]]
constexpr auto llrint(T arg)
noexcept ->
long long
152 return llrint(static_cast<
double>(arg)
);
constexpr auto llrintf(float arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:121
constexpr auto llrint(double arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:128
constexpr auto llrintl(long double arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:142
constexpr auto lrintf(float arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:78
constexpr auto lrint(double arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:85
constexpr auto lrint(long double arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:92
constexpr auto llrint(float arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:114
constexpr auto lrint(T arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:107
constexpr auto llrint(T arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:150
constexpr auto lrint(float arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:71
constexpr auto lrintl(long double arg) noexcept -> long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:99
constexpr auto llrint(long double arg) noexcept -> long long
Rounds the floating-point argument arg to an integer value, using the current rounding mode.
Definition lrint.hpp:135
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