|
Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
|
a block-based floating-point fraction More...
#include <blockfraction.hpp>
Public Types | |
| typedef bt | BlockType |
Public Member Functions | |
| constexpr | blockfraction () noexcept |
| NOTE: don't set a default blocktype as this makes the integration more brittle as blocktriple uses the blocksignificant as storage class and needs to interact with the client number system, which is also blocked. | |
| template<size_t... I> | |
| constexpr | blockfraction (const uint64_t raw, int radixPoint, std::index_sequence< I... >) noexcept |
| constexpr | blockfraction (const uint64_t raw, int radixPoint) noexcept |
| constexpr | blockfraction (const blockfraction &) noexcept=default |
| constexpr | blockfraction (blockfraction &&) noexcept=default |
| constexpr blockfraction & | operator= (const blockfraction &) noexcept=default |
| constexpr blockfraction & | operator= (blockfraction &&) noexcept=default |
| constexpr | operator float () const noexcept |
| explicit conversion operators | |
| constexpr | operator double () const noexcept |
| constexpr blockfraction | operator~ () const noexcept |
| prefix operators | |
| constexpr bool | anyAfter (unsigned bitIndex) const noexcept |
| logic operators | |
| constexpr void | increment () noexcept |
| arithmetic operators | |
| void | add (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| add two fractions of the form 00h.fffff, that is, radix point at nbits-3 In this encoding, all valid values are encapsulated | |
| void | sub (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| void | mul (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| void | div (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| void | scaleByBase (const blockfraction &fraction, const blockfraction &integerBase) noexcept |
| constexpr blockfraction & | operator<<= (int bitsToShift) noexcept |
| constexpr blockfraction & | operator>>= (int bitsToShift) noexcept |
| constexpr void | clear () noexcept |
| constexpr void | setzero () noexcept |
| constexpr void | setradix (int radix) noexcept |
| constexpr void | setbit (unsigned i, bool v=true) noexcept |
| constexpr void | setblock (unsigned b, const bt &block) noexcept |
| constexpr void | setbits (uint64_t value) noexcept |
| constexpr blockfraction & | flip () noexcept |
| constexpr blockfraction & | twosComplement () noexcept |
| constexpr bool | iszero () const noexcept |
| constexpr int | radix () const noexcept |
| constexpr bool | isodd () const noexcept |
| constexpr bool | iseven () const noexcept |
| constexpr bool | sign () const noexcept |
| constexpr bool | isneg () const noexcept |
| constexpr unsigned | integer () const noexcept |
| constexpr bool | test (unsigned bitIndex) const noexcept |
| constexpr bool | at (unsigned bitIndex) const noexcept |
| constexpr bool | checkCarry () const noexcept |
| constexpr uint8_t | nibble (unsigned n) const noexcept |
| constexpr bt | block (unsigned b) const noexcept |
| constexpr blockfraction | fraction () const noexcept |
| constexpr int | msb () const noexcept |
| constexpr float | to_float () const noexcept |
| constexpr double | to_double () const noexcept |
| constexpr bool | roundingDirection (unsigned targetLsb) const noexcept |
| constexpr bool | any (unsigned msb) const noexcept |
Public Attributes | |
| int | radixPoint |
| bt | _block [nrBlocks] |
Static Public Attributes | |
| static constexpr unsigned | nbits = _nbits |
| static constexpr unsigned | bitsInByte = 8 |
| static constexpr unsigned | bitsInBlock = sizeof(bt) * bitsInByte |
| static constexpr unsigned | nrBlocks = 1ull + ((nbits - 1ull) / bitsInBlock) |
| static constexpr uint64_t | storageMask = (0xFFFF'FFFF'FFFF'FFFFull >> (64 - bitsInBlock)) |
| static constexpr uint64_t | maxRightShift = ((64 - nbits + 3) > 62) ? 63 : (64 - nbits + 3) |
| static constexpr uint64_t | fmask = (64 - nbits + 3) > 63 ? 0ull : (0xFFFF'FFFF'FFFF'FFFFull >> maxRightShift) |
| static constexpr unsigned | MSU = nrBlocks - 1 |
| static constexpr bt | ALL_ONES = bt(~0) |
| static constexpr bt | MSU_MASK = (ALL_ONES >> (nrBlocks * bitsInBlock - nbits)) |
| static constexpr bt | OVERFLOW_BIT = ~(MSU_MASK >> 1) & MSU_MASK |
Friends | |
| constexpr bool | operator== (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr bool | operator!= (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr bool | operator< (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr bool | operator<= (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr bool | operator> (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr bool | operator>= (const blockfraction &lhs, const blockfraction &rhs) noexcept |
| constexpr blockfraction | operator<< (const blockfraction &a, const long b) noexcept |
| constexpr blockfraction | operator>> (const blockfraction &a, const long b) noexcept |
a block-based floating-point fraction
A blockfraction is by definition an unsigned entity. As arithmetic operators introduce additional bits, the radixpoint is controllable.
| bt |
| typedef bt sw::universal::blockfraction< _nbits, bt >::BlockType |
|
inlineconstexprnoexcept |
NOTE: don't set a default blocktype as this makes the integration more brittle as blocktriple uses the blocksignificant as storage class and needs to interact with the client number system, which is also blocked.
Using the same blocktype simplifies the copying of fraction bits from and to the client.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
|
inlinenoexcept |
add two fractions of the form 00h.fffff, that is, radix point at nbits-3 In this encoding, all valid values are encapsulated
| lhs | nbits of fraction in the form 00h.ffff |
| rhs | nbits of fraction in the form 00h.ffff |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
logic operators
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
arithmetic operators
increment the value by one
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineexplicitconstexprnoexcept |
|
inlineexplicitconstexprnoexcept |
explicit conversion operators
|
inlineconstexprnoexcept |
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
prefix operators
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
| bt sw::universal::blockfraction< _nbits, bt >::_block[nrBlocks] |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
| int sw::universal::blockfraction< _nbits, bt >::radixPoint |
|
staticconstexpr |