tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
floor.hpp
Go to the documentation of this file.
1
2// SPDX-License-Identifier: BSL-1.0
3
4#ifndef TETL_CMATH_FLOOR_HPP
5#define TETL_CMATH_FLOOR_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_3rd_party/gcem/gcem.hpp>
13
14namespace etl {
15
16namespace detail {
17
18inline constexpr struct floor {
19 template <typename Float>
20 [[nodiscard]] constexpr auto operator()(Float arg) const noexcept -> Float
21 {
22 if (not is_constant_evaluated()) {
23#if __has_builtin(__builtin_floorf)
24 if constexpr (etl::same_as<Float, float>) {
25 return __builtin_floorf(arg);
26 }
27#endif
28#if __has_builtin(__builtin_floor)
29 if constexpr (etl::same_as<Float, double>) {
30 return __builtin_floor(arg);
31 }
32#endif
33 }
34 return etl::detail::gcem::floor(arg);
35 }
36} floor;
37
38} // namespace detail
39
42
45[[nodiscard]] constexpr auto floor(float arg) noexcept -> float { return etl::detail::floor(arg); }
46[[nodiscard]] constexpr auto floorf(float arg) noexcept -> float { return etl::detail::floor(arg); }
47[[nodiscard]] constexpr auto floor(double arg) noexcept -> double { return etl::detail::floor(arg); }
48[[nodiscard]] constexpr auto floor(long double arg) noexcept -> long double { return etl::detail::gcem::floor(arg); }
49[[nodiscard]] constexpr auto floorl(long double arg) noexcept -> long double { return etl::detail::floor(arg); }
50[[nodiscard]] constexpr auto floor(integral auto arg) noexcept -> double { return etl::detail::floor(double(arg)); }
51
53
54} // namespace etl
55
56#endif // TETL_CMATH_FLOOR_HPP
The concept integral<T> is satisfied if and only if T is an integral type.
Definition integral.hpp:13
constexpr auto floorf(float arg) noexcept -> float
Computes the largest integer value not greater than arg.
Definition floor.hpp:46
constexpr auto floorl(long double arg) noexcept -> long double
Computes the largest integer value not greater than arg.
Definition floor.hpp:49
constexpr auto floor(float arg) noexcept -> float
Computes the largest integer value not greater than arg.
Definition floor.hpp:45
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