half  1.11
IEEE 754-based half-precision floating point library
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
half.hpp File Reference

Main header file of the library. More...

Go to the source code of this file.

Classes

struct  half
 Half-precision floating point type. More...
 
struct  numeric_limits< half_float::half >
 Numeric limits for half-precision floats. More...
 
struct  hash< half_float::half >
 Hash function for half-precision floats. More...
 

Namespaces

namespace  half_float
 Main namespace for half precision functionality.
 
namespace  half_float::literal
 Library-defined half-precision literals.
 
namespace  std
 Extensions to the C++ standard library.
 

Macros

#define HALF_ROUND_STYLE   -1
 Default rounding mode.
 
#define HALF_ROUND_TIES_TO_EVEN   0
 Tie-breaking behaviour for round to nearest.
 
#define HUGE_VALH   std::numeric_limits<half_float::half>::infinity()
 Value signaling overflow.
 
#define FP_FAST_FMAH   1
 Fast half-precision fma function.
 

Functions

half operator""_h (long double value)
 Half literal.
 
Comparison operators
bool operator== (half a, half b)
 Comparison for equality.
 
bool operator!= (half a, half b)
 Comparison for inequality.
 
bool operator< (half a, half b)
 Comparison for less than.
 
bool operator> (half a, half b)
 Comparison for greater than.
 
bool operator<= (half a, half b)
 Comparison for less equal.
 
bool operator>= (half a, half b)
 Comparison for greater equal.
 
Arithmetic operators
half operator+ (half a, half b)
 Add halfs.
 
half operator- (half a, half b)
 Subtract halfs.
 
half operator* (half a, half b)
 Multiply halfs.
 
half operator/ (half a, half b)
 Divide halfs.
 
half constexpr operator+ (half h)
 Identity.
 
half constexpr operator- (half h)
 Negation.
 
Input and output
template<typename charT , typename traits >
std::basic_ostream< charT,
traits > & 
operator<< (std::basic_ostream< charT, traits > &out, half h)
 Output operator.
 
template<typename charT , typename traits >
std::basic_istream< charT,
traits > & 
operator>> (std::basic_istream< charT, traits > &in, half &h)
 Input operator.
 
Basic mathematical operations
half abs (half arg)
 Absolute value.
 
half fabs (half arg)
 Absolute value.
 
half fmod (half x, half y)
 Remainder of division.
 
half remainder (half x, half y)
 Remainder of division.
 
half remquo (half x, half y, int *quo)
 Remainder of division.
 
half fma (half x, half y, half z)
 Fused multiply add.
 
half fmin (half x, half y)
 Minimum of halfs.
 
half fmax (half x, half y)
 Maximum of halfs.
 
half fdim (half x, half y)
 Positive difference.
 
half nanh (const char *)
 Get NaN value.
 
Exponential functions
half exp (half arg)
 Exponential function.
 
half exp2 (half arg)
 Binary exponential.
 
half expm1 (half arg)
 Exponential minus one.
 
half log (half arg)
 Natural logorithm.
 
half log10 (half arg)
 Common logorithm.
 
half log1p (half arg)
 Natural logorithm.
 
half log2 (half arg)
 Binary logorithm.
 
Power functions
half sqrt (half arg)
 Square root.
 
half cbrt (half arg)
 Cubic root.
 
half hypot (half x, half y)
 Hypotenuse function.
 
half pow (half base, half exp)
 Power function.
 
Trigonometric functions
half sin (half arg)
 Sine function.
 
half cos (half arg)
 Cosine function.
 
half tan (half arg)
 Tangent function.
 
half asin (half arg)
 Arc sine.
 
half acos (half arg)
 Arc cosine function.
 
half atan (half arg)
 Arc tangent function.
 
half atan2 (half x, half y)
 Arc tangent function.
 
Hyperbolic functions
half sinh (half arg)
 Hyperbolic sine.
 
half cosh (half arg)
 Hyperbolic cosine.
 
half tanh (half arg)
 Hyperbolic tangent.
 
half asinh (half arg)
 Hyperbolic area sine.
 
half acosh (half arg)
 Hyperbolic area cosine.
 
half atanh (half arg)
 Hyperbolic area tangent.
 
Error and gamma functions
half erf (half arg)
 Error function.
 
half erfc (half arg)
 Complementary error function.
 
half lgamma (half arg)
 Natural logarithm of gamma function.
 
half tgamma (half arg)
 Gamma function.
 
Rounding
half ceil (half arg)
 Nearest integer not less than half value.
 
half floor (half arg)
 Nearest integer not greater than half value.
 
half trunc (half arg)
 Nearest integer not greater in magnitude than half value.
 
half round (half arg)
 Nearest integer.
 
long lround (half arg)
 Nearest integer.
 
long long llround (half arg)
 Nearest integer.
 
half nearbyint (half arg)
 Nearest integer.
 
half rint (half arg)
 Nearest integer.
 
long lrint (half arg)
 Nearest integer.
 
long long llrint (half arg)
 Nearest integer.
 
Floating point manipulation
half frexp (half arg, int *exp)
 Decompress floating point number.
 
half ldexp (half arg, int exp)
 Multiply by power of two.
 
half modf (half x, half *iptr)
 Extract integer and fractional parts.
 
half scalbn (half x, int exp)
 Multiply by power of two.
 
half scalbln (half x, long exp)
 Multiply by power of two.
 
int ilogb (half arg)
 Extract exponent.
 
half logb (half arg)
 Extract exponent.
 
half nextafter (half from, half to)
 Next representable value.
 
half nexttoward (half from, long double to)
 Next representable value.
 
half copysign (half x, half y)
 Take sign.
 
Floating point classification
int fpclassify (half arg)
 Classify floating point value.
 
bool isfinite (half arg)
 Check if finite number.
 
bool isinf (half arg)
 Check for infinity.
 
bool isnan (half arg)
 Check for NaN.
 
bool isnormal (half arg)
 Check if normal number.
 
bool signbit (half arg)
 Check sign.
 
Comparison
bool isgreater (half x, half y)
 Comparison for greater than.
 
bool isgreaterequal (half x, half y)
 Comparison for greater equal.
 
bool isless (half x, half y)
 Comparison for less than.
 
bool islessequal (half x, half y)
 Comparison for less equal.
 
bool islessgreater (half x, half y)
 Comarison for less or greater.
 
bool isunordered (half x, half y)
 Check if unordered.
 
Casting
template<typename T , typename U >
half_cast (const U &arg)
 Cast to or from half-precision floating point number.
 
template<typename T , std::float_round_style R, typename U >
half_cast (const U &arg)
 Cast to or from half-precision floating point number.
 

Detailed Description

Main header file of the library.

Macro Definition Documentation

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

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

#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

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

See also: Documentation for FP_FAST_FMA