|
Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
|
#include <takum_impl.hpp>
Public Types | |
| typedef bt | BlockType |
| using | Codec = takum_codec<_nbits, _rbits> |
| using | BlockBinary = blockbinary<nbits, bt, BinaryNumberType::Unsigned> |
Public Member Functions | |
| constexpr bool | in_double_safe_range () const noexcept |
| constexpr bool | takes_exact_path (const takum &rhs) const noexcept |
| takum ()=default | |
| trivial constructor | |
| takum (const takum &)=default | |
| takum (takum &&)=default | |
| takum & | operator= (const takum &)=default |
| takum & | operator= (takum &&)=default |
| constexpr | takum (const SpecificValue code) noexcept |
| constexpr | takum (signed char initial_value) noexcept |
| constexpr | takum (short initial_value) noexcept |
| constexpr | takum (int initial_value) noexcept |
| constexpr | takum (long initial_value) noexcept |
| constexpr | takum (long long initial_value) noexcept |
| constexpr | takum (unsigned int initial_value) noexcept |
| constexpr | takum (unsigned long initial_value) noexcept |
| constexpr | takum (unsigned long long initial_value) noexcept |
| constexpr | takum (float initial_value) noexcept |
| constexpr | takum (double initial_value) noexcept |
| constexpr takum & | operator= (signed char rhs) noexcept |
| constexpr takum & | operator= (short rhs) noexcept |
| constexpr takum & | operator= (int rhs) noexcept |
| constexpr takum & | operator= (long rhs) noexcept |
| constexpr takum & | operator= (long long rhs) noexcept |
| constexpr takum & | operator= (char rhs) noexcept |
| constexpr takum & | operator= (unsigned short rhs) noexcept |
| constexpr takum & | operator= (unsigned int rhs) noexcept |
| constexpr takum & | operator= (unsigned long rhs) noexcept |
| constexpr takum & | operator= (unsigned long long rhs) noexcept |
| CONSTEXPRESSION takum & | operator= (float rhs) noexcept |
| CONSTEXPRESSION takum & | operator= (double rhs) noexcept |
| CONSTEXPRESSION | operator int () const noexcept |
| CONSTEXPRESSION | operator long () const noexcept |
| CONSTEXPRESSION | operator long long () const noexcept |
| CONSTEXPRESSION | operator unsigned int () const noexcept |
| CONSTEXPRESSION | operator unsigned long () const noexcept |
| CONSTEXPRESSION | operator unsigned long long () const noexcept |
| CONSTEXPRESSION | operator float () const noexcept |
| CONSTEXPRESSION | operator double () const noexcept |
| constexpr takum | operator- () const noexcept |
| CONSTEXPRESSION takum & | operator+= (const takum &rhs) |
| CONSTEXPRESSION takum & | operator+= (double rhs) |
| CONSTEXPRESSION takum & | operator-= (const takum &rhs) |
| CONSTEXPRESSION takum & | operator-= (double rhs) |
| CONSTEXPRESSION takum & | operator*= (const takum &rhs) |
| CONSTEXPRESSION takum & | operator*= (double rhs) |
| CONSTEXPRESSION takum & | operator/= (const takum &rhs) |
| CONSTEXPRESSION takum & | operator/= (double rhs) |
| constexpr takum_wide::operand | to_wide_operand () const noexcept |
| CONSTEXPRESSION takum & | assign_wide (const takum_wide::wide_value &r) noexcept |
| constexpr takum & | operator++ () noexcept |
| constexpr takum | operator++ (int) noexcept |
| constexpr takum & | operator-- () noexcept |
| constexpr takum | operator-- (int) noexcept |
| constexpr void | clear () noexcept |
| constexpr void | setzero () noexcept |
| constexpr void | setnar () noexcept |
| constexpr void | setnan (bool sign=false) noexcept |
| constexpr void | setinf (bool sign) noexcept |
| constexpr void | setsign (bool s=true) noexcept |
| constexpr void | setbit (unsigned i, bool v=true) noexcept |
| constexpr void | setbits (uint64_t value) noexcept |
| constexpr takum & | maxpos () noexcept |
| constexpr takum & | minpos () noexcept |
| constexpr takum & | zero () noexcept |
| constexpr takum & | minneg () noexcept |
| constexpr takum & | maxneg () noexcept |
| constexpr bool | iszero () const noexcept |
| constexpr bool | isneg () const noexcept |
| constexpr bool | ispos () const noexcept |
| constexpr bool | isinf () const noexcept |
| constexpr bool | isnan () const noexcept |
| constexpr bool | isnar () const noexcept |
| constexpr bool | sign () const noexcept |
| constexpr bool | direct () const noexcept |
| constexpr unsigned | regime () const noexcept |
| constexpr unsigned | dr_field () const noexcept |
| constexpr int64_t | characteristic () const noexcept |
| constexpr int64_t | scale () const noexcept |
| constexpr bool | at (unsigned bitIndex) const noexcept |
| constexpr bt | block (unsigned b) const noexcept |
| constexpr uint8_t | nibble (unsigned n) const noexcept |
| std::string | get () const noexcept |
| constexpr uint64_t | raw_bits () const noexcept |
| constexpr uint64_t | magnitude_bits () const noexcept |
| void | debugConstexprParameters () |
Static Public Member Functions | |
| static constexpr unsigned | dr_to_r (unsigned dr) noexcept |
| static constexpr int64_t | dr_to_c_bias (unsigned dr) noexcept |
| static constexpr unsigned | find_dr (int64_t c) noexcept |
| static constexpr int64_t | max_characteristic () noexcept |
| static constexpr int64_t | min_characteristic () noexcept |
Static Public Attributes | |
| static constexpr unsigned | nbits = _nbits |
| static constexpr unsigned | rbits = _rbits |
| static constexpr unsigned | overhead = Codec::overhead |
| static constexpr unsigned | dr_bits = Codec::dr_bits |
| static constexpr unsigned | nr_dr_values = Codec::nr_dr_values |
| static constexpr unsigned | max_r = Codec::max_r |
| static constexpr unsigned | r_mask = Codec::r_mask |
| static constexpr unsigned | dr_field_mask = Codec::dr_field_mask |
| static constexpr unsigned | bitsInByte = 8ull |
| static constexpr unsigned | bitsInBlock = sizeof(bt) * bitsInByte |
| static constexpr unsigned | nrBlocks = (1 + ((nbits - 1) / bitsInBlock)) |
| static constexpr unsigned | bitsInMSU = (1 + ((nbits - 1) % bitsInBlock)) |
| static constexpr uint64_t | storageMask = (0xFFFFFFFFFFFFFFFFull >> (64 - bitsInBlock)) |
| static constexpr unsigned | MSU = nrBlocks - 1 |
| static constexpr bt | MSU_MASK = bt(bt(~0) >> (nrBlocks * bitsInBlock - nbits)) |
| static constexpr bt | SIGN_BIT_MASK = bt(1ull << ((nbits - 1ull) % bitsInBlock)) |
| static constexpr bt | DIRECTION_BIT_MASK = bt(1ull << ((nbits - 2ull) % bitsInBlock)) |
| static constexpr unsigned | maxCharBits = Codec::maxCharBits |
| static constexpr bool | wide_significand = 2u * (maxCharBits + 1u) + 2u > 53u |
| static constexpr int64_t | double_safe_characteristic = 510 |
| static constexpr bool | range_fits_double |
Protected Member Functions | |
| constexpr takum & | flip () noexcept |
| CONSTEXPRESSION takum & | assign (const std::string &str) noexcept |
| CONSTEXPRESSION takum & | wide_sum (const takum &rhs, bool subtract) noexcept |
| template<typename SignedInt> | |
| CONSTEXPRESSION takum & | convert_signed (SignedInt rhs) noexcept |
| conversion routines from native types | |
| template<typename UnsignedInt> | |
| CONSTEXPRESSION takum & | convert_unsigned (UnsignedInt rhs) noexcept |
| CONSTEXPRESSION takum & | convert_integer_magnitude (uint64_t magnitude, bool negative) noexcept |
| template<typename Real> | |
| CONSTEXPRESSION takum & | convert_ieee754 (Real rhs) noexcept |
| Convert an IEEE-754 floating-point value to linear takum encoding. | |
| template<typename SignedInt> | |
| CONSTEXPRESSION std::enable_if< std::is_integral< SignedInt >::value &&std::is_signed< SignedInt >::value, SignedInt >::type | to_signed () const noexcept |
| conversion routines to native types | |
| template<typename UnsignedInt> | |
| CONSTEXPRESSION std::enable_if< std::is_integral< UnsignedInt >::value &&std::is_unsigned< UnsignedInt >::value, UnsignedInt >::type | to_unsigned () const noexcept |
| template<typename Integer> | |
| constexpr Integer | to_integer () const noexcept |
| template<typename TargetFloat> | |
| CONSTEXPRESSION TargetFloat | to_ieee754 () const noexcept |
| Decode a linear takum to an IEEE-754 floating-point value, correctly rounded. | |
Static Protected Member Functions | |
| static constexpr uint64_t | nbits_mask () noexcept |
Friends | |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| std::ostream & | operator<< (std::ostream &ostr, const takum< nnbits, nrbits, nbt > &r) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| std::istream & | operator>> (std::istream &istr, takum< nnbits, nrbits, nbt > &r) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator== (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator!= (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator< (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator> (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator<= (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| template<unsigned nnbits, unsigned nrbits, typename nbt> | |
| constexpr bool | operator>= (const takum< nnbits, nrbits, nbt > &lhs, const takum< nnbits, nrbits, nbt > &rhs) |
| using sw::universal::takum< _nbits, _rbits, bt >::BlockBinary = blockbinary<nbits, bt, BinaryNumberType::Unsigned> |
| typedef bt sw::universal::takum< _nbits, _rbits, bt >::BlockType |
| using sw::universal::takum< _nbits, _rbits, bt >::Codec = takum_codec<_nbits, _rbits> |
|
default |
trivial constructor
|
default |
|
default |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineprotectednoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineprotectednoexcept |
Convert an IEEE-754 floating-point value to linear takum encoding.
Constexpr-promoted by replacing std::frexp with bit-extraction: for an IEEE 754 normal v = (1 + rawFrac/2^fbits) * 2^(rawExp - bias), the takum decomposition is c = rawExp - bias and m_real = rawFrac/2^fbits directly, with no math-library calls. Subnormals are normalized via a bounded leading-zero shift on rawFrac. Long double routes through double at constant evaluation (LONG_DOUBLE_DOWNCAST pattern); finite long-double inputs out of double range are extremely rare in compile- time literals.
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |
conversion routines from native types
|
inlineprotectednoexcept |
| void sw::universal::takum< nbits, rbits, bt >::debugConstexprParameters | ( | ) |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlineconstexprprotectednoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlinestaticconstexprprotectednoexcept |
|
inlineconstexprnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inlineexplicitnoexcept |
|
inline |
|
inline |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inline |
|
inline |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineconstexprnoexcept |
|
default |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
default |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineprotectednoexcept |
Decode a linear takum to an IEEE-754 floating-point value, correctly rounded.
|value| = S * 2^e with the integer significand S = 2^p + M, so the conversion is one integer rounding of S to the precision the target holds AT THIS MAGNITUDE – digits for a normal result, fewer for a subnormal one – followed by an exact scaling. The earlier form, (1 + M/2^p) * float(2^c), rounded up to three times: M/2^p to the target, 1 + f again, and the product once more when it was subnormal. takum<32,3> -> float was wrong for 2.9% of encodings, every takum value in (2^-150, 2^-149) became 0.0f instead of 2^-149, and takum<64,3> -> double was double-rounded the same way (#1622).
Constexpr-promoted: powers of two come from constexpr_math::detail::pow2, which sets the exponent field directly – exact, O(1), and unlike exp2 it does not evaluate a Taylor series for an integer argument.
|
inlineconstexprprotectednoexcept |
|
inlineprotectednoexcept |
conversion routines to native types
|
inlineprotectednoexcept |
|
inlineconstexprnoexcept |
|
inlineprotectednoexcept |
|
inlineconstexprnoexcept |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |