/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-half/checkouts/latest/include/half.hpp File Reference#
Main header file for half precision functionality. More...
#include <utility>
#include <algorithm>
#include <iostream>
#include <limits>
#include <climits>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <type_traits>
#include <cstdint>
#include <functional>
Go to the source code of this file.
Classes | |
struct | half_float::detail::conditional< B, T, F > |
Conditional type. More... | |
struct | half_float::detail::bool_type< B > |
Helper for tag dispatching. More... | |
struct | half_float::detail::is_float< T > |
Type traits for floating point types. More... | |
struct | half_float::detail::bits< T > |
Type traits for floating point bits. More... | |
struct | half_float::detail::bits< float > |
Unsigned integer of (at least) 32 bits width. More... | |
struct | half_float::detail::bits< double > |
Unsigned integer of (at least) 64 bits width. More... | |
struct | half_float::detail::binary_t |
Tag type for binary construction. More... | |
struct | half_float::detail::expr |
Temporary half-precision expression. More... | |
struct | half_float::detail::enable< T, typename, typename, typename > |
SFINAE helper for generic half-precision functions. More... | |
struct | half_float::detail::result< T, U > |
Return type for specialized generic 2-argument half-precision functions. More... | |
class | half_float::half |
Half-precision floating point type. More... | |
struct | half_float::detail::functions |
Wrapper implementing unspecialized half-precision functions. More... | |
struct | half_float::detail::unary_specialized< T > |
Wrapper for unary half-precision functions needing specialization for individual argument types. More... | |
struct | half_float::detail::binary_specialized< T, U > |
Wrapper for binary half-precision functions needing specialization for individual argument types. More... | |
struct | half_float::detail::half_caster< T, U, R > |
Helper class for half casts. More... | |
class | std::numeric_limits< half_float::half > |
Numeric limits for half-precision floats. More... | |
struct | std::hash< half_float::half > |
Hash function for half-precision floats. More... | |
Namespaces | |
half_float | |
Main namespace for half precision functionality. | |
half_float::literal | |
Library-defined half-precision literals. | |
half_float::detail | |
Implementation details. | |
std | |
Extensions to the C++ standard library. | |
Macros | |
#define | HALF_GNUC_VERSION (__GNUC__*100+__GNUC_MINOR__) |
Combined gcc version number. | |
#define | HALF_CONSTEXPR constexpr |
#define | HALF_CONSTEXPR_CONST constexpr |
#define | HALF_NOEXCEPT noexcept |
#define | HALF_NOTHROW noexcept |
#define | HALF_ROUND_STYLE -1 |
Default rounding mode. More... | |
#define | HALF_ROUND_TIES_TO_EVEN 0 |
Tie-breaking behaviour for round to nearest. More... | |
#define | HUGE_VALH std::numeric_limits<half_float::half>::infinity() |
Value signaling overflow. More... | |
#define | FP_FAST_FMAH 1 |
Fast half-precision fma function. More... | |
Typedefs | |
typedef std::uint_least16_t | half_float::detail::uint16 |
Unsigned integer of (at least) 16 bits width. | |
Functions | |
half | half_float::literal::operator""_h (long double value) |
Half literal. More... | |
Classification helpers | |
template<typename T > | |
bool | half_float::detail::builtin_isinf (T arg) |
Check for infinity. More... | |
template<typename T > | |
bool | half_float::detail::builtin_isnan (T arg) |
Check for NaN. More... | |
template<typename T > | |
bool | half_float::detail::builtin_signbit (T arg) |
Check sign. More... | |
Conversion | |
template<std::float_round_style R> | |
uint16 | half_float::detail::float2half_impl (float value, true_type) |
Convert IEEE single-precision to half-precision. More... | |
template<std::float_round_style R> | |
uint16 | half_float::detail::float2half_impl (double value, true_type) |
Convert IEEE double-precision to half-precision. More... | |
template<std::float_round_style R, typename T > | |
uint16 | half_float::detail::float2half_impl (T value,...) |
Convert non-IEEE floating point to half-precision. More... | |
template<std::float_round_style R, typename T > | |
uint16 | half_float::detail::float2half (T value) |
Convert floating point to half-precision. More... | |
template<std::float_round_style R, bool S, typename T > | |
uint16 | half_float::detail::int2half_impl (T value) |
Convert integer to half-precision floating point. More... | |
template<std::float_round_style R, typename T > | |
uint16 | half_float::detail::int2half (T value) |
Convert integer to half-precision floating point. More... | |
float | half_float::detail::half2float_impl (uint16 value, float, true_type) |
Convert half-precision to IEEE single-precision. More... | |
double | half_float::detail::half2float_impl (uint16 value, double, true_type) |
Convert half-precision to IEEE double-precision. More... | |
template<typename T > | |
T | half_float::detail::half2float_impl (uint16 value, T,...) |
Convert half-precision to non-IEEE floating point. More... | |
template<typename T > | |
T | half_float::detail::half2float (uint16 value) |
Convert half-precision to floating point. More... | |
template<std::float_round_style R, bool E, typename T > | |
T | half_float::detail::half2int_impl (uint16 value) |
Convert half-precision floating point to integer. More... | |
template<std::float_round_style R, typename T > | |
T | half_float::detail::half2int (uint16 value) |
Convert half-precision floating point to integer. More... | |
template<typename T > | |
T | half_float::detail::half2int_up (uint16 value) |
Convert half-precision floating point to integer using round-to-nearest-away-from-zero. More... | |
template<std::float_round_style R, bool E> | |
uint16 | half_float::detail::round_half_impl (uint16 value) |
Round half-precision number to nearest integer value. More... | |
template<std::float_round_style R> | |
uint16 | half_float::detail::round_half (uint16 value) |
Round half-precision number to nearest integer value. More... | |
uint16 | half_float::detail::round_half_up (uint16 value) |
Round half-precision number to nearest integer value using round-to-nearest-away-from-zero. More... | |
Comparison operators | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator== (T x, U y) |
Comparison for equality. More... | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator!= (T x, U y) |
Comparison for inequality. More... | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator< (T x, U y) |
Comparison for less than. More... | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator> (T x, U y) |
Comparison for greater than. More... | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator<= (T x, U y) |
Comparison for less equal. More... | |
template<typename T , typename U > | |
enable< bool, T, U >::type | half_float::detail::operator>= (T x, U y) |
Comparison for greater equal. More... | |
Arithmetic operators | |
template<typename T , typename U > | |
enable< expr, T, U >::type | half_float::detail::operator+ (T x, U y) |
Add halfs. More... | |
template<typename T , typename U > | |
enable< expr, T, U >::type | half_float::detail::operator- (T x, U y) |
Subtract halfs. More... | |
template<typename T , typename U > | |
enable< expr, T, U >::type | half_float::detail::operator* (T x, U y) |
Multiply halfs. More... | |
template<typename T , typename U > | |
enable< expr, T, U >::type | half_float::detail::operator/ (T x, U y) |
Divide halfs. More... | |
template<typename T > | |
constexpr enable< T, T >::type | half_float::detail::operator+ (T arg) |
Identity. More... | |
template<typename T > | |
constexpr enable< T, T >::type | half_float::detail::operator- (T arg) |
Negation. More... | |
Input and output | |
template<typename T , typename charT , typename traits > | |
enable< std::basic_ostream< charT, traits > &, T >::type | half_float::detail::operator<< (std::basic_ostream< charT, traits > &out, T arg) |
Output operator. More... | |
template<typename charT , typename traits > | |
std::basic_istream< charT, traits > & | half_float::detail::operator>> (std::basic_istream< charT, traits > &in, half &arg) |
Input operator. More... | |
Basic mathematical operations | |
half | half_float::detail::abs (half arg) |
Absolute value. More... | |
expr | half_float::detail::abs (expr arg) |
half | half_float::detail::fabs (half arg) |
Absolute value. More... | |
expr | half_float::detail::fabs (expr arg) |
expr | half_float::detail::fmod (half x, half y) |
Remainder of division. More... | |
expr | half_float::detail::fmod (half x, expr y) |
expr | half_float::detail::fmod (expr x, half y) |
expr | half_float::detail::fmod (expr x, expr y) |
expr | half_float::detail::remainder (half x, half y) |
Remainder of division. More... | |
expr | half_float::detail::remainder (half x, expr y) |
expr | half_float::detail::remainder (expr x, half y) |
expr | half_float::detail::remainder (expr x, expr y) |
expr | half_float::detail::remquo (half x, half y, int *quo) |
Remainder of division. More... | |
expr | half_float::detail::remquo (half x, expr y, int *quo) |
expr | half_float::detail::remquo (expr x, half y, int *quo) |
expr | half_float::detail::remquo (expr x, expr y, int *quo) |
expr | half_float::detail::fma (half x, half y, half z) |
Fused multiply add. More... | |
expr | half_float::detail::fma (half x, half y, expr z) |
expr | half_float::detail::fma (half x, expr y, half z) |
expr | half_float::detail::fma (half x, expr y, expr z) |
expr | half_float::detail::fma (expr x, half y, half z) |
expr | half_float::detail::fma (expr x, half y, expr z) |
expr | half_float::detail::fma (expr x, expr y, half z) |
expr | half_float::detail::fma (expr x, expr y, expr z) |
half | half_float::detail::fmax (half x, half y) |
Maximum of half expressions. More... | |
expr | half_float::detail::fmax (half x, expr y) |
expr | half_float::detail::fmax (expr x, half y) |
expr | half_float::detail::fmax (expr x, expr y) |
half | half_float::detail::fmin (half x, half y) |
Minimum of half expressions. More... | |
expr | half_float::detail::fmin (half x, expr y) |
expr | half_float::detail::fmin (expr x, half y) |
expr | half_float::detail::fmin (expr x, expr y) |
expr | half_float::detail::fdim (half x, half y) |
Positive difference. More... | |
expr | half_float::detail::fdim (half x, expr y) |
expr | half_float::detail::fdim (expr x, half y) |
expr | half_float::detail::fdim (expr x, expr y) |
half | half_float::detail::nanh (const char *) |
Get NaN value. More... | |
Exponential functions | |
expr | half_float::detail::exp (half arg) |
Exponential function. More... | |
expr | half_float::detail::exp (expr arg) |
expr | half_float::detail::expm1 (half arg) |
Exponential minus one. More... | |
expr | half_float::detail::expm1 (expr arg) |
expr | half_float::detail::exp2 (half arg) |
Binary exponential. More... | |
expr | half_float::detail::exp2 (expr arg) |
expr | half_float::detail::log (half arg) |
Natural logorithm. More... | |
expr | half_float::detail::log (expr arg) |
expr | half_float::detail::log10 (half arg) |
Common logorithm. More... | |
expr | half_float::detail::log10 (expr arg) |
expr | half_float::detail::log1p (half arg) |
Natural logorithm. More... | |
expr | half_float::detail::log1p (expr arg) |
expr | half_float::detail::log2 (half arg) |
Binary logorithm. More... | |
expr | half_float::detail::log2 (expr arg) |
Power functions | |
expr | half_float::detail::sqrt (half arg) |
Square root. More... | |
expr | half_float::detail::sqrt (expr arg) |
expr | half_float::detail::cbrt (half arg) |
Cubic root. More... | |
expr | half_float::detail::cbrt (expr arg) |
expr | half_float::detail::hypot (half x, half y) |
Hypotenuse function. More... | |
expr | half_float::detail::hypot (half x, expr y) |
expr | half_float::detail::hypot (expr x, half y) |
expr | half_float::detail::hypot (expr x, expr y) |
expr | half_float::detail::pow (half base, half exp) |
Power function. More... | |
expr | half_float::detail::pow (half base, expr exp) |
expr | half_float::detail::pow (expr base, half exp) |
expr | half_float::detail::pow (expr base, expr exp) |
Trigonometric functions | |
expr | half_float::detail::sin (half arg) |
Sine function. More... | |
expr | half_float::detail::sin (expr arg) |
expr | half_float::detail::cos (half arg) |
Cosine function. More... | |
expr | half_float::detail::cos (expr arg) |
expr | half_float::detail::tan (half arg) |
Tangent function. More... | |
expr | half_float::detail::tan (expr arg) |
expr | half_float::detail::asin (half arg) |
Arc sine. More... | |
expr | half_float::detail::asin (expr arg) |
expr | half_float::detail::acos (half arg) |
Arc cosine function. More... | |
expr | half_float::detail::acos (expr arg) |
expr | half_float::detail::atan (half arg) |
Arc tangent function. More... | |
expr | half_float::detail::atan (expr arg) |
expr | half_float::detail::atan2 (half x, half y) |
Arc tangent function. More... | |
expr | half_float::detail::atan2 (half x, expr y) |
expr | half_float::detail::atan2 (expr x, half y) |
expr | half_float::detail::atan2 (expr x, expr y) |
Hyperbolic functions | |
expr | half_float::detail::sinh (half arg) |
Hyperbolic sine. More... | |
expr | half_float::detail::sinh (expr arg) |
expr | half_float::detail::cosh (half arg) |
Hyperbolic cosine. More... | |
expr | half_float::detail::cosh (expr arg) |
expr | half_float::detail::tanh (half arg) |
Hyperbolic tangent. More... | |
expr | half_float::detail::tanh (expr arg) |
expr | half_float::detail::asinh (half arg) |
Hyperbolic area sine. More... | |
expr | half_float::detail::asinh (expr arg) |
expr | half_float::detail::acosh (half arg) |
Hyperbolic area cosine. More... | |
expr | half_float::detail::acosh (expr arg) |
expr | half_float::detail::atanh (half arg) |
Hyperbolic area tangent. More... | |
expr | half_float::detail::atanh (expr arg) |
Error and gamma functions | |
expr | half_float::detail::erf (half arg) |
Error function. More... | |
expr | half_float::detail::erf (expr arg) |
expr | half_float::detail::erfc (half arg) |
Complementary error function. More... | |
expr | half_float::detail::erfc (expr arg) |
expr | half_float::detail::lgamma (half arg) |
Natural logarithm of gamma function. More... | |
expr | half_float::detail::lgamma (expr arg) |
expr | half_float::detail::tgamma (half arg) |
Gamma function. More... | |
expr | half_float::detail::tgamma (expr arg) |
Rounding | |
half | half_float::detail::ceil (half arg) |
Nearest integer not less than half value. More... | |
half | half_float::detail::ceil (expr arg) |
half | half_float::detail::floor (half arg) |
Nearest integer not greater than half value. More... | |
half | half_float::detail::floor (expr arg) |
half | half_float::detail::trunc (half arg) |
Nearest integer not greater in magnitude than half value. More... | |
half | half_float::detail::trunc (expr arg) |
half | half_float::detail::round (half arg) |
Nearest integer. More... | |
half | half_float::detail::round (expr arg) |
long | half_float::detail::lround (half arg) |
Nearest integer. More... | |
long | half_float::detail::lround (expr arg) |
half | half_float::detail::nearbyint (half arg) |
Nearest integer using half's internal rounding mode. More... | |
half | half_float::detail::nearbyint (expr arg) |
half | half_float::detail::rint (half arg) |
Nearest integer using half's internal rounding mode. More... | |
half | half_float::detail::rint (expr arg) |
long | half_float::detail::lrint (half arg) |
Nearest integer using half's internal rounding mode. More... | |
long | half_float::detail::lrint (expr arg) |
long long | half_float::detail::llround (half arg) |
Nearest integer. More... | |
long long | half_float::detail::llround (expr arg) |
long long | half_float::detail::llrint (half arg) |
Nearest integer using half's internal rounding mode. More... | |
long long | half_float::detail::llrint (expr arg) |
Floating point manipulation | |
half | half_float::detail::frexp (half arg, int *exp) |
Decompress floating point number. More... | |
half | half_float::detail::frexp (expr arg, int *exp) |
half | half_float::detail::ldexp (half arg, int exp) |
Multiply by power of two. More... | |
half | half_float::detail::ldexp (expr arg, int exp) |
half | half_float::detail::modf (half arg, half *iptr) |
Extract integer and fractional parts. More... | |
half | half_float::detail::modf (expr arg, half *iptr) |
half | half_float::detail::scalbn (half arg, int exp) |
Multiply by power of two. More... | |
half | half_float::detail::scalbn (expr arg, int exp) |
half | half_float::detail::scalbln (half arg, long exp) |
Multiply by power of two. More... | |
half | half_float::detail::scalbln (expr arg, long exp) |
int | half_float::detail::ilogb (half arg) |
Extract exponent. More... | |
int | half_float::detail::ilogb (expr arg) |
half | half_float::detail::logb (half arg) |
Extract exponent. More... | |
half | half_float::detail::logb (expr arg) |
half | half_float::detail::nextafter (half from, half to) |
Next representable value. More... | |
half | half_float::detail::nextafter (half from, expr to) |
half | half_float::detail::nextafter (expr from, half to) |
half | half_float::detail::nextafter (expr from, expr to) |
half | half_float::detail::nexttoward (half from, long double to) |
Next representable value. More... | |
half | half_float::detail::nexttoward (expr from, long double to) |
half | half_float::detail::copysign (half x, half y) |
Take sign. More... | |
half | half_float::detail::copysign (half x, expr y) |
half | half_float::detail::copysign (expr x, half y) |
half | half_float::detail::copysign (expr x, expr y) |
Floating point classification | |
int | half_float::detail::fpclassify (half arg) |
Classify floating point value. More... | |
int | half_float::detail::fpclassify (expr arg) |
bool | half_float::detail::isfinite (half arg) |
Check if finite number. More... | |
bool | half_float::detail::isfinite (expr arg) |
bool | half_float::detail::isinf (half arg) |
Check for infinity. More... | |
bool | half_float::detail::isinf (expr arg) |
bool | half_float::detail::isnan (half arg) |
Check for NaN. More... | |
bool | half_float::detail::isnan (expr arg) |
bool | half_float::detail::isnormal (half arg) |
Check if normal number. More... | |
bool | half_float::detail::isnormal (expr arg) |
bool | half_float::detail::signbit (half arg) |
Check sign. More... | |
bool | half_float::detail::signbit (expr arg) |
Comparison | |
bool | half_float::detail::isgreater (half x, half y) |
Comparison for greater than. More... | |
bool | half_float::detail::isgreater (half x, expr y) |
bool | half_float::detail::isgreater (expr x, half y) |
bool | half_float::detail::isgreater (expr x, expr y) |
bool | half_float::detail::isgreaterequal (half x, half y) |
Comparison for greater equal. More... | |
bool | half_float::detail::isgreaterequal (half x, expr y) |
bool | half_float::detail::isgreaterequal (expr x, half y) |
bool | half_float::detail::isgreaterequal (expr x, expr y) |
bool | half_float::detail::isless (half x, half y) |
Comparison for less than. More... | |
bool | half_float::detail::isless (half x, expr y) |
bool | half_float::detail::isless (expr x, half y) |
bool | half_float::detail::isless (expr x, expr y) |
bool | half_float::detail::islessequal (half x, half y) |
Comparison for less equal. More... | |
bool | half_float::detail::islessequal (half x, expr y) |
bool | half_float::detail::islessequal (expr x, half y) |
bool | half_float::detail::islessequal (expr x, expr y) |
bool | half_float::detail::islessgreater (half x, half y) |
Comarison for less or greater. More... | |
bool | half_float::detail::islessgreater (half x, expr y) |
bool | half_float::detail::islessgreater (expr x, half y) |
bool | half_float::detail::islessgreater (expr x, expr y) |
bool | half_float::detail::isunordered (half x, half y) |
Check if unordered. More... | |
bool | half_float::detail::isunordered (half x, expr y) |
bool | half_float::detail::isunordered (expr x, half y) |
bool | half_float::detail::isunordered (expr x, expr y) |
Casting | |
template<typename T , typename U > | |
T | half_float::detail::half_cast (U arg) |
Cast to or from half-precision floating point number. More... | |
template<typename T , std::float_round_style R, typename U > | |
T | half_float::detail::half_cast (U arg) |
Cast to or from half-precision floating point number. More... | |
Variables | |
constexpr binary_t | half_float::detail::binary = binary_t() |
Tag for binary construction. | |
Detailed Description
Main header file for half precision functionality.
Definition in file half.hpp.
Macro Definition Documentation
◆ HALF_ROUND_STYLE
#define HALF_ROUND_STYLE -1 |
Default rounding mode.
This specifies the rounding mode used for all conversions between halfs and float
s as well as for the half_cast() if not specifying a rounding mode explicitly. 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 (default) |
std::round_toward_zero | 0 | toward zero |
std::round_to_nearest | 1 | to nearest |
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_indeterminate
), which uses truncation (round toward zero, but with overflows set to infinity) and is the fastest rounding mode possible. It can even be set to std::numeric_limits<float>::round_style
to synchronize the rounding mode with that of the underlying single-precision implementation.
◆ HALF_ROUND_TIES_TO_EVEN
#define HALF_ROUND_TIES_TO_EVEN 0 |
Tie-breaking behaviour for round to nearest.
This specifies if ties in round to nearest should be resolved by rounding to the nearest even value. By default this is defined to 0
resulting in the faster but slightly more biased behaviour of rounding away from zero in half-way cases (and thus equal to the round() function), but can be redefined to 1
(before including half.hpp) if more IEEE-conformant behaviour is needed.
◆ HUGE_VALH
#define HUGE_VALH std::numeric_limits<half_float::half>::infinity() |
◆ FP_FAST_FMAH
#define FP_FAST_FMAH 1 |
Fast half-precision fma function.
This symbol is only defined if the fma() function generally executes as fast as, or faster than, a separate half-precision multiplication followed by an addition. Due to the internal single-precision implementation of all arithmetic operations, this is in fact always the case.