Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
Loading...
Searching...
No Matches
sw::universal::bfloat16 Class Reference

#include <bfloat16_impl.hpp>

Public Member Functions

 bfloat16 ()=default
constexpr bfloat16 (const bfloat16 &)=default
constexpr bfloat16 (bfloat16 &&)=default
constexpr bfloat16 & operator= (const bfloat16 &)=default
constexpr bfloat16 & operator= (bfloat16 &&)=default
constexpr bfloat16 (const SpecificValue code) noexcept
BIT_CAST_CONSTEXPR bfloat16 (signed char iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (short iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (int iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (long iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (long long iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (char iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (unsigned short iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (unsigned int iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (unsigned long iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (unsigned long long iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (float iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 (double iv) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (signed char rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (short rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (int rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (long rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (long long rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (char rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (unsigned short rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (unsigned int rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (unsigned long rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (unsigned long long rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (float rhs) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator= (double rhs) noexcept
template<typename Integer>
BIT_CAST_CONSTEXPR Integer to_integer () const noexcept
BIT_CAST_CONSTEXPR operator signed char () const noexcept
BIT_CAST_CONSTEXPR operator short () const noexcept
BIT_CAST_CONSTEXPR operator int () const noexcept
BIT_CAST_CONSTEXPR operator long () const noexcept
BIT_CAST_CONSTEXPR operator long long () const noexcept
BIT_CAST_CONSTEXPR operator char () const noexcept
BIT_CAST_CONSTEXPR operator unsigned short () const noexcept
BIT_CAST_CONSTEXPR operator unsigned int () const noexcept
BIT_CAST_CONSTEXPR operator unsigned long () const noexcept
BIT_CAST_CONSTEXPR operator unsigned long long () const noexcept
BIT_CAST_CONSTEXPR operator float () const noexcept
BIT_CAST_CONSTEXPR operator double () const noexcept
constexpr bfloat16 operator- () const noexcept
constexpr bfloat16 & operator++ () noexcept
constexpr bfloat16 operator++ (int) noexcept
constexpr bfloat16 & operator-- () noexcept
constexpr bfloat16 operator-- (int) noexcept
BIT_CAST_CONSTEXPR bfloat16 & operator+= (const bfloat16 &rhs)
BIT_CAST_CONSTEXPR bfloat16 & operator-= (const bfloat16 &rhs)
BIT_CAST_CONSTEXPR bfloat16 & operator*= (const bfloat16 &rhs)
BIT_CAST_CONSTEXPR bfloat16 & operator/= (const bfloat16 &rhs)
constexpr void clear () noexcept
constexpr void setzero () noexcept
constexpr void setnan (int NaNType=NAN_TYPE_SIGNALLING) noexcept
constexpr void setinf (bool sign=false) noexcept
constexpr void setbit (unsigned i, bool v=true) noexcept
constexpr void setbits (unsigned value) noexcept
constexpr bfloat16 & minpos () noexcept
constexpr bfloat16 & maxpos () noexcept
constexpr bfloat16 & zero () noexcept
constexpr bfloat16 & minneg () noexcept
constexpr bfloat16 & maxneg () noexcept
bfloat16 & assign (const std::string &str) noexcept
 assign an encoding given as a binary string
constexpr bool iszero () const noexcept
constexpr bool isone () const noexcept
constexpr bool isodd () const noexcept
constexpr bool iseven () const noexcept
bool isinteger () const noexcept
constexpr bool ispos () const noexcept
constexpr bool isneg () const noexcept
constexpr bool isnan (int NaNType=NAN_TYPE_EITHER) const noexcept
constexpr bool isinf (int InfType=INF_TYPE_EITHER) const noexcept
constexpr bool sign () const noexcept
constexpr int scale () const noexcept
constexpr unsigned short bits () const noexcept
constexpr bool test (unsigned bitIndex) const noexcept
constexpr bool at (unsigned bitIndex) const noexcept
constexpr uint8_t nibble (unsigned n) const noexcept
constexpr uint8_t exponent () const noexcept
constexpr uint8_t fraction () const noexcept

Static Public Attributes

static constexpr unsigned nbits = 16
static constexpr unsigned es = 8
static constexpr unsigned fbits = nbits - 1u - es

Protected Attributes

unsigned short _bits

Friends

constexpr bool operator== (bfloat16 lhs, bfloat16 rhs)
BIT_CAST_CONSTEXPR bool operator== (bfloat16 lhs, float rhs)
BIT_CAST_CONSTEXPR bool operator== (float lhs, bfloat16 rhs)

Constructor & Destructor Documentation

◆ bfloat16() [1/16]

sw::universal::bfloat16::bfloat16 ( )
default

◆ bfloat16() [2/16]

sw::universal::bfloat16::bfloat16 ( const bfloat16 & )
constexprdefault

◆ bfloat16() [3/16]

sw::universal::bfloat16::bfloat16 ( bfloat16 && )
constexprdefault

◆ bfloat16() [4/16]

sw::universal::bfloat16::bfloat16 ( const SpecificValue code)
inlineconstexprnoexcept

◆ bfloat16() [5/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( signed char iv)
inlinenoexcept

◆ bfloat16() [6/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( short iv)
inlinenoexcept

◆ bfloat16() [7/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( int iv)
inlinenoexcept

◆ bfloat16() [8/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( long iv)
inlinenoexcept

◆ bfloat16() [9/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( long long iv)
inlinenoexcept

◆ bfloat16() [10/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( char iv)
inlinenoexcept

◆ bfloat16() [11/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( unsigned short iv)
inlinenoexcept

◆ bfloat16() [12/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( unsigned int iv)
inlinenoexcept

◆ bfloat16() [13/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( unsigned long iv)
inlinenoexcept

◆ bfloat16() [14/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( unsigned long long iv)
inlinenoexcept

◆ bfloat16() [15/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( float iv)
inlineexplicitnoexcept

◆ bfloat16() [16/16]

BIT_CAST_CONSTEXPR sw::universal::bfloat16::bfloat16 ( double iv)
inlineexplicitnoexcept

Member Function Documentation

◆ assign()

bfloat16 & sw::universal::bfloat16::assign ( const std::string & str)
inlinenoexcept

assign an encoding given as a binary string

Parameters
str"0b", then the sign, exponent and fraction bits with the three fields separated by '.'; ' may separate digits. The bit count must match the type.
Returns
reference to this bfloat16; on a malformed string it is left at zero and the reason is printed to stderr

Clang doesn't support constexpr yet on string manipulations, so we need to make it conditional

◆ at()

bool sw::universal::bfloat16::at ( unsigned bitIndex) const
inlineconstexprnoexcept

◆ bits()

unsigned short sw::universal::bfloat16::bits ( ) const
inlineconstexprnoexcept

◆ clear()

void sw::universal::bfloat16::clear ( )
inlineconstexprnoexcept

◆ exponent()

uint8_t sw::universal::bfloat16::exponent ( ) const
inlineconstexprnoexcept

◆ fraction()

uint8_t sw::universal::bfloat16::fraction ( ) const
inlineconstexprnoexcept

◆ iseven()

bool sw::universal::bfloat16::iseven ( ) const
inlineconstexprnoexcept

◆ isinf()

bool sw::universal::bfloat16::isinf ( int InfType = INF_TYPE_EITHER) const
inlineconstexprnoexcept

◆ isinteger()

bool sw::universal::bfloat16::isinteger ( ) const
inlinenoexcept

◆ isnan()

bool sw::universal::bfloat16::isnan ( int NaNType = NAN_TYPE_EITHER) const
inlineconstexprnoexcept

◆ isneg()

bool sw::universal::bfloat16::isneg ( ) const
inlineconstexprnoexcept

◆ isodd()

bool sw::universal::bfloat16::isodd ( ) const
inlineconstexprnoexcept

◆ isone()

bool sw::universal::bfloat16::isone ( ) const
inlineconstexprnoexcept

◆ ispos()

bool sw::universal::bfloat16::ispos ( ) const
inlineconstexprnoexcept

◆ iszero()

bool sw::universal::bfloat16::iszero ( ) const
inlineconstexprnoexcept

◆ maxneg()

bfloat16 & sw::universal::bfloat16::maxneg ( )
inlineconstexprnoexcept

◆ maxpos()

bfloat16 & sw::universal::bfloat16::maxpos ( )
inlineconstexprnoexcept

◆ minneg()

bfloat16 & sw::universal::bfloat16::minneg ( )
inlineconstexprnoexcept

◆ minpos()

bfloat16 & sw::universal::bfloat16::minpos ( )
inlineconstexprnoexcept

◆ nibble()

uint8_t sw::universal::bfloat16::nibble ( unsigned n) const
inlineconstexprnoexcept

◆ operator char()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator char ( ) const
inlineexplicitnoexcept

◆ operator double()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator double ( ) const
inlineexplicitnoexcept

◆ operator float()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator float ( ) const
inlineexplicitnoexcept

◆ operator int()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator int ( ) const
inlineexplicitnoexcept

◆ operator long()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator long ( ) const
inlineexplicitnoexcept

◆ operator long long()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator long long ( ) const
inlineexplicitnoexcept

◆ operator short()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator short ( ) const
inlineexplicitnoexcept

◆ operator signed char()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator signed char ( ) const
inlineexplicitnoexcept

◆ operator unsigned int()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator unsigned int ( ) const
inlineexplicitnoexcept

◆ operator unsigned long()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator unsigned long ( ) const
inlineexplicitnoexcept

◆ operator unsigned long long()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator unsigned long long ( ) const
inlineexplicitnoexcept

◆ operator unsigned short()

BIT_CAST_CONSTEXPR sw::universal::bfloat16::operator unsigned short ( ) const
inlineexplicitnoexcept

◆ operator*=()

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator*= ( const bfloat16 & rhs)
inline

◆ operator++() [1/2]

bfloat16 & sw::universal::bfloat16::operator++ ( )
inlineconstexprnoexcept

◆ operator++() [2/2]

bfloat16 sw::universal::bfloat16::operator++ ( int )
inlineconstexprnoexcept

◆ operator+=()

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator+= ( const bfloat16 & rhs)
inline

◆ operator-()

bfloat16 sw::universal::bfloat16::operator- ( ) const
inlineconstexprnoexcept

◆ operator--() [1/2]

bfloat16 & sw::universal::bfloat16::operator-- ( )
inlineconstexprnoexcept

◆ operator--() [2/2]

bfloat16 sw::universal::bfloat16::operator-- ( int )
inlineconstexprnoexcept

◆ operator-=()

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator-= ( const bfloat16 & rhs)
inline

◆ operator/=()

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator/= ( const bfloat16 & rhs)
inline

◆ operator=() [1/14]

bfloat16 & sw::universal::bfloat16::operator= ( bfloat16 && )
constexprdefault

◆ operator=() [2/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( char rhs)
inlinenoexcept

◆ operator=() [3/14]

bfloat16 & sw::universal::bfloat16::operator= ( const bfloat16 & )
constexprdefault

◆ operator=() [4/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( double rhs)
inlinenoexcept

◆ operator=() [5/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( float rhs)
inlinenoexcept

◆ operator=() [6/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( int rhs)
inlinenoexcept

◆ operator=() [7/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( long long rhs)
inlinenoexcept

◆ operator=() [8/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( long rhs)
inlinenoexcept

◆ operator=() [9/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( short rhs)
inlinenoexcept

◆ operator=() [10/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( signed char rhs)
inlinenoexcept

◆ operator=() [11/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( unsigned int rhs)
inlinenoexcept

◆ operator=() [12/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( unsigned long long rhs)
inlinenoexcept

◆ operator=() [13/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( unsigned long rhs)
inlinenoexcept

◆ operator=() [14/14]

BIT_CAST_CONSTEXPR bfloat16 & sw::universal::bfloat16::operator= ( unsigned short rhs)
inlinenoexcept

◆ scale()

int sw::universal::bfloat16::scale ( ) const
inlineconstexprnoexcept

◆ setbit()

void sw::universal::bfloat16::setbit ( unsigned i,
bool v = true )
inlineconstexprnoexcept

◆ setbits()

void sw::universal::bfloat16::setbits ( unsigned value)
inlineconstexprnoexcept

◆ setinf()

void sw::universal::bfloat16::setinf ( bool sign = false)
inlineconstexprnoexcept

◆ setnan()

void sw::universal::bfloat16::setnan ( int NaNType = NAN_TYPE_SIGNALLING)
inlineconstexprnoexcept

◆ setzero()

void sw::universal::bfloat16::setzero ( )
inlineconstexprnoexcept

◆ sign()

bool sw::universal::bfloat16::sign ( ) const
inlineconstexprnoexcept

◆ test()

bool sw::universal::bfloat16::test ( unsigned bitIndex) const
inlineconstexprnoexcept

◆ to_integer()

template<typename Integer>
BIT_CAST_CONSTEXPR Integer sw::universal::bfloat16::to_integer ( ) const
inlinenoexcept

◆ zero()

bfloat16 & sw::universal::bfloat16::zero ( )
inlineconstexprnoexcept

◆ operator== [1/3]

bool operator== ( bfloat16 lhs,
bfloat16 rhs )
friend

◆ operator== [2/3]

BIT_CAST_CONSTEXPR bool operator== ( bfloat16 lhs,
float rhs )
friend

◆ operator== [3/3]

BIT_CAST_CONSTEXPR bool operator== ( float lhs,
bfloat16 rhs )
friend

Member Data Documentation

◆ _bits

unsigned short sw::universal::bfloat16::_bits
protected

◆ es

unsigned sw::universal::bfloat16::es = 8
staticconstexpr

◆ fbits

unsigned sw::universal::bfloat16::fbits = nbits - 1u - es
staticconstexpr

◆ nbits

unsigned sw::universal::bfloat16::nbits = 16
staticconstexpr

The documentation for this class was generated from the following file:
  • /home/runner/work/universal/universal/include/sw/universal/number/bfloat16/bfloat16_impl.hpp