|
Uni20
Asynchronous tensor and runtime library.
|
Signed value type that stores multiples of one half exactly. More...
#include <half_int.hpp>
Classes | |
| struct | twice_tag |
| Tag type used to construct directly from the doubled representation. More... | |
Public Types | |
| using | value_type = T |
| Underlying signed storage type. | |
Public Member Functions | |
| constexpr | basic_half_int ()=default |
| Construct the value zero. | |
| constexpr | basic_half_int (T twice_value, twice_tag tag) |
| Construct directly from the doubled representation. | |
| template<std::integral U> | |
| constexpr | basic_half_int (U value) |
| Construct from an integral value. | |
| template<std::floating_point U> | |
| basic_half_int (U value) | |
| Construct by rounding a floating-point value to the nearest half-integer. | |
| template<std::signed_integral U> | |
| explicit (std::numeric_limits< T >::digits< std::numeric_limits< U >::digits) const expr basic_half_int(basic_half_int< U > other) noexcept(std::numeric_limits< T >::digits >=std::numeric_limits< U >::digits) | |
| Convert another half-integer without changing its value. | |
| constexpr auto | is_integral () const -> bool |
| Return whether the represented value is integral. | |
| constexpr auto | operator++ () -> basic_half_int & |
| Prefix increment by one. | |
| constexpr auto | operator++ (int) -> basic_half_int |
| Postfix increment by one. | |
| constexpr auto | operator+= (basic_half_int other) -> basic_half_int & |
| Add another half-integer value. | |
| constexpr auto | operator-- () -> basic_half_int & |
| Prefix decrement by one. | |
| constexpr auto | operator-- (int) -> basic_half_int |
| Postfix decrement by one. | |
| constexpr auto | operator-= (basic_half_int other) -> basic_half_int & |
| Subtract another half-integer value. | |
| constexpr auto | operator<=> (basic_half_int const &other) const =default |
| Compare two half-integer values. | |
| constexpr auto | to_double () const -> double |
Convert to double. | |
| constexpr auto | to_int () const -> T |
| Convert to the underlying integral type. | |
| constexpr auto | to_int_assert () const -> T |
| Convert to the underlying integral type assuming exact integrality. | |
| constexpr auto | twice () const -> T |
| Return the doubled representation. | |
Static Public Member Functions | |
| static auto | parse (std::string_view text) -> basic_half_int |
| Parse a textual half-integer representation. | |
Signed value type that stores multiples of one half exactly.
| T | Signed integer storage type used for the doubled representation. |
| using uni20::basic_half_int< T >::value_type = T |
Underlying signed storage type.
|
constexprdefault |
Construct the value zero.
|
inlineconstexpr |
Construct from an integral value.
| value | Integral value to represent exactly. |
|
inlineexplicit |
Construct by rounding a floating-point value to the nearest half-integer.
| value | Floating-point value to round. |
|
inlineconstexpr |
Construct directly from the doubled representation.
| twice_value | Stored doubled value. |
| tag | Selects the direct doubled-value constructor. |
|
inlinenoexcept |
Convert another half-integer without changing its value.
Conversion is implicit and non-throwing when T can represent every doubled value of U. Narrowing requires explicit construction and checks the doubled representation before converting it.
| std::overflow_error | If the doubled value does not fit in T. |
|
inlineconstexpr |
Return whether the represented value is integral.
true if the value has no half-integer part.
|
inlineconstexpr |
Prefix increment by one.
*this.
|
inlineconstexpr |
Postfix increment by one.
|
inlineconstexpr |
Add another half-integer value.
| other | Value to add. |
*this.
|
inlineconstexpr |
Prefix decrement by one.
*this.
|
inlineconstexpr |
Postfix decrement by one.
|
inlineconstexpr |
Subtract another half-integer value.
| other | Value to subtract. |
*this.
|
constexprdefault |
Compare two half-integer values.
| other | Other value to compare. |
|
inlinestatic |
Parse a textual half-integer representation.
| text | String form such as "3", "5/2", or "1.5". |
|
inlineconstexpr |
Convert to double.
|
inlineconstexpr |
Convert to the underlying integral type.
| std::runtime_error | If the value is not integral. |
|
inlineconstexpr |
Convert to the underlying integral type assuming exact integrality.
is_integral()
|
inlineconstexpr |
Return the doubled representation.