native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native::fp16 Struct Referenceexport

Public Types

using underlying_type = _Float16
 Native half storage when supported by the target; otherwise sixteen raw bits.

Public Member Functions

constexpr fp16 () noexcept=default
 Default-initialize storage without setting its bits; value-initialization zeroes it.
constexpr fp16 (fp16 const &) noexcept=default
 Copy the native sixteen-bit representation.
constexpr fp16 (fp16 &&) noexcept=default
 Copy the native representation; the source retains its bits.
constexpr fp16 (float value) noexcept
 Round a binary32 value to this format, ties to even.
constexpr fp16 (_Float16 content) noexcept
 Copy native storage without a numerical conversion.
constexpr operator float (this fp16 self) noexcept
 Decode to binary32; finite values are exact and signaling NaNs are quieted.
constexpr operator _Float16 (this fp16 self) noexcept
 Return native storage without rounding or normalizing NaN payloads.
constexpr fp16 & operator= (fp16 const &) noexcept=default
 Copy the native representation, replacing all previous bits.
constexpr fp16 & operator= (fp16 &&) noexcept=default
 Copy the native representation, leaving the source unchanged.
constexpr uint16_t to_bits (this fp16 self) noexcept
 Return the exact sixteen representation bits.

Static Public Member Functions

static constexpr fp16 from_bits (uint16_t data) noexcept
 Adopt the exact sixteen representation bits without normalization.

Public Attributes

underlying_type content
 Target-dependent storage. Use to_bits()/from_bits() for portable representation access.

Friends

constexpr bool operator== (fp16 x, fp16 y) noexcept
 Compare decoded values for equality; signed zeros compare equal and NaNs do not.
constexpr bool operator!= (fp16 x, fp16 y) noexcept
 Compare decoded values for inequality; a NaN operand makes the result true.
constexpr std::partial_ordering operator<=> (fp16 x, fp16 y) noexcept
 Compare decoded values; NaNs are unordered and signed zeros equivalent.
constexpr bool operator< (fp16 x, fp16 y) noexcept
 Return whether the decoded left value is less; false for NaN operands.
constexpr bool operator<= (fp16 x, fp16 y) noexcept
 Return whether the decoded left value is at most the right; false for NaN operands.
constexpr bool operator> (fp16 x, fp16 y) noexcept
 Return whether the decoded left value is greater; false for NaN operands.
constexpr bool operator>= (fp16 x, fp16 y) noexcept
 Return whether the decoded left value is at least the right; false for NaN operands.
constexpr void swap (fp16 &x, fp16 &y) noexcept
 Exchange native representations, including signed zeros and NaN payloads.

Detailed Description

Two-byte binary16 storage with environment-independent binary32 ties-to-even conversion. Conversion from float handles subnormals and overflow explicitly. Native-half interoperability is available only where the target supports that type. Native import and bit factories preserve representation without rounding. This is a storage/conversion type, not an FTZ arithmetic policy.

void common_utilities() {
using namespace native;
auto first = "vector"_ss;
auto second = "vector"_ss;
check(first == second && first.data() == second.data());
check(std::hash<static_string>{}(first) == std::hash<static_string>{}(second));
auto owned = native::dup(first.data());
if (owned) check(std::string_view(owned.get()) == "vector");
check(!native::type_of(first).empty());
auto half = native::fp16(1.5f);
check(static_cast<float>(half) == 1.5f);
}

Definition at line 34 of file native.numerics.ccm.


The documentation for this struct was generated from the following file: