fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
Loading...
Searching...
No Matches
fp128::detail::basic_big_uint< Capacity > Class Template Reference

Fixed capacity unsigned big integer, 32 bit limbs, least significant first. More...

#include <fp128_decimal.h>

Public Member Functions

 basic_big_uint () noexcept
 Constructs zero.
void set (uint64_t low, uint64_t high) noexcept
 Sets the value to a 128 bit integer.
void clear () noexcept
 Sets the value to zero.
bool is_zero () const noexcept
int32_t limbs () const noexcept
uint32_t at (int32_t index) const noexcept
int32_t bit_length () const noexcept
 Index of the highest set bit, or -1 when the value is zero.
bool mul_small (uint32_t multiplier) noexcept
 Multiplies by a value that fits in a limb.
void add_small (uint32_t addend) noexcept
 Adds a value that fits in a limb.
uint32_t divmod_small (uint32_t divisor) noexcept
 Divides by a value that fits in a limb.
bool mul_pow10 (int32_t count) noexcept
 Multiplies in place by 10^count, in blocks that fit in a limb.
void div_pow10 (int32_t count, bool &sticky) noexcept
 Divides in place by 10^count, reporting whether anything was discarded.
bool shift_left (int32_t bits) noexcept
 Shifts left, growing the value.
void shift_right (int32_t bits) noexcept
 Shifts right, discarding the bits that fall off the bottom.
void keep_low_bits (int32_t bits) noexcept
 Clears every bit at or above the given position.
uint32_t fraction_mul_extract (uint32_t multiplier, int32_t width) noexcept
 Treats the value as a fraction, multiplies it by a small value and peels off the integer part that crosses the point.
int32_t compare_half (int32_t width) const noexcept
 Compares the value against one half of 2^(width*32), the fraction's midpoint.

Static Public Attributes

static constexpr int32_t CAPACITY = Capacity
 Limbs.
static constexpr int32_t LIMB_BITS = 32
 Bits per limb.
static constexpr uint64_t LIMB_BASE = 1ull << LIMB_BITS
 One past the largest limb value.
static constexpr uint32_t POWERS_OF_10 [10]
 Powers of ten that fit in a limb, indexed by the exponent.

Detailed Description

template<int32_t Capacity>
class fp128::detail::basic_big_uint< Capacity >

Fixed capacity unsigned big integer, 32 bit limbs, least significant first.

The operations are only the ones the conversions use - multiply and divide by a value that fits in a limb, shift, compare - so none of them needs a general multi word division.

Template Parameters
CapacityLimbs. big_uint, the one every conversion uses, is sized for the widest intermediate they need: reading the smallest subnormal back from its decimal form scales a 40 digit mantissa by 2^16716, which is 527 limbs. wide_big_uint holds the same for a mantissa of MAX_EXACT_DIGITS digits, which only an input that long needs.

Definition at line 67 of file fp128_decimal.h.

Constructor & Destructor Documentation

◆ basic_big_uint()

template<int32_t Capacity>
fp128::detail::basic_big_uint< Capacity >::basic_big_uint ( )
inlinenoexcept

Constructs zero.

Definition at line 75 of file fp128_decimal.h.

Member Function Documentation

◆ set()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::set ( uint64_t low,
uint64_t high )
inlinenoexcept

Sets the value to a 128 bit integer.

Definition at line 78 of file fp128_decimal.h.

◆ clear()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::clear ( )
inlinenoexcept

Sets the value to zero.

Definition at line 90 of file fp128_decimal.h.

◆ is_zero()

template<int32_t Capacity>
bool fp128::detail::basic_big_uint< Capacity >::is_zero ( ) const
inlinenodiscardnoexcept

Definition at line 97 of file fp128_decimal.h.

◆ limbs()

template<int32_t Capacity>
int32_t fp128::detail::basic_big_uint< Capacity >::limbs ( ) const
inlinenodiscardnoexcept

Definition at line 98 of file fp128_decimal.h.

◆ at()

template<int32_t Capacity>
uint32_t fp128::detail::basic_big_uint< Capacity >::at ( int32_t index) const
inlinenodiscardnoexcept

Definition at line 99 of file fp128_decimal.h.

◆ bit_length()

template<int32_t Capacity>
int32_t fp128::detail::basic_big_uint< Capacity >::bit_length ( ) const
inlinenodiscardnoexcept

Index of the highest set bit, or -1 when the value is zero.

Definition at line 102 of file fp128_decimal.h.

◆ mul_small()

template<int32_t Capacity>
bool fp128::detail::basic_big_uint< Capacity >::mul_small ( uint32_t multiplier)
inlinenoexcept

Multiplies by a value that fits in a limb.

Parameters
multiplierValue to multiply by
Returns
False when the product did not fit in the capacity.

Definition at line 116 of file fp128_decimal.h.

◆ add_small()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::add_small ( uint32_t addend)
inlinenoexcept

Adds a value that fits in a limb.

Definition at line 134 of file fp128_decimal.h.

◆ divmod_small()

template<int32_t Capacity>
uint32_t fp128::detail::basic_big_uint< Capacity >::divmod_small ( uint32_t divisor)
inlinenoexcept

Divides by a value that fits in a limb.

Parameters
divisorValue to divide by, must not be zero
Returns
The remainder.

Definition at line 153 of file fp128_decimal.h.

◆ mul_pow10()

template<int32_t Capacity>
bool fp128::detail::basic_big_uint< Capacity >::mul_pow10 ( int32_t count)
inlinenoexcept

Multiplies in place by 10^count, in blocks that fit in a limb.

Returns
False when the product did not fit in the capacity.

Definition at line 167 of file fp128_decimal.h.

◆ div_pow10()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::div_pow10 ( int32_t count,
bool & sticky )
inlinenoexcept

Divides in place by 10^count, reporting whether anything was discarded.

Parameters
countPower of ten to divide by
stickySet to true when a division left a non zero remainder

Definition at line 181 of file fp128_decimal.h.

◆ shift_left()

template<int32_t Capacity>
bool fp128::detail::basic_big_uint< Capacity >::shift_left ( int32_t bits)
inlinenoexcept

Shifts left, growing the value.

Returns
False when the result did not fit in the capacity.

Definition at line 193 of file fp128_decimal.h.

◆ shift_right()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::shift_right ( int32_t bits)
inlinenoexcept

Shifts right, discarding the bits that fall off the bottom.

Definition at line 225 of file fp128_decimal.h.

◆ keep_low_bits()

template<int32_t Capacity>
void fp128::detail::basic_big_uint< Capacity >::keep_low_bits ( int32_t bits)
inlinenoexcept

Clears every bit at or above the given position.

Definition at line 253 of file fp128_decimal.h.

◆ fraction_mul_extract()

template<int32_t Capacity>
uint32_t fp128::detail::basic_big_uint< Capacity >::fraction_mul_extract ( uint32_t multiplier,
int32_t width )
inlinenoexcept

Treats the value as a fraction, multiplies it by a small value and peels off the integer part that crosses the point.

The buffer holds a fraction scaled by 2^(width*32), so multiplying it produces digits above the point that no longer belong in it. Those are what the caller wants.

Parameters
multiplierValue to multiply by, small enough that the overflow fits in a limb
widthLimb count the fraction occupies
Returns
The integer part the multiply produced.

Definition at line 282 of file fp128_decimal.h.

◆ compare_half()

template<int32_t Capacity>
int32_t fp128::detail::basic_big_uint< Capacity >::compare_half ( int32_t width) const
inlinenodiscardnoexcept

Compares the value against one half of 2^(width*32), the fraction's midpoint.

Returns
1 above the midpoint, -1 below it, 0 exactly on it.

Definition at line 297 of file fp128_decimal.h.

Member Data Documentation

◆ CAPACITY

template<int32_t Capacity>
int32_t fp128::detail::basic_big_uint< Capacity >::CAPACITY = Capacity
staticconstexpr

Limbs.

Definition at line 70 of file fp128_decimal.h.

◆ LIMB_BITS

template<int32_t Capacity>
int32_t fp128::detail::basic_big_uint< Capacity >::LIMB_BITS = 32
staticconstexpr

Bits per limb.

Definition at line 71 of file fp128_decimal.h.

◆ LIMB_BASE

template<int32_t Capacity>
uint64_t fp128::detail::basic_big_uint< Capacity >::LIMB_BASE = 1ull << LIMB_BITS
staticconstexpr

One past the largest limb value.

Definition at line 72 of file fp128_decimal.h.

◆ POWERS_OF_10

template<int32_t Capacity>
uint32_t fp128::detail::basic_big_uint< Capacity >::POWERS_OF_10[10]
staticconstexpr
Initial value:
= {1u, 10u, 100u, 1000u, 10000u,
100000u, 1000000u, 10000000u, 100000000u, 1000000000u}

Powers of ten that fit in a limb, indexed by the exponent.

Definition at line 313 of file fp128_decimal.h.


The documentation for this class was generated from the following file: