GADGET-4
half.hpp File Reference

Implements half precision functionality. More...

#include <utility>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>

Go to the source code of this file.

Classes

struct  conditional< bool, T, typename >
 Conditional type. More...
 
struct  conditional< false, T, F >
 
struct  bool_type< bool >
 Helper for tag dispatching. More...
 
struct  is_float< typename >
 Type traits for floating point types. More...
 
struct  is_float< const T >
 
struct  is_float< volatile T >
 
struct  is_float< const volatile T >
 
struct  is_float< float >
 
struct  is_float< double >
 
struct  is_float< long double >
 
struct  bits< T >
 Type traits for floating point bits. More...
 
struct  bits< const T >
 
struct  bits< volatile T >
 
struct  bits< const volatile T >
 
struct  bits< float >
 Unsigned integer of (at least) 32 bits width. More...
 
struct  bits< double >
 Unsigned integer of (at least) 64 bits width. More...
 
struct  binary_t
 Tag type for binary construction. More...
 
struct  expr
 
struct  enable< T, typename, typename, typename >
 
struct  enable< T, half, void, void >
 
struct  enable< T, expr, void, void >
 
struct  enable< T, half, half, void >
 
struct  enable< T, half, expr, void >
 
struct  enable< T, expr, half, void >
 
struct  enable< T, expr, expr, void >
 
struct  enable< T, half, half, half >
 
struct  enable< T, half, half, expr >
 
struct  enable< T, half, expr, half >
 
struct  enable< T, half, expr, expr >
 
struct  enable< T, expr, half, half >
 
struct  enable< T, expr, half, expr >
 
struct  enable< T, expr, expr, half >
 
struct  enable< T, expr, expr, expr >
 
struct  result< T, U >
 
struct  result< half, half >
 
class  half
 
struct  functions
 Wrapper implementing unspecialized half-precision functions. More...
 
struct  unary_specialized< T >
 
struct  unary_specialized< expr >
 
struct  binary_specialized< T, U >
 
struct  binary_specialized< half, half >
 
struct  half_caster< T, U, R >
 
struct  half_caster< half, U, R >
 
struct  half_caster< T, half, R >
 
struct  half_caster< T, expr, R >
 
struct  half_caster< half, half, R >
 
struct  half_caster< half, expr, R >
 
class  numeric_limits< half_float::half >
 

Namespaces

namespace  half_float
 
namespace  half_float::detail
 
namespace  std
 STL namespace.
 

Macros

#define HALF_GNUC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 Combined gcc version number. More...
 
#define HALF_CONSTEXPR
 
#define HALF_CONSTEXPR_CONST   const
 
#define HALF_NOEXCEPT
 
#define HALF_NOTHROW   throw()
 
#define HALF_ROUND_STYLE   -1
 
#define HALF_ROUND_TIES_TO_EVEN   0
 
#define HUGE_VALH   std::numeric_limits<half_float::half>::infinity()
 
#define FP_FAST_FMAH   1
 
#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
 

Typedefs

typedef bool_type< true > true_type
 
typedef bool_type< false > false_type
 
typedef unsigned short uint16
 Unsigned integer of (at least) 16 bits width. More...
 

Functions

Classification helpers
template<typename T >
bool builtin_isinf (T arg)
 
template<typename T >
bool builtin_isnan (T arg)
 
template<typename T >
bool builtin_signbit (T arg)
 
Conversion
template<std::float_round_style R>
uint16 float2half_impl (float value, true_type)
 
template<std::float_round_style R>
uint16 float2half_impl (double value, true_type)
 
template<std::float_round_style R, typename T >
uint16 float2half_impl (T value,...)
 
template<std::float_round_style R, typename T >
uint16 float2half (T value)
 
template<std::float_round_style R, bool S, typename T >
uint16 int2half_impl (T value)
 
template<std::float_round_style R, typename T >
uint16 int2half (T value)
 
float half2float_impl (uint16 value, float, true_type)
 
double half2float_impl (uint16 value, double, true_type)
 
template<typename T >
half2float_impl (uint16 value, T,...)
 
template<typename T >
half2float (uint16 value)
 
template<std::float_round_style R, bool E, typename T >
half2int_impl (uint16 value)
 
template<std::float_round_style R, typename T >
half2int (uint16 value)
 
template<typename T >
half2int_up (uint16 value)
 
template<std::float_round_style R, bool E>
uint16 round_half_impl (uint16 value)
 
template<std::float_round_style R>
uint16 round_half (uint16 value)
 
uint16 round_half_up (uint16 value)
 
Comparison operators
template<typename T , typename U >
enable< bool, T, U >::type operator== (T x, U y)
 
template<typename T , typename U >
enable< bool, T, U >::type operator!= (T x, U y)
 
template<typename T , typename U >
enable< bool, T, U >::type operator< (T x, U y)
 
template<typename T , typename U >
enable< bool, T, U >::type operator> (T x, U y)
 
template<typename T , typename U >
enable< bool, T, U >::type operator<= (T x, U y)
 
template<typename T , typename U >
enable< bool, T, U >::type operator>= (T x, U y)
 
Arithmetic operators
template<typename T , typename U >
enable< expr, T, U >::type operator+ (T x, U y)
 
template<typename T , typename U >
enable< expr, T, U >::type operator- (T x, U y)
 
template<typename T , typename U >
enable< expr, T, U >::type operator* (T x, U y)
 
template<typename T , typename U >
enable< expr, T, U >::type operator/ (T x, U y)
 
template<typename T >
HALF_CONSTEXPR enable< T, T >::type operator+ (T arg)
 
template<typename T >
HALF_CONSTEXPR enable< T, T >::type operator- (T arg)
 
Input and output
template<typename T , typename charT , typename traits >
enable< std::basic_ostream< charT, traits > &, T >::type operator<< (std::basic_ostream< charT, traits > &out, T arg)
 
template<typename charT , typename traits >
std::basic_istream< charT, traits > & operator>> (std::basic_istream< charT, traits > &in, half &arg)
 
Basic mathematical operations
half abs (half arg)
 
expr abs (expr arg)
 
half fabs (half arg)
 
expr fabs (expr arg)
 
expr fmod (half x, half y)
 
expr fmod (half x, expr y)
 
expr fmod (expr x, half y)
 
expr fmod (expr x, expr y)
 
expr remainder (half x, half y)
 
expr remainder (half x, expr y)
 
expr remainder (expr x, half y)
 
expr remainder (expr x, expr y)
 
expr remquo (half x, half y, int *quo)
 
expr remquo (half x, expr y, int *quo)
 
expr remquo (expr x, half y, int *quo)
 
expr remquo (expr x, expr y, int *quo)
 
expr fma (half x, half y, half z)
 
expr fma (half x, half y, expr z)
 
expr fma (half x, expr y, half z)
 
expr fma (half x, expr y, expr z)
 
expr fma (expr x, half y, half z)
 
expr fma (expr x, half y, expr z)
 
expr fma (expr x, expr y, half z)
 
expr fma (expr x, expr y, expr z)
 
half fmax (half x, half y)
 
expr fmax (half x, expr y)
 
expr fmax (expr x, half y)
 
expr fmax (expr x, expr y)
 
half fmin (half x, half y)
 
expr fmin (half x, expr y)
 
expr fmin (expr x, half y)
 
expr fmin (expr x, expr y)
 
expr fdim (half x, half y)
 
expr fdim (half x, expr y)
 
expr fdim (expr x, half y)
 
expr fdim (expr x, expr y)
 
half nanh (const char *)
 
Exponential functions
expr exp (half arg)
 
expr exp (expr arg)
 
expr expm1 (half arg)
 
expr expm1 (expr arg)
 
expr exp2 (half arg)
 
expr exp2 (expr arg)
 
expr log (half arg)
 
expr log (expr arg)
 
expr log10 (half arg)
 
expr log10 (expr arg)
 
expr log1p (half arg)
 
expr log1p (expr arg)
 
expr log2 (half arg)
 
expr log2 (expr arg)
 
Power functions
expr sqrt (half arg)
 
expr sqrt (expr arg)
 
expr cbrt (half arg)
 
expr cbrt (expr arg)
 
expr hypot (half x, half y)
 
expr hypot (half x, expr y)
 
expr hypot (expr x, half y)
 
expr hypot (expr x, expr y)
 
expr pow (half base, half exp)
 
expr pow (half base, expr exp)
 
expr pow (expr base, half exp)
 
expr pow (expr base, expr exp)
 
Trigonometric functions
expr sin (half arg)
 
expr sin (expr arg)
 
expr cos (half arg)
 
expr cos (expr arg)
 
expr tan (half arg)
 
expr tan (expr arg)
 
expr asin (half arg)
 
expr asin (expr arg)
 
expr acos (half arg)
 
expr acos (expr arg)
 
expr atan (half arg)
 
expr atan (expr arg)
 
expr atan2 (half x, half y)
 
expr atan2 (half x, expr y)
 
expr atan2 (expr x, half y)
 
expr atan2 (expr x, expr y)
 
Hyperbolic functions
expr sinh (half arg)
 
expr sinh (expr arg)
 
expr cosh (half arg)
 
expr cosh (expr arg)
 
expr tanh (half arg)
 
expr tanh (expr arg)
 
expr asinh (half arg)
 
expr asinh (expr arg)
 
expr acosh (half arg)
 
expr acosh (expr arg)
 
expr atanh (half arg)
 
expr atanh (expr arg)
 
Error and gamma functions
expr erf (half arg)
 
expr erf (expr arg)
 
expr erfc (half arg)
 
expr erfc (expr arg)
 
expr lgamma (half arg)
 
expr lgamma (expr arg)
 
expr tgamma (half arg)
 
expr tgamma (expr arg)
 
Rounding
half ceil (half arg)
 
half ceil (expr arg)
 
half floor (half arg)
 
half floor (expr arg)
 
half trunc (half arg)
 
half trunc (expr arg)
 
half round (half arg)
 
half round (expr arg)
 
long lround (half arg)
 
long lround (expr arg)
 
half nearbyint (half arg)
 
half nearbyint (expr arg)
 
half rint (half arg)
 
half rint (expr arg)
 
long lrint (half arg)
 
long lrint (expr arg)
 
Floating point manipulation
half frexp (half arg, int *exp)
 
half frexp (expr arg, int *exp)
 
half ldexp (half arg, int exp)
 
half ldexp (expr arg, int exp)
 
half modf (half arg, half *iptr)
 
half modf (expr arg, half *iptr)
 
half scalbn (half arg, int exp)
 
half scalbn (expr arg, int exp)
 
half scalbln (half arg, long exp)
 
half scalbln (expr arg, long exp)
 
int ilogb (half arg)
 
int ilogb (expr arg)
 
half logb (half arg)
 
half logb (expr arg)
 
half nextafter (half from, half to)
 
half nextafter (half from, expr to)
 
half nextafter (expr from, half to)
 
half nextafter (expr from, expr to)
 
half nexttoward (half from, long double to)
 
half nexttoward (expr from, long double to)
 
half copysign (half x, half y)
 
half copysign (half x, expr y)
 
half copysign (expr x, half y)
 
half copysign (expr x, expr y)
 
Floating point classification
int fpclassify (half arg)
 
int fpclassify (expr arg)
 
bool isfinite (half arg)
 
bool isfinite (expr arg)
 
bool isinf (half arg)
 
bool isinf (expr arg)
 
bool isnan (half arg)
 
bool isnan (expr arg)
 
bool isnormal (half arg)
 
bool isnormal (expr arg)
 
bool signbit (half arg)
 
bool signbit (expr arg)
 
Comparison
bool isgreater (half x, half y)
 
bool isgreater (half x, expr y)
 
bool isgreater (expr x, half y)
 
bool isgreater (expr x, expr y)
 
bool isgreaterequal (half x, half y)
 
bool isgreaterequal (half x, expr y)
 
bool isgreaterequal (expr x, half y)
 
bool isgreaterequal (expr x, expr y)
 
bool isless (half x, half y)
 
bool isless (half x, expr y)
 
bool isless (expr x, half y)
 
bool isless (expr x, expr y)
 
bool islessequal (half x, half y)
 
bool islessequal (half x, expr y)
 
bool islessequal (expr x, half y)
 
bool islessequal (expr x, expr y)
 
bool islessgreater (half x, half y)
 
bool islessgreater (half x, expr y)
 
bool islessgreater (expr x, half y)
 
bool islessgreater (expr x, expr y)
 
bool isunordered (half x, half y)
 
bool isunordered (half x, expr y)
 
bool isunordered (expr x, half y)
 
bool isunordered (expr x, expr y)
 
Casting
template<typename T , typename U >
half_cast (U arg)
 
template<typename T , std::float_round_style R, typename U >
half_cast (U arg)
 

Variables

HALF_CONSTEXPR_CONST binary_t binary = binary_t()
 Tag for binary construction. More...
 

Detailed Description

Implements half precision functionality.

Definition in file half.hpp.

Macro Definition Documentation

◆ 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.

Definition at line 236 of file half.hpp.

◆ FP_ILOGB0

#define FP_ILOGB0   INT_MIN

Definition at line 239 of file half.hpp.

◆ FP_ILOGBNAN

#define FP_ILOGBNAN   INT_MAX

Definition at line 242 of file half.hpp.

◆ FP_INFINITE

#define FP_INFINITE   3

Definition at line 254 of file half.hpp.

◆ FP_NAN

#define FP_NAN   2

Definition at line 251 of file half.hpp.

◆ FP_NORMAL

#define FP_NORMAL   4

Definition at line 257 of file half.hpp.

◆ FP_SUBNORMAL

#define FP_SUBNORMAL   0

Definition at line 245 of file half.hpp.

◆ FP_ZERO

#define FP_ZERO   1

Definition at line 248 of file half.hpp.

◆ HALF_CONSTEXPR

#define HALF_CONSTEXPR

Definition at line 169 of file half.hpp.

◆ HALF_CONSTEXPR_CONST

#define HALF_CONSTEXPR_CONST   const

Definition at line 170 of file half.hpp.

◆ HALF_GNUC_VERSION

#define HALF_GNUC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Combined gcc version number.

Definition at line 29 of file half.hpp.

◆ HALF_NOEXCEPT

#define HALF_NOEXCEPT

Definition at line 178 of file half.hpp.

◆ HALF_NOTHROW

#define HALF_NOTHROW   throw()

Definition at line 179 of file half.hpp.

◆ HALF_ROUND_STYLE

#define HALF_ROUND_STYLE   -1

Default rounding mode. This specifies the rounding mode used for all conversions between halfs and floats 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.

Definition at line 215 of file half.hpp.

◆ 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.

Definition at line 224 of file half.hpp.

◆ HUGE_VALH

#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.

Definition at line 230 of file half.hpp.