|
sparrow 1.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
|
Main header file for half-precision functionality. More...
#include <utility>#include <algorithm>#include <istream>#include <ostream>#include <limits>#include <stdexcept>#include <climits>#include <cmath>#include <cstring>#include <cstdlib>#include <type_traits>#include <cstdint>#include <cfenv>#include <functional>#include <concepts>Go to the source code of this file.
Namespaces | |
| namespace | half_float |
| Main namespace for half-precision functionality. | |
| namespace | std |
| Extensions to the C++ standard library. | |
| namespace | half_float::literal |
| Library-defined half-precision literals. | |
| namespace | half_float::detail |
Concepts | |
| concept | half_float::detail::arithmetic |
Macros | |
| #define | HALF_TWOS_COMPLEMENT_INT 1 |
| #define | HALF_ERRHANDLING (HALF_ERRHANDLING_FLAGS||HALF_ERRHANDLING_ERRNO||HALF_ERRHANDLING_FENV||HALF_ERRHANDLING_THROWS) |
| #define | HALF_UNUSED_NOERR(name) |
| #define | constexpr_NOERR constexpr |
| #define | HALF_ENABLE_F16C_INTRINSICS __F16C__ |
| Enable F16C intruction set intrinsics. | |
| #define | HALF_ERRHANDLING_OVERFLOW_TO_INEXACT 1 |
| Raise INEXACT exception on overflow. | |
| #define | HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT 1 |
| Raise INEXACT exception on underflow. | |
| #define | HALF_ROUND_STYLE 1 |
| Default rounding mode. | |
| #define | HUGE_VALH std::numeric_limits<half_float::half>::infinity() |
| Value signaling overflow. | |
| #define | FP_FAST_FMAH 1 |
| Fast half-precision fma function. | |
| #define | HLF_ROUNDS HALF_ROUND_STYLE |
| Half rounding mode. | |
| #define | FP_ILOGB0 INT_MIN |
| #define | FP_ILOGBNAN INT_MAX |
| #define | FP_SUBNORMAL 0 |
| #define | FP_ZERO 1 |
| #define | FP_NAN 2 |
| #define | FP_INFINITE 3 |
| #define | FP_NORMAL 4 |
| #define | FE_INVALID 0x10 |
| #define | FE_DIVBYZERO 0x08 |
| #define | FE_OVERFLOW 0x04 |
| #define | FE_UNDERFLOW 0x02 |
| #define | FE_INEXACT 0x01 |
| #define | FE_ALL_EXCEPT (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT) |
Typedefs | |
| using | half_float::detail::uint16 = std::uint_least16_t |
| Unsigned integer of (at least) 16 bits width. | |
| using | half_float::detail::uint32 = std::uint_fast32_t |
| Fastest unsigned integer of (at least) 32 bits width. | |
| using | half_float::detail::int32 = std::int_fast32_t |
| Fastest signed integer of (at least) 32 bits width. | |
| template<class T> | |
| using | half_float::detail::bits_t = typename bits<T>::type |
Functions | |
| half | half_float::literal::operator""_h (long double value) |
| Half literal. | |
Implementation defined classification and arithmetic | |
| template<class T> | |
| bool | half_float::detail::builtin_isinf (T arg) |
| Check for infinity. | |
| template<class T> | |
| bool | half_float::detail::builtin_isnan (T arg) |
| Check for NaN. | |
| template<class T> | |
| bool | half_float::detail::builtin_signbit (T arg) |
| Check sign. | |
| uint32 | half_float::detail::sign_mask (uint32 arg) |
| Platform-independent sign mask. | |
| uint32 | half_float::detail::arithmetic_shift (uint32 arg, int i) |
| Platform-independent arithmetic right shift. | |
Error handling | |
| int & | half_float::detail::errflags () |
| Internal exception flags. | |
| void | half_float::detail::raise (int HALF_UNUSED_NOERR(flags), bool HALF_UNUSED_NOERR(cond)=true) |
| Raise floating-point exception. | |
| constexpr_NOERR bool | half_float::detail::compsignal (unsigned int x, unsigned int y) |
| Check and signal for any NaN. | |
| constexpr_NOERR unsigned int | half_float::detail::signal (unsigned int nan) |
| Signal and silence signaling NaN. | |
| constexpr_NOERR unsigned int | half_float::detail::signal (unsigned int x, unsigned int y) |
| Signal and silence signaling NaNs. | |
| constexpr_NOERR unsigned int | half_float::detail::signal (unsigned int x, unsigned int y, unsigned int z) |
| Signal and silence signaling NaNs. | |
| constexpr_NOERR unsigned int | half_float::detail::select (unsigned int x, unsigned int HALF_UNUSED_NOERR(y)) |
| Select value or signaling NaN. | |
| constexpr_NOERR unsigned int | half_float::detail::invalid () |
| Raise domain error and return NaN. | |
| constexpr_NOERR unsigned int | half_float::detail::pole (unsigned int sign=0) |
| Raise pole error and return infinity. | |
| constexpr_NOERR unsigned int | half_float::detail::check_underflow (unsigned int arg) |
| Check value for underflow. | |
Conversion and rounding | |
| template<std::float_round_style R> | |
| constexpr_NOERR unsigned int | half_float::detail::overflow (unsigned int sign=0) |
| Half-precision overflow. | |
| template<std::float_round_style R> | |
| constexpr_NOERR unsigned int | half_float::detail::underflow (unsigned int sign=0) |
| Half-precision underflow. | |
| template<std::float_round_style R, bool I> | |
| constexpr_NOERR unsigned int | half_float::detail::rounded (unsigned int value, int g, int s) |
| Round half-precision number. | |
| template<std::float_round_style R, bool E, bool I> | |
| unsigned int | half_float::detail::integral (unsigned int value) |
| Round half-precision number to nearest integer value. | |
| template<std::float_round_style R, unsigned int F, bool S, bool N, bool I> | |
| unsigned int | half_float::detail::fixed2half (uint32 m, int exp=14, unsigned int sign=0, int s=0) |
| Convert fixed point to half-precision floating-point. | |
| template<std::float_round_style R> | |
| unsigned int | half_float::detail::float2half_impl (float value, true_type) |
| Convert IEEE single-precision to half-precision. | |
| template<std::float_round_style R> | |
| unsigned int | half_float::detail::float2half_impl (double value, true_type) |
| Convert IEEE double-precision to half-precision. | |
| template<std::float_round_style R, class T> | |
| unsigned int | half_float::detail::float2half_impl (T value,...) |
| Convert non-IEEE floating-point to half-precision. | |
| template<std::float_round_style R, class T> | |
| unsigned int | half_float::detail::float2half (T value) |
| Convert floating-point to half-precision. | |
| template<class T> | |
| unsigned int | half_float::detail::float2half (T value) |
| template<std::float_round_style R, class T> | |
| unsigned int | half_float::detail::int2half (T value) |
| Convert integer to half-precision floating-point. | |
| float | half_float::detail::half2float_impl (unsigned int value, float, true_type) |
| Convert half-precision to IEEE single-precision. | |
| double | half_float::detail::half2float_impl (unsigned int value, double, true_type) |
| Convert half-precision to IEEE double-precision. | |
| template<class T> | |
| T | half_float::detail::half2float_impl (unsigned int value, T,...) |
| Convert half-precision to non-IEEE floating-point. | |
| template<class T> | |
| T | half_float::detail::half2float (unsigned int value) |
| Convert half-precision to floating-point. | |
| template<std::float_round_style R, bool E, bool I, class T> | |
| T | half_float::detail::half2int (unsigned int value) |
| Convert half-precision floating-point to integer. | |
Mathematics | |
| template<std::float_round_style R> | |
| uint32 | half_float::detail::mulhi (uint32 x, uint32 y) |
| upper part of 64-bit multiplication. | |
| uint32 | half_float::detail::multiply64 (uint32 x, uint32 y) |
| 64-bit multiplication. | |
| uint32 | half_float::detail::divide64 (uint32 x, uint32 y, int &s) |
| 64-bit division. | |
| template<bool Q, bool R> | |
| unsigned int | half_float::detail::mod (unsigned int x, unsigned int y, int *quo=NULL) |
| Half precision positive modulus. | |
| template<unsigned int F> | |
| uint32 | half_float::detail::sqrt (uint32 &r, int &exp) |
| Fixed point square root. | |
| uint32 | half_float::detail::exp2 (uint32 m, unsigned int n=32) |
| Fixed point binary exponential. | |
| uint32 | half_float::detail::log2 (uint32 m, unsigned int n=32) |
| Fixed point binary logarithm. | |
| std::pair< uint32, uint32 > | half_float::detail::sincos (uint32 mz, unsigned int n=31) |
| Fixed point sine and cosine. | |
| uint32 | half_float::detail::atan2 (uint32 my, uint32 mx, unsigned int n=31) |
| Fixed point arc tangent. | |
| uint32 | half_float::detail::angle_arg (unsigned int abs, int &k) |
| Reduce argument for trigonometric functions. | |
| std::pair< uint32, uint32 > | half_float::detail::atan2_args (unsigned int abs) |
| Get arguments for atan2 function. | |
| std::pair< uint32, uint32 > | half_float::detail::hyperbolic_args (unsigned int abs, int &exp, unsigned int n=32) |
| Get exponentials for hyperbolic computation. | |
| template<std::float_round_style R, bool I> | |
| unsigned int | half_float::detail::exp2_post (uint32 m, int exp, bool esign, unsigned int sign=0) |
| Postprocessing for binary exponential. | |
| template<std::float_round_style R, uint32 L> | |
| unsigned int | half_float::detail::log2_post (uint32 m, int ilog, int exp, unsigned int sign=0) |
| Postprocessing for binary logarithm. | |
| template<std::float_round_style R> | |
| unsigned int | half_float::detail::hypot_post (uint32 r, int exp) |
| Hypotenuse square root and postprocessing. | |
| template<std::float_round_style R> | |
| unsigned int | half_float::detail::tangent_post (uint32 my, uint32 mx, int exp, unsigned int sign=0) |
| Division and postprocessing for tangents. | |
| template<std::float_round_style R, bool S> | |
| unsigned int | half_float::detail::area (unsigned int arg) |
| Area function and postprocessing. | |
| template<std::float_round_style R, bool C> | |
| unsigned int | half_float::detail::erf (unsigned int arg) |
| Error function and postprocessing. | |
| template<std::float_round_style R, bool L> | |
| unsigned int | half_float::detail::gamma (unsigned int arg) |
| Gamma function and postprocessing. | |
Comparison operators | |
| constexpr_NOERR bool | half_float::operator== (half x, half y) |
| Comparison for equality. | |
| template<detail::arithmetic T> | |
| constexpr_NOERR bool | half_float::operator== (half x, T y) |
| constexpr_NOERR std::partial_ordering | half_float::operator<=> (half x, half y) |
| template<detail::arithmetic T> | |
| constexpr_NOERR std::partial_ordering | half_float::operator<=> (half x, T y) |
Arithmetic operators | |
| constexpr half | half_float::operator+ (half arg) |
| Identity. | |
| constexpr half | half_float::operator- (half arg) |
| Negation. | |
| half | half_float::operator+ (half x, half y) |
| Addition. | |
| template<class T> | |
| half | half_float::operator+ (half x, T y) |
| template<class T> | |
| half | half_float::operator+ (T x, half y) |
| half | half_float::operator- (half x, half y) |
| Subtraction. | |
| template<class T> | |
| half | half_float::operator- (half x, T y) |
| template<class T> | |
| half | half_float::operator- (T x, half y) |
| half | half_float::operator* (half x, half y) |
| Multiplication. | |
| template<class T> | |
| half | half_float::operator* (half x, T y) |
| template<class T> | |
| half | half_float::operator* (T x, half y) |
| half | half_float::operator/ (half x, half y) |
| Division. | |
| template<class T> | |
| half | half_float::operator/ (half x, T y) |
| template<class T> | |
| half | half_float::operator/ (T x, half y) |
Input and output | |
| template<class charT, class traits> | |
| std::basic_ostream< charT, traits > & | half_float::operator<< (std::basic_ostream< charT, traits > &out, half arg) |
| Output operator. | |
| template<class charT, class traits> | |
| std::basic_istream< charT, traits > & | half_float::operator>> (std::basic_istream< charT, traits > &in, half &arg) |
| Input operator. | |
Basic mathematical operations | |
| constexpr half | half_float::fabs (half arg) |
| Absolute value. | |
| constexpr half | half_float::abs (half arg) |
| Absolute value. | |
| half | half_float::fmod (half x, half y) |
| Remainder of division. | |
| half | half_float::remainder (half x, half y) |
| Remainder of division. | |
| half | half_float::remquo (half x, half y, int *quo) |
| Remainder of division. | |
| half | half_float::fma (half x, half y, half z) |
| Fused multiply add. | |
| constexpr_NOERR half | half_float::fmax (half x, half y) |
| Maximum of half expressions. | |
| constexpr_NOERR half | half_float::fmin (half x, half y) |
| Minimum of half expressions. | |
| half | half_float::fdim (half x, half y) |
| Positive difference. | |
| half | half_float::nanh (const char *arg) |
| Get NaN value. | |
Exponential functions | |
| half | half_float::exp (half arg) |
| Exponential function. | |
| half | half_float::exp2 (half arg) |
| Binary exponential. | |
| half | half_float::expm1 (half arg) |
| Exponential minus one. | |
| half | half_float::log (half arg) |
| Natural logarithm. | |
| half | half_float::log10 (half arg) |
| Common logarithm. | |
| half | half_float::log2 (half arg) |
| Binary logarithm. | |
| half | half_float::log1p (half arg) |
| Natural logarithm plus one. | |
Power functions | |
| half | half_float::sqrt (half arg) |
| Square root. | |
| half | half_float::cbrt (half arg) |
| Cubic root. | |
| half | half_float::hypot (half x, half y) |
| Hypotenuse function. | |
| half | half_float::hypot (half x, half y, half z) |
| Hypotenuse function. | |
| half | half_float::pow (half x, half y) |
| Power function. | |
Trigonometric functions | |
| void | half_float::sincos (half arg, half *sin, half *cos) |
| Compute sine and cosine simultaneously. | |
| half | half_float::sin (half arg) |
| Sine function. | |
| half | half_float::cos (half arg) |
| Cosine function. | |
| half | half_float::tan (half arg) |
| Tangent function. | |
| half | half_float::asin (half arg) |
| Arc sine. | |
| half | half_float::acos (half arg) |
| Arc cosine function. | |
| half | half_float::atan (half arg) |
| Arc tangent function. | |
| half | half_float::atan2 (half y, half x) |
| Arc tangent function. | |
Hyperbolic functions | |
| half | half_float::sinh (half arg) |
| Hyperbolic sine. | |
| half | half_float::cosh (half arg) |
| Hyperbolic cosine. | |
| half | half_float::tanh (half arg) |
| Hyperbolic tangent. | |
| half | half_float::asinh (half arg) |
| Hyperbolic area sine. | |
| half | half_float::acosh (half arg) |
| Hyperbolic area cosine. | |
| half | half_float::atanh (half arg) |
| Hyperbolic area tangent. | |
Error and gamma functions | |
| half | half_float::erf (half arg) |
| Error function. | |
| half | half_float::erfc (half arg) |
| Complementary error function. | |
| half | half_float::lgamma (half arg) |
| Natural logarithm of gamma function. | |
| half | half_float::tgamma (half arg) |
| Gamma function. | |
Rounding | |
| half | half_float::ceil (half arg) |
| Nearest integer not less than half value. | |
| half | half_float::floor (half arg) |
| Nearest integer not greater than half value. | |
| half | half_float::trunc (half arg) |
| Nearest integer not greater in magnitude than half value. | |
| half | half_float::round (half arg) |
| Nearest integer. | |
| long | half_float::lround (half arg) |
| Nearest integer. | |
| half | half_float::rint (half arg) |
| Nearest integer using half's internal rounding mode. | |
| long | half_float::lrint (half arg) |
| Nearest integer using half's internal rounding mode. | |
| half | half_float::nearbyint (half arg) |
| Nearest integer using half's internal rounding mode. | |
| long long | half_float::llround (half arg) |
| Nearest integer. | |
| long long | half_float::llrint (half arg) |
| Nearest integer using half's internal rounding mode. | |
Floating point manipulation | |
| half | half_float::frexp (half arg, int *exp) |
| Decompress floating-point number. | |
| half | half_float::scalbln (half arg, long exp) |
| Multiply by power of two. | |
| half | half_float::scalbn (half arg, int exp) |
| Multiply by power of two. | |
| half | half_float::ldexp (half arg, int exp) |
| Multiply by power of two. | |
| half | half_float::modf (half arg, half *iptr) |
| Extract integer and fractional parts. | |
| int | half_float::ilogb (half arg) |
| Extract exponent. | |
| half | half_float::logb (half arg) |
| Extract exponent. | |
| half | half_float::nextafter (half from, half to) |
| Next representable value. | |
| half | half_float::nexttoward (half from, long double to) |
| Next representable value. | |
| constexpr half | half_float::copysign (half x, half y) |
| Take sign. | |
Floating point classification | |
| constexpr int | half_float::fpclassify (half arg) |
| Classify floating-point value. | |
| constexpr bool | half_float::isfinite (half arg) |
| Check if finite number. | |
| constexpr bool | half_float::isinf (half arg) |
| Check for infinity. | |
| constexpr bool | half_float::isnan (half arg) |
| Check for NaN. | |
| constexpr bool | half_float::isnormal (half arg) |
| Check if normal number. | |
| constexpr bool | half_float::signbit (half arg) |
| Check sign. | |
Comparison | |
| constexpr bool | half_float::isgreater (half x, half y) |
| Quiet comparison for greater than. | |
| constexpr bool | half_float::isgreaterequal (half x, half y) |
| Quiet comparison for greater equal. | |
| constexpr bool | half_float::isless (half x, half y) |
| Quiet comparison for less than. | |
| constexpr bool | half_float::islessequal (half x, half y) |
| Quiet comparison for less equal. | |
| constexpr bool | half_float::islessgreater (half x, half y) |
| Quiet comarison for less or greater. | |
| constexpr bool | half_float::isunordered (half x, half y) |
| Quiet check if unordered. | |
Casting | |
| template<class T, class U> | |
| T | half_float::half_cast (U arg) |
| Cast to or from half-precision floating-point number. | |
| template<class T, std::float_round_style R, class U> | |
| T | half_float::half_cast (U arg) |
| Cast to or from half-precision floating-point number. | |
Error handling | |
| int | half_float::feclearexcept (int excepts) |
| Clear exception flags. | |
| int | half_float::fetestexcept (int excepts) |
| Test exception flags. | |
| int | half_float::feraiseexcept (int excepts) |
| Raise exception flags. | |
| int | half_float::fegetexceptflag (int *flagp, int excepts) |
| Save exception flags. | |
| int | half_float::fesetexceptflag (const int *flagp, int excepts) |
| Restore exception flags. | |
| void | half_float::fethrowexcept (int excepts, const char *msg="") |
| Throw C++ exceptions based on set exception flags. | |
Variables | |
| template<> | |
| constexpr bool | std::is_floating_point_v< half_float::half > = true |
| template<> | |
| constexpr bool | std::is_scalar_v< half_float::half > = true |
| template<> | |
| constexpr bool | std::is_signed_v< half_float::half > = true |
| constexpr binary_t | half_float::detail::binary = binary_t() |
| Tag for binary construction. | |
Main header file for half-precision functionality.
Definition in file float16_t.hpp.
| #define constexpr_NOERR constexpr |
Definition at line 70 of file float16_t.hpp.
| #define FE_ALL_EXCEPT (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT) |
Definition at line 200 of file float16_t.hpp.
| #define FE_DIVBYZERO 0x08 |
Definition at line 196 of file float16_t.hpp.
| #define FE_INEXACT 0x01 |
Definition at line 199 of file float16_t.hpp.
| #define FE_INVALID 0x10 |
Definition at line 195 of file float16_t.hpp.
| #define FE_OVERFLOW 0x04 |
Definition at line 197 of file float16_t.hpp.
| #define FE_UNDERFLOW 0x02 |
Definition at line 198 of file float16_t.hpp.
| #define FP_FAST_FMAH 1 |
Fast half-precision fma function.
This symbol is defined if the fma() function generally executes as fast as, or faster than, a separate half-precision multiplication followed by an addition, which is always the case.
See also: Documentation for FP_FAST_FMA
Definition at line 163 of file float16_t.hpp.
| #define FP_ILOGB0 INT_MIN |
Definition at line 173 of file float16_t.hpp.
| #define FP_ILOGBNAN INT_MAX |
Definition at line 176 of file float16_t.hpp.
| #define FP_INFINITE 3 |
Definition at line 188 of file float16_t.hpp.
| #define FP_NAN 2 |
Definition at line 185 of file float16_t.hpp.
| #define FP_NORMAL 4 |
Definition at line 191 of file float16_t.hpp.
| #define FP_SUBNORMAL 0 |
Definition at line 179 of file float16_t.hpp.
| #define FP_ZERO 1 |
Definition at line 182 of file float16_t.hpp.
| #define HALF_ENABLE_F16C_INTRINSICS __F16C__ |
Enable F16C intruction set intrinsics.
Defining this to 1 enables the use of F16C compiler intrinsics for converting between half-precision and single-precision values which may result in improved performance. This will not perform additional checks for support of the F16C instruction set, so an appropriate target platform is required when enabling this feature.
Unless predefined it will be enabled automatically when the __F16C__ symbol is defined, which some compilers do on supporting platforms.
Definition at line 105 of file float16_t.hpp.
| #define HALF_ERRHANDLING (HALF_ERRHANDLING_FLAGS||HALF_ERRHANDLING_ERRNO||HALF_ERRHANDLING_FENV||HALF_ERRHANDLING_THROWS) |
Definition at line 58 of file float16_t.hpp.
| #define HALF_ERRHANDLING_OVERFLOW_TO_INEXACT 1 |
Raise INEXACT exception on overflow.
Defining this to 1 (default) causes overflow errors to automatically raise inexact exceptions in addition. These will be raised after any possible handling of the underflow exception.
Definition at line 116 of file float16_t.hpp.
| #define HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT 1 |
Raise INEXACT exception on underflow.
Defining this to 1 (default) causes underflow errors to automatically raise inexact exceptions in addition. These will be raised after any possible handling of the underflow exception.
Note: This will actually cause underflow (and the accompanying inexact) exceptions to be raised only when the result is inexact, while if disabled bare underflow errors will be raised for any (possibly exact) subnormal result.
Definition at line 126 of file float16_t.hpp.
| #define HALF_ROUND_STYLE 1 |
Default rounding mode.
This specifies the rounding mode used for all conversions between halfs and more precise types (unless using half_cast() and specifying the rounding mode directly) as well as in arithmetic operations and mathematical functions. It can be redefined (before including half.hpp) to one of the standard rounding modes using their respective constants or the equivalent values of std::float_round_style:
std::float_round_style | value | rounding |
|---|---|---|
std::round_indeterminate | -1 | fastest |
std::round_toward_zero | 0 | toward zero |
std::round_to_nearest | 1 | to nearest (default) |
std::round_toward_infinity | 2 | toward positive infinity |
std::round_toward_neg_infinity | 3 | toward negative infinity |
By default this is set to 1 (std::round_to_nearest), which rounds results to the nearest representable value. It can even be set to std::numeric_limits<float>::round_style to synchronize the rounding mode with that of the built-in single-precision implementation (which is likely std::round_to_nearest, though).
Definition at line 148 of file float16_t.hpp.
| #define HALF_TWOS_COMPLEMENT_INT 1 |
Definition at line 50 of file float16_t.hpp.
| #define HALF_UNUSED_NOERR | ( | name | ) |
Definition at line 63 of file float16_t.hpp.
| #define HLF_ROUNDS HALF_ROUND_STYLE |
Half rounding mode.
In correspondence with FLT_ROUNDS from <cfloat> this symbol expands to the rounding mode used for half-precision operations. It is an alias for HALF_ROUND_STYLE.
See also: Documentation for FLT_ROUNDS
Definition at line 170 of file float16_t.hpp.
| #define HUGE_VALH std::numeric_limits<half_float::half>::infinity() |
Value signaling overflow.
In correspondence with HUGE_VAL[F|L] from <cmath> this symbol expands to a positive value signaling the overflow of an operation, in particular it just evaluates to positive infinity.
See also: Documentation for HUGE_VAL
Definition at line 156 of file float16_t.hpp.