|
Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
|
Generalized blocktriple representing a (sign, scale, significand) with unrounded arithmetic. More...
#include <blocktriple.hpp>
Public Types | |
| typedef bt | BlockType |
| using | significand_t = sw::universal::blocksignificand<bfbits, bt> |
Public Member Functions | |
| constexpr | blocktriple (const blocktriple &) noexcept=default |
| constexpr | blocktriple (blocktriple &&) noexcept=default |
| constexpr blocktriple & | operator= (const blocktriple &) noexcept=default |
| constexpr blocktriple & | operator= (blocktriple &&) noexcept=default |
| constexpr | blocktriple () noexcept |
| constexpr | blocktriple (signed char iv) noexcept |
| constexpr | blocktriple (short iv) noexcept |
| constexpr | blocktriple (int iv) noexcept |
| constexpr | blocktriple (long iv) noexcept |
| constexpr | blocktriple (long long iv) noexcept |
| constexpr | blocktriple (char iv) noexcept |
| constexpr | blocktriple (unsigned char iv) noexcept |
| constexpr | blocktriple (unsigned short iv) noexcept |
| constexpr | blocktriple (unsigned int iv) noexcept |
| constexpr | blocktriple (unsigned long iv) noexcept |
| constexpr | blocktriple (unsigned long long iv) noexcept |
| constexpr | blocktriple (float iv) noexcept |
| constexpr | blocktriple (double iv) noexcept |
| constexpr blocktriple & | operator= (signed char rhs) noexcept |
| constexpr blocktriple & | operator= (short rhs) noexcept |
| constexpr blocktriple & | operator= (int rhs) noexcept |
| constexpr blocktriple & | operator= (long rhs) noexcept |
| constexpr blocktriple & | operator= (long long rhs) noexcept |
| constexpr blocktriple & | operator= (char rhs) noexcept |
| constexpr blocktriple & | operator= (unsigned char rhs) noexcept |
| constexpr blocktriple & | operator= (unsigned short rhs) noexcept |
| constexpr blocktriple & | operator= (unsigned int rhs) noexcept |
| constexpr blocktriple & | operator= (unsigned long rhs) noexcept |
| constexpr blocktriple & | operator= (unsigned long long rhs) noexcept |
| constexpr blocktriple & | operator= (float rhs) noexcept |
| constexpr blocktriple & | operator= (double rhs) noexcept |
| CONSTEXPRESSION blocktriple & | assign (const std::string &bitPattern) noexcept |
| operator float () const noexcept | |
| operator double () const noexcept | |
| constexpr blocktriple & | operator- () noexcept |
| constexpr blocktriple & | operator<<= (int leftShift) noexcept |
| constexpr blocktriple & | operator>>= (int rightShift) noexcept |
| constexpr blocktriple & | bitShift (int leftShift) noexcept |
| constexpr std::pair< bool, unsigned > | roundingDecision (int adjustment=0) const noexcept |
| roundingDecision returns a pair<bool, unsigned> to direct the rounding and right shift | |
| constexpr blocktriple & | twosComplement () noexcept |
| constexpr void | clear () noexcept |
| constexpr void | setzero (bool sign=false) noexcept |
| constexpr void | setnan (bool sign=true) noexcept |
| constexpr void | setinf (bool sign) noexcept |
| constexpr void | setpos () noexcept |
| constexpr void | setnormal () noexcept |
| constexpr void | setsign (bool s) noexcept |
| constexpr void | setscale (int scale) noexcept |
| constexpr void | setradix () noexcept |
| constexpr void | setradix (int _radix) noexcept |
| constexpr void | setbit (unsigned index, bool v=true) noexcept |
| constexpr void | setbits (uint64_t raw) noexcept |
| constexpr void | setblock (unsigned i, const bt &block) noexcept |
| constexpr void | set (bool sign, int scale, uint64_t raw, bool inf=false, bool nan=false) noexcept |
| constexpr bool | isnan () const noexcept |
| constexpr bool | isinf () const noexcept |
| constexpr bool | iszero () const noexcept |
| constexpr bool | ispos () const noexcept |
| constexpr bool | isneg () const noexcept |
| constexpr bool | sign () const noexcept |
| constexpr int | scale () const noexcept |
| constexpr int | significandscale () const noexcept |
| constexpr significand_t | significand () const noexcept |
| constexpr significand_t | fraction () const noexcept |
| constexpr uint64_t | significand_ull () const noexcept |
| constexpr uint64_t | fraction_ull () const noexcept |
| constexpr bool | at (unsigned index) const noexcept |
| constexpr bool | test (unsigned index) const noexcept |
| constexpr bool | any (unsigned index) const noexcept |
| constexpr bt | block (unsigned b) const noexcept |
| void | traceSignificandOp (const char *header, const char *label, const blocktriple &lhs, const blocktriple &rhs) const |
| void | traceNormalizedOp (const char *header, const char *label, const blocktriple &lhs, const blocktriple &rhs) const |
| std::string | to_string (std::streamsize precision=7, std::streamsize width=0, bool fixed=false, bool scientific=true, bool internal=false, bool left=false, bool showpos=false, bool uppercase=false, char fill=' ') const |
| void | constexprClassParameters () const |
| constexpr void | add (blocktriple &lhs, blocktriple &rhs) |
| add two fixed-point numbers with fbits fraction bits and a leading 1 yielding an unrounded sum of 3+fbits. | |
| constexpr void | sub (blocktriple &lhs, blocktriple &rhs) |
| constexpr void | mul (blocktriple &lhs, blocktriple &rhs) |
| multiply two real numbers with fbits fraction bits yielding an 2*(1+fbits) unrounded product. | |
| constexpr void | div (blocktriple &lhs, blocktriple &rhs) |
Static Public Attributes | |
| static constexpr unsigned | fbits = _fbits |
| static constexpr unsigned | nbits = fbits |
| static constexpr BlockTripleOperator | op = _op |
| static constexpr unsigned | bitsInByte = 8ull |
| static constexpr unsigned | bitsInBlock = sizeof(bt) * bitsInByte |
| static constexpr unsigned | nrBlocks = 1ull + ((fbits - 1ull) / bitsInBlock) |
| static constexpr uint64_t | storageMask = (0xFFFF'FFFF'FFFF'FFFFull >> (64ull - bitsInBlock)) |
| static constexpr unsigned | MSU = nrBlocks - 1ull |
| static constexpr unsigned | fhbits = fbits + 1 |
| static constexpr unsigned | rbits = 3 |
| static constexpr unsigned | abits = fbits + rbits |
| static constexpr unsigned | mbits = 2 * fbits |
| static constexpr unsigned | divbits = 3 * fbits + 4 |
| static constexpr unsigned | divshift = divbits - fbits |
| static constexpr unsigned | sqrtbits = 2 * fhbits |
| static constexpr unsigned | bfbits |
| static constexpr int | radix |
| static constexpr unsigned | normalBits = (bfbits < 64 ? bfbits : 64) |
| static constexpr uint64_t | normalFormMask = (normalBits == 64) ? 0xFFFF'FFFF'FFFF'FFFFull : (~(0xFFFF'FFFF'FFFF'FFFFull << (normalBits - 1))) |
| static constexpr bt | ALL_ONES = bt(~0) |
| static constexpr unsigned | maxbits = (fbits + 1) < 63 ? (fbits + 1) : 63 |
| static constexpr uint64_t | overflowPattern = (maxbits < 63) ? (1ull << maxbits) : 0ull |
Protected Attributes | |
| significand_t | _significand |
Friends | |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| std::string | to_binary (const blocktriple< ffbits, oop, bbt > &, bool) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| std::string | to_triple (const blocktriple< ffbits, oop, bbt > &, bool) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator== (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator!= (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator< (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator> (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator<= (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
| template<unsigned ffbits, BlockTripleOperator oop, typename bbt> | |
| bool | operator>= (const blocktriple< ffbits, oop, bbt > &lhs, const blocktriple< ffbits, oop, bbt > &rhs) |
Generalized blocktriple representing a (sign, scale, significand) with unrounded arithmetic.
For addition and subtraction, blocktriple uses a 2's complement representation of the form iii.fffff. The 3 integer bits are required to capture the negative overflow condition.
For multiplication, blocktriple uses a 1's complement representation of the form ii.fffff. The 2 integer bits are required to capture the overflow condition.
Blocktriple does not normalize the output of ADD/SUB/MUL so that all bits are available for the rounding decision. Number systems that use blocktriple as their general floating-point engine can use the roundUp(targetFbits) method to obtain the rounding direction, and the alignmentShift(targetFbits) method to obtain the shift required to normalize the fraction bits.
| fbits | number of fraction bits in the significand |
| bt | block type: one of [uint8_t, uint16_t, uint32_t, uint64_t] |
| typedef bt sw::universal::blocktriple< _fbits, _op, bt >::BlockType |
| using sw::universal::blocktriple< _fbits, _op, bt >::significand_t = sw::universal::blocksignificand<bfbits, bt> |
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
add two fixed-point numbers with fbits fraction bits and a leading 1 yielding an unrounded sum of 3+fbits.
(currently we generate a 3+(2*fbits) result as we haven't implemented the sticky bit optimization) This sum can overflow, be normal, or denormal. Since we are not rounding we cannot act on overflow as we would potentially shift rounding state out, and thus the output must be processed by the calling environment. We can act on denormalized encodings, so these are processed in this function. To avoid fraction bit copies, the input arguments must be prepared by the calling environment, and this function only manipulates the bits.
| lhs | ephemeral blocktriple that may get modified |
| rhs | ephemeral blocktriple that may get modified |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
| void sw::universal::blocktriple< fbits, op, bt >::constexprClassParameters | ( | ) | const |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
multiply two real numbers with fbits fraction bits yielding an 2*(1+fbits) unrounded product.
This product can overflow, be normal, or denormal. Since we are not rounding we cannot act on overflow as we would potentially shift rounding state out, and thus the output must be processed by the calling environment. We can act on denormalized encodings, so these are processed in this function. To avoid fraction bit copies, the input arguments must be prepared by the calling environment, and this function only manipulates the bits.
| lhs | ephemeral blocktriple that may get modified |
| rhs | ephemeral blocktriple that may get modified |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
constexprdefaultnoexcept |
|
inlineconstexprnoexcept |
|
constexprdefaultnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
roundingDecision returns a pair<bool, unsigned> to direct the rounding and right shift
| adjustment | adjustment for subnormals |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
| std::string sw::universal::blocktriple< fbits, op, bt >::to_string | ( | std::streamsize | precision = 7, |
| std::streamsize | width = 0, | ||
| bool | fixed = false, | ||
| bool | scientific = true, | ||
| bool | internal = false, | ||
| bool | left = false, | ||
| bool | showpos = false, | ||
| bool | uppercase = false, | ||
| char | fill = ' ' ) const |
| void sw::universal::blocktriple< fbits, op, bt >::traceNormalizedOp | ( | const char * | header, |
| const char * | label, | ||
| const blocktriple< _fbits, _op, bt > & | lhs, | ||
| const blocktriple< _fbits, _op, bt > & | rhs ) const |
| void sw::universal::blocktriple< fbits, op, bt >::traceSignificandOp | ( | const char * | header, |
| const char * | label, | ||
| const blocktriple< _fbits, _op, bt > & | lhs, | ||
| const blocktriple< _fbits, _op, bt > & | rhs ) const |
|
inlineconstexprnoexcept |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |