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

Main namespace for half precision functionality. More...

Namespaces

namespace  literal
 Library-defined half-precision literals.
 

Classes

struct  half
 Half-precision floating point type. More...
 

Functions

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 namespace for half precision functionality.

This namespace contains all the functionality provided by the library.

Function Documentation

bool half_float::operator== ( half  a,
half  b 
)

Comparison for equality.

Parameters
afirst operand
bsecond operand
Return values
trueif operands equal
falseelse
bool half_float::operator!= ( half  a,
half  b 
)

Comparison for inequality.

Parameters
afirst operand
bsecond operand
Return values
trueif operands not equal
falseelse
bool half_float::operator< ( half  a,
half  b 
)

Comparison for less than.

Parameters
afirst operand
bsecond operand
Return values
trueif a less than b
falseelse
bool half_float::operator> ( half  a,
half  b 
)

Comparison for greater than.

Parameters
afirst operand
bsecond operand
Return values
trueif a greater than b
falseelse
bool half_float::operator<= ( half  a,
half  b 
)

Comparison for less equal.

Parameters
afirst operand
bsecond operand
Return values
trueif a less equal b
falseelse
bool half_float::operator>= ( half  a,
half  b 
)

Comparison for greater equal.

Parameters
afirst operand
bsecond operand
Return values
trueif a greater equal b
falseelse
half half_float::operator+ ( half  a,
half  b 
)

Add halfs.

This operation uses the underlying single-precision implementation.

Parameters
aleft operand
bright operand
Returns
sum of halfs
half half_float::operator- ( half  a,
half  b 
)

Subtract halfs.

This operation uses the underlying single-precision implementation.

Parameters
aleft operand
bright operand
Returns
difference of halfs
half half_float::operator* ( half  a,
half  b 
)

Multiply halfs.

This operation uses the underlying single-precision implementation.

Parameters
aleft operand
bright operand
Returns
product of halfs
half half_float::operator/ ( half  a,
half  b 
)

Divide halfs.

This operation uses the underlying single-precision implementation.

Parameters
aleft operand
bright operand
Returns
quotient of halfs
half constexpr half_float::operator+ ( half  h)

Identity.

Parameters
hoperand
Returns
uncahnged operand
half constexpr half_float::operator- ( half  h)

Negation.

Parameters
hoperand
Returns
negated operand
std::basic_ostream<charT,traits>& half_float::operator<< ( std::basic_ostream< charT, traits > &  out,
half  h 
)

Output operator.

Template Parameters
charTcharacter type
traitscharacter traits
Parameters
outoutput stream to write into
hhalf to write
Returns
reference to output stream
std::basic_istream<charT,traits>& half_float::operator>> ( std::basic_istream< charT, traits > &  in,
half &  h 
)

Input operator.

Template Parameters
charTcharacter type
traitscharacter traits
Parameters
ininput stream to read from
hhalf to read into
Returns
reference to input stream
half half_float::abs ( half  arg)

Absolute value.

Parameters
argoperand
Returns
absolute value of arg
half half_float::fabs ( half  arg)

Absolute value.

Parameters
argoperand
Returns
absolute value of arg
half half_float::fmod ( half  x,
half  y 
)

Remainder of division.

This function uses the underlying single-precision implementation.

Parameters
xfirst operand
ysecond operand
Returns
remainder of floating point division.
half half_float::remainder ( half  x,
half  y 
)

Remainder of division.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
xfirst operand
ysecond operand
Returns
remainder of floating point division.
half half_float::remquo ( half  x,
half  y,
int *  quo 
)

Remainder of division.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
xfirst operand
ysecond operand
quoaddress to store some bits of quotient at
Returns
remainder of floating point division.
half half_float::fma ( half  x,
half  y,
half  z 
)

Fused multiply add.

This function uses the underlying single-precision implementation from C++11 <cmath> if it is supported and faster than the straight-forward single-precision implementation (thus if FP_FAST_FMAF is defined).

Parameters
xfirst operand
ysecond operand
zthird operand
Returns
( x * y ) + z rounded as one operation.
half half_float::fmin ( half  x,
half  y 
)

Minimum of halfs.

Parameters
xfirst operand
ysecond operand
Returns
minimum of operands
half half_float::fmax ( half  x,
half  y 
)

Maximum of halfs.

Parameters
xfirst operand
ysecond operand
Returns
maximum of operands
half half_float::fdim ( half  x,
half  y 
)

Positive difference.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
xfirst operand
ysecond operand
Returns
x - y or 0 if difference negative
half half_float::nanh ( const char *  )

Get NaN value.

Returns
quiet NaN
half half_float::exp ( half  arg)

Exponential function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
e raised to arg
half half_float::exp2 ( half  arg)

Binary exponential.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
2 raised to arg
half half_float::expm1 ( half  arg)

Exponential minus one.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
e raised to arg and subtracted by 1
half half_float::log ( half  arg)

Natural logorithm.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
logarithm of arg to base e
half half_float::log10 ( half  arg)

Common logorithm.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
logarithm of arg to base 10
half half_float::log1p ( half  arg)

Natural logorithm.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
logarithm of arg + 1 to base e
half half_float::log2 ( half  arg)

Binary logorithm.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
logarithm of arg to base 2
half half_float::sqrt ( half  arg)

Square root.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
square root of arg
half half_float::cbrt ( half  arg)

Cubic root.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
cubic root of arg
half half_float::hypot ( half  x,
half  y 
)

Hypotenuse function.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
xfirst argument
ysecond argument
Returns
square root of sum of squares without internal over- or underflows
half half_float::pow ( half  base,
half  exp 
)

Power function.

This function uses the underlying single-precision implementation.

Parameters
basefirst argument
expsecond argument
Returns
base raised to exp
half half_float::sin ( half  arg)

Sine function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
sine value of arg
half half_float::cos ( half  arg)

Cosine function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
cosine value of arg
half half_float::tan ( half  arg)

Tangent function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
tangent value of arg
half half_float::asin ( half  arg)

Arc sine.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
arc sine value of arg
half half_float::acos ( half  arg)

Arc cosine function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
arc cosine value of arg
half half_float::atan ( half  arg)

Arc tangent function.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
arc tangent value of arg
half half_float::atan2 ( half  x,
half  y 
)

Arc tangent function.

This function uses the underlying single-precision implementation.

Parameters
xfirst argument
ysecond argument
Returns
arc tangent value
half half_float::sinh ( half  arg)

Hyperbolic sine.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
hyperbolic sine value of arg
half half_float::cosh ( half  arg)

Hyperbolic cosine.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
hyperbolic cosine value of arg
half half_float::tanh ( half  arg)

Hyperbolic tangent.

This function uses the underlying single-precision implementation.

Parameters
argfunction argument
Returns
hyperbolic tangent value of arg
half half_float::asinh ( half  arg)

Hyperbolic area sine.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
hyperbolic area sine value of arg
half half_float::acosh ( half  arg)

Hyperbolic area cosine.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
hyperbolic area cosine value of arg
half half_float::atanh ( half  arg)

Hyperbolic area tangent.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
hyperbolic area tangent value of arg
half half_float::erf ( half  arg)

Error function.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
error function value of arg
half half_float::erfc ( half  arg)

Complementary error function.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
1 minus error function value of arg
half half_float::lgamma ( half  arg)

Natural logarithm of gamma function.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
natural logarith of gamma function for arg
half half_float::tgamma ( half  arg)

Gamma function.

This function uses the underlying single-precision implementation if C++11 <cmath> functions are supported.

Parameters
argfunction argument
Returns
gamma function value of arg
half half_float::ceil ( half  arg)

Nearest integer not less than half value.

Parameters
arghalf to round
Returns
nearest integer not less than arg
half half_float::floor ( half  arg)

Nearest integer not greater than half value.

Parameters
arghalf to round
Returns
nearest integer not greater than arg
half half_float::trunc ( half  arg)

Nearest integer not greater in magnitude than half value.

Parameters
arghalf to round
Returns
nearest integer not greater in magnitude than arg
half half_float::round ( half  arg)

Nearest integer.

Parameters
arghalf to round
Returns
nearest integer, rounded away from zero in half-way cases
long half_float::lround ( half  arg)

Nearest integer.

Parameters
arghalf to round
Returns
nearest integer, rounded away from zero in half-way cases
long long half_float::llround ( half  arg)

Nearest integer.

This function requires support for C++11 long long.

Parameters
arghalf to round
Returns
nearest integer, rounded away from zero in half-way cases
half half_float::nearbyint ( half  arg)

Nearest integer.

Template Parameters
Etype of half expression
Parameters
arghalf expression to round
Returns
nearest integer using default rounding mode
half half_float::rint ( half  arg)

Nearest integer.

Template Parameters
Etype of half expression
Parameters
arghalf expression to round
Returns
nearest integer using default rounding mode
long half_float::lrint ( half  arg)

Nearest integer.

Template Parameters
Etype of half expression
Parameters
arghalf expression to round
Returns
nearest integer using default rounding mode
long long half_float::llrint ( half  arg)

Nearest integer.

This function requires support for C++11 long long.

Template Parameters
Etype of half expression
Parameters
arghalf expression to round
Returns
nearest integer using default rounding mode
half half_float::frexp ( half  arg,
int *  exp 
)

Decompress floating point number.

Parameters
argnumber to decompress
expaddress to store exponent at
Returns
significant in range [0.5, 1)
half half_float::ldexp ( half  arg,
int  exp 
)

Multiply by power of two.

Parameters
argnumber to modify
exppower of two to multiply with
Returns
arg multplied by 2 raised to exp
half half_float::modf ( half  x,
half *  iptr 
)

Extract integer and fractional parts.

Parameters
xnumber to decompress
iptraddress to store integer part at
Returns
fractional part
half half_float::scalbn ( half  x,
int  exp 
)

Multiply by power of two.

Parameters
xnumber to modify
exppower of two to multiply with
Returns
arg multplied by 2 raised to exp
half half_float::scalbln ( half  x,
long  exp 
)

Multiply by power of two.

Parameters
xnumber to modify
exppower of two to multiply with
Returns
arg multplied by 2 raised to exp
int half_float::ilogb ( half  arg)

Extract exponent.

Parameters
argnumber to query
Returns
floating point exponent
Return values
FP_ILOGB0for zero
FP_ILOGBNANfor NaN
MAX_INTfor infinity
half half_float::logb ( half  arg)

Extract exponent.

Parameters
argnumber to query
Returns
floating point exponent
half half_float::nextafter ( half  from,
half  to 
)

Next representable value.

Parameters
fromvalue to compute next representable value for
todirection towards which to compute next value
Returns
next representable value after from in direction towards to
half half_float::nexttoward ( half  from,
long double  to 
)

Next representable value.

Parameters
fromvalue to compute next representable value for
todirection towards which to compute next value
Returns
next representable value after from in direction towards to
half half_float::copysign ( half  x,
half  y 
)

Take sign.

Parameters
xvalue to change sign for
yvalue to take sign from
Returns
value equal to x in magnitude and to y in sign
int half_float::fpclassify ( half  arg)

Classify floating point value.

Parameters
argnumber to classify
Return values
FP_ZEROfor positive and negative zero
FP_SUBNORMALfor subnormal numbers
FP_INFINITYfor positive and negative infinity
FP_NANfor NaNs
FP_NORMALfor all other (normal) values
bool half_float::isfinite ( half  arg)

Check if finite number.

Parameters
argnumber to check
Return values
trueif neither infinity nor NaN
falseelse
bool half_float::isinf ( half  arg)

Check for infinity.

Parameters
argnumber to check
Return values
truefor positive or negative infinity
falseelse
bool half_float::isnan ( half  arg)

Check for NaN.

Parameters
argnumber to check
Return values
truefor NaNs
falseelse
bool half_float::isnormal ( half  arg)

Check if normal number.

Parameters
argnumber to check
Return values
trueif normal number
falseif either subnormal, zero, infinity or NaN
bool half_float::signbit ( half  arg)

Check sign.

Parameters
argnumber to check
Return values
truefor negative number
falsefor positive number
bool half_float::isgreater ( half  x,
half  y 
)

Comparison for greater than.

Parameters
xfirst operand
ysecond operand
Return values
trueif x greater than y
falseelse
bool half_float::isgreaterequal ( half  x,
half  y 
)

Comparison for greater equal.

Parameters
xfirst operand
ysecond operand
Return values
trueif x greater equal y
falseelse
bool half_float::isless ( half  x,
half  y 
)

Comparison for less than.

Parameters
xfirst operand
ysecond operand
Return values
trueif x less than y
falseelse
bool half_float::islessequal ( half  x,
half  y 
)

Comparison for less equal.

Parameters
xfirst operand
ysecond operand
Return values
trueif x less equal y
falseelse
bool half_float::islessgreater ( half  x,
half  y 
)

Comarison for less or greater.

Parameters
xfirst operand
ysecond operand
Return values
trueif either less or greater
falseelse
bool half_float::isunordered ( half  x,
half  y 
)

Check if unordered.

Parameters
xfirst operand
ysecond operand
Return values
trueif unordered (one or two NaN operands)
falseelse
T half_float::half_cast ( const U &  arg)

Cast to or from half-precision floating point number.

This casts between half and any built-in arithmetic type. Floating point types are converted via an explicit cast to/from float (using the rounding mode of the built-in single precision implementation) and thus any possible warnings due to an otherwise implicit conversion to/from float will be suppressed. Integer types are converted directly using the given rounding mode, without any roundtrip over float that a static_cast would otherwise do. It uses the default rounding mode.

Using this cast with neither of the two types being a half or with any of the two types not being a built-in arithmetic type (apart from half, of course) results in a compiler error and casting between halfs is just a no-op.

Template Parameters
Tdestination type (half or built-in arithmetic type)
Usource type (half or built-in arithmetic type)
Parameters
argvalue to cast
Returns
arg converted to destination type
T half_float::half_cast ( const U &  arg)

Cast to or from half-precision floating point number.

This casts between half and any built-in arithmetic type. Floating point types are converted via an explicit cast to/from float (using the rounding mode of the built-in single precision implementation) and thus any possible warnings due to an otherwise implicit conversion to/from float will be suppressed. Integer types are converted directly using the given rounding mode, without any roundtrip over float that a static_cast would otherwise do.

Using this cast with neither of the two types being a half or with any of the two types not being a built-in arithmetic type (apart from half, of course) results in a compiler error and casting between halfs is just a no-op.

Template Parameters
Tdestination type (half or built-in arithmetic type)
Rrounding mode to use (see std::float_round_style)
Usource type (half or built-in arithmetic type)
Parameters
argvalue to cast
Returns
arg converted to destination type