|
fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
|
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. | |
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.
| Capacity | Limbs. 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.
|
inlinenoexcept |
Constructs zero.
Definition at line 75 of file fp128_decimal.h.
|
inlinenoexcept |
Sets the value to a 128 bit integer.
Definition at line 78 of file fp128_decimal.h.
|
inlinenoexcept |
Sets the value to zero.
Definition at line 90 of file fp128_decimal.h.
|
inlinenodiscardnoexcept |
Definition at line 97 of file fp128_decimal.h.
|
inlinenodiscardnoexcept |
Definition at line 98 of file fp128_decimal.h.
|
inlinenodiscardnoexcept |
Definition at line 99 of file fp128_decimal.h.
|
inlinenodiscardnoexcept |
Index of the highest set bit, or -1 when the value is zero.
Definition at line 102 of file fp128_decimal.h.
|
inlinenoexcept |
Multiplies by a value that fits in a limb.
| multiplier | Value to multiply by |
Definition at line 116 of file fp128_decimal.h.
|
inlinenoexcept |
Adds a value that fits in a limb.
Definition at line 134 of file fp128_decimal.h.
|
inlinenoexcept |
Divides by a value that fits in a limb.
| divisor | Value to divide by, must not be zero |
Definition at line 153 of file fp128_decimal.h.
|
inlinenoexcept |
Multiplies in place by 10^count, in blocks that fit in a limb.
Definition at line 167 of file fp128_decimal.h.
|
inlinenoexcept |
Divides in place by 10^count, reporting whether anything was discarded.
| count | Power of ten to divide by |
| sticky | Set to true when a division left a non zero remainder |
Definition at line 181 of file fp128_decimal.h.
|
inlinenoexcept |
Shifts left, growing the value.
Definition at line 193 of file fp128_decimal.h.
|
inlinenoexcept |
Shifts right, discarding the bits that fall off the bottom.
Definition at line 225 of file fp128_decimal.h.
|
inlinenoexcept |
Clears every bit at or above the given position.
Definition at line 253 of file fp128_decimal.h.
|
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.
| multiplier | Value to multiply by, small enough that the overflow fits in a limb |
| width | Limb count the fraction occupies |
Definition at line 282 of file fp128_decimal.h.
|
inlinenodiscardnoexcept |
Compares the value against one half of 2^(width*32), the fraction's midpoint.
Definition at line 297 of file fp128_decimal.h.
|
staticconstexpr |
Limbs.
Definition at line 70 of file fp128_decimal.h.
|
staticconstexpr |
Bits per limb.
Definition at line 71 of file fp128_decimal.h.
|
staticconstexpr |
One past the largest limb value.
Definition at line 72 of file fp128_decimal.h.
|
staticconstexpr |
Powers of ten that fit in a limb, indexed by the exponent.
Definition at line 313 of file fp128_decimal.h.