tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
nextafter.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_NEXTAFTER_HPP
4#define TETL_CMATH_NEXTAFTER_HPP
5
10
11namespace etl {
12
13namespace detail {
14
15template <typename T>
16[[nodiscard]] constexpr auto nextafter(T from, T to) -> T
17{
18 using U = etl::conditional_t<sizeof(T) == 4U, etl::uint32_t, etl::uint64_t>;
19 auto const fromBits = etl::bit_cast<U>(from);
20 auto const toBits = etl::bit_cast<U>(to);
21 if (toBits == fromBits) {
22 return to;
23 }
24 if (toBits > fromBits) {
25 return etl::bit_cast<T>(fromBits + 1);
26 }
27 return etl::bit_cast<T>(fromBits - 1);
28}
29} // namespace detail
30
33
37[[nodiscard]] constexpr auto nextafter(float from, float to) noexcept -> float { return detail::nextafter(from, to); }
38[[nodiscard]] constexpr auto nextafterf(float from, float to) noexcept -> float { return detail::nextafter(from, to); }
39[[nodiscard]] constexpr auto nextafter(double from, double to) noexcept -> double
40{
41 return detail::nextafter(from, to);
42}
43
45
46} // namespace etl
47
48#endif // TETL_CMATH_NEXTAFTER_HPP
constexpr auto bit_cast(From const &src) noexcept -> To
Obtain a value of type To by reinterpreting the object representation of from. Every bit in the value...
Definition bit_cast.hpp:38
constexpr auto nextafterf(float from, float to) noexcept -> float
Returns the next representable value of from in the direction of to. If from equals to,...
Definition nextafter.hpp:38
constexpr auto nextafter(float from, float to) noexcept -> float
Returns the next representable value of from in the direction of to. If from equals to,...
Definition nextafter.hpp:37
Definition adjacent_find.hpp:8
typename conditional< B, T, F >::type conditional_t
Definition conditional.hpp:21
TETL_BUILTIN_UINT64 uint64_t
Unsigned integer type with width of exactly 64 bits.
Definition uint_t.hpp:20
TETL_BUILTIN_UINT32 uint32_t
Unsigned integer type with width of exactly 32 bits.
Definition uint_t.hpp:17