Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
fast_float::bigint Struct Reference

#include <fast_float.h>

Collaboration diagram for fast_float::bigint:
[legend]

Public Member Functions

 bigint ()
 
 bigint (const bigint &)=delete
 
bigintoperator= (const bigint &)=delete
 
 bigint (bigint &&)=delete
 
bigintoperator= (bigint &&other)=delete
 
 bigint (uint64_t value)
 
uint64_t hi64 (bool &truncated) const noexcept
 
int compare (const bigint &other) const noexcept
 
bool shl_bits (size_t n) noexcept
 
bool shl_limbs (size_t n) noexcept
 
bool shl (size_t n) noexcept
 
int ctlz () const noexcept
 
int bit_length () const noexcept
 
bool mul (limb y) noexcept
 
bool add (limb y) noexcept
 
bool pow2 (uint32_t exp) noexcept
 
bool pow5 (uint32_t exp) noexcept
 
bool pow10 (uint32_t exp) noexcept
 

Public Attributes

stackvec< bigint_limbsvec
 

Detailed Description

Definition at line 1959 of file fast_float.h.

Constructor & Destructor Documentation

◆ bigint() [1/4]

fast_float::bigint::bigint ( )
inline

Definition at line 1963 of file fast_float.h.

1963: vec() {}
stackvec< bigint_limbs > vec
Definition: fast_float.h:1961

◆ bigint() [2/4]

fast_float::bigint::bigint ( const bigint )
delete

◆ bigint() [3/4]

fast_float::bigint::bigint ( bigint &&  )
delete

◆ bigint() [4/4]

fast_float::bigint::bigint ( uint64_t  value)
inline

Definition at line 1969 of file fast_float.h.

1969 : vec() {
1970#ifdef FASTFLOAT_64BIT_LIMB
1971 vec.push_unchecked(value);
1972#else
1973 vec.push_unchecked(uint32_t(value));
1974 vec.push_unchecked(uint32_t(value >> 32));
1975#endif
1976 vec.normalize();
1977 }
void push_unchecked(limb value) noexcept
Definition: fast_float.h:1677
void normalize() noexcept
Definition: fast_float.h:1741

References fast_float::stackvec< size >::normalize(), fast_float::stackvec< size >::push_unchecked(), and vec.

Here is the call graph for this function:

Member Function Documentation

◆ add()

bool fast_float::bigint::add ( limb  y)
inlinenoexcept

Definition at line 2118 of file fast_float.h.

2118 {
2119 return small_add(vec, y);
2120 }
fastfloat_really_inline bool small_add(stackvec< size > &vec, limb y) noexcept
Definition: fast_float.h:1862

References fast_float::small_add(), and vec.

Here is the call graph for this function:

◆ bit_length()

int fast_float::bigint::bit_length ( ) const
inlinenoexcept

Definition at line 2109 of file fast_float.h.

2109 {
2110 int lz = ctlz();
2111 return int(limb_bits * vec.len()) - lz;
2112 }
constexpr size_t limb_bits
Definition: fast_float.h:1617
int ctlz() const noexcept
Definition: fast_float.h:2094
constexpr size_t len() const noexcept
Definition: fast_float.h:1667

References ctlz(), fast_float::stackvec< size >::len(), fast_float::limb_bits, and vec.

Here is the call graph for this function:

◆ compare()

int fast_float::bigint::compare ( const bigint other) const
inlinenoexcept

Definition at line 2013 of file fast_float.h.

2013 {
2014 if (vec.len() > other.vec.len()) {
2015 return 1;
2016 } else if (vec.len() < other.vec.len()) {
2017 return -1;
2018 } else {
2019 for (size_t index = vec.len(); index > 0; index--) {
2020 limb xi = vec[index - 1];
2021 limb yi = other.vec[index - 1];
2022 if (xi > yi) {
2023 return 1;
2024 } else if (xi < yi) {
2025 return -1;
2026 }
2027 }
2028 return 0;
2029 }
2030 }
uint32_t limb
Definition: fast_float.h:1616

References fast_float::stackvec< size >::len(), and vec.

Referenced by fast_float::negative_digit_comp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctlz()

int fast_float::bigint::ctlz ( ) const
inlinenoexcept

Definition at line 2094 of file fast_float.h.

2094 {
2095 if (vec.is_empty()) {
2096 return 0;
2097 } else {
2098#ifdef FASTFLOAT_64BIT_LIMB
2099 return leading_zeroes(vec.rindex(0));
2100#else
2101 // no use defining a specialized leading_zeroes for a 32-bit type.
2102 uint64_t r0 = vec.rindex(0);
2103 return leading_zeroes(r0 << 32);
2104#endif
2105 }
2106 }
fastfloat_really_inline int leading_zeroes(uint64_t input_num)
Definition: fast_float.h:232
constexpr bool is_empty() const noexcept
Definition: fast_float.h:1670
const limb & rindex(size_t index) const noexcept
Definition: fast_float.h:1657

References fast_float::stackvec< size >::is_empty(), fast_float::leading_zeroes(), fast_float::stackvec< size >::rindex(), and vec.

Referenced by bit_length().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hi64()

uint64_t fast_float::bigint::hi64 ( bool &  truncated) const
inlinenoexcept

Definition at line 1981 of file fast_float.h.

1981 {
1982#ifdef FASTFLOAT_64BIT_LIMB
1983 if (vec.len() == 0) {
1984 return empty_hi64(truncated);
1985 } else if (vec.len() == 1) {
1986 return uint64_hi64(vec.rindex(0), truncated);
1987 } else {
1988 uint64_t result = uint64_hi64(vec.rindex(0), vec.rindex(1), truncated);
1989 truncated |= vec.nonzero(2);
1990 return result;
1991 }
1992#else
1993 if (vec.len() == 0) {
1994 return empty_hi64(truncated);
1995 } else if (vec.len() == 1) {
1996 return uint32_hi64(vec.rindex(0), truncated);
1997 } else if (vec.len() == 2) {
1998 return uint32_hi64(vec.rindex(0), vec.rindex(1), truncated);
1999 } else {
2000 uint64_t result = uint32_hi64(vec.rindex(0), vec.rindex(1), vec.rindex(2), truncated);
2001 truncated |= vec.nonzero(3);
2002 return result;
2003 }
2004#endif
2005 }
fastfloat_really_inline uint64_t uint32_hi64(uint32_t r0, bool &truncated) noexcept
Definition: fast_float.h:1775
fastfloat_really_inline uint64_t empty_hi64(bool &truncated) noexcept
Definition: fast_float.h:1749
fastfloat_really_inline uint64_t uint64_hi64(uint64_t r0, bool &truncated) noexcept
Definition: fast_float.h:1755
bool nonzero(size_t index) const noexcept
Definition: fast_float.h:1731

References fast_float::empty_hi64(), fast_float::stackvec< size >::len(), fast_float::stackvec< size >::nonzero(), fast_float::stackvec< size >::rindex(), fast_float::uint32_hi64(), fast_float::uint64_hi64(), and vec.

Here is the call graph for this function:

◆ mul()

bool fast_float::bigint::mul ( limb  y)
inlinenoexcept

Definition at line 2114 of file fast_float.h.

2114 {
2115 return small_mul(vec, y);
2116 }
bool small_mul(stackvec< size > &vec, limb y) noexcept
Definition: fast_float.h:1868

References fast_float::small_mul(), and vec.

Here is the call graph for this function:

◆ operator=() [1/2]

bigint & fast_float::bigint::operator= ( bigint &&  other)
delete

◆ operator=() [2/2]

bigint & fast_float::bigint::operator= ( const bigint )
delete

◆ pow10()

bool fast_float::bigint::pow10 ( uint32_t  exp)
inlinenoexcept

Definition at line 2173 of file fast_float.h.

2173 {
2174 FASTFLOAT_TRY(pow5(exp));
2175 return pow2(exp);
2176 }
#define FASTFLOAT_TRY(x)
Definition: fast_float.h:188
bool pow2(uint32_t exp) noexcept
Definition: fast_float.h:2123
bool pow5(uint32_t exp) noexcept
Definition: fast_float.h:2128

References FASTFLOAT_TRY, pow2(), and pow5().

Here is the call graph for this function:

◆ pow2()

bool fast_float::bigint::pow2 ( uint32_t  exp)
inlinenoexcept

Definition at line 2123 of file fast_float.h.

2123 {
2124 return shl(exp);
2125 }
bool shl(size_t n) noexcept
Definition: fast_float.h:2081

References shl().

Referenced by fast_float::negative_digit_comp(), and pow10().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pow5()

bool fast_float::bigint::pow5 ( uint32_t  exp)
inlinenoexcept

Definition at line 2128 of file fast_float.h.

2128 {
2129 // multiply by a power of 5
2130 static constexpr uint32_t large_step = 135;
2131 static constexpr uint64_t small_power_of_5[] = {
2132 1UL, 5UL, 25UL, 125UL, 625UL, 3125UL, 15625UL, 78125UL, 390625UL,
2133 1953125UL, 9765625UL, 48828125UL, 244140625UL, 1220703125UL,
2134 6103515625UL, 30517578125UL, 152587890625UL, 762939453125UL,
2135 3814697265625UL, 19073486328125UL, 95367431640625UL, 476837158203125UL,
2136 2384185791015625UL, 11920928955078125UL, 59604644775390625UL,
2137 298023223876953125UL, 1490116119384765625UL, 7450580596923828125UL,
2138 };
2139#ifdef FASTFLOAT_64BIT_LIMB
2140 constexpr static limb large_power_of_5[] = {
2141 1414648277510068013UL, 9180637584431281687UL, 4539964771860779200UL,
2142 10482974169319127550UL, 198276706040285095UL};
2143#else
2144 constexpr static limb large_power_of_5[] = {
2145 4279965485U, 329373468U, 4020270615U, 2137533757U, 4287402176U,
2146 1057042919U, 1071430142U, 2440757623U, 381945767U, 46164893U};
2147#endif
2148 size_t large_length = sizeof(large_power_of_5) / sizeof(limb);
2149 limb_span large = limb_span(large_power_of_5, large_length);
2150 while (exp >= large_step) {
2151 FASTFLOAT_TRY(large_mul(vec, large));
2152 exp -= large_step;
2153 }
2154#ifdef FASTFLOAT_64BIT_LIMB
2155 uint32_t small_step = 27;
2156 limb max_native = 7450580596923828125UL;
2157#else
2158 uint32_t small_step = 13;
2159 limb max_native = 1220703125U;
2160#endif
2161 while (exp >= small_step) {
2162 FASTFLOAT_TRY(small_mul(vec, max_native));
2163 exp -= small_step;
2164 }
2165 if (exp != 0) {
2166 FASTFLOAT_TRY(small_mul(vec, limb(small_power_of_5[exp])));
2167 }
2168
2169 return true;
2170 }
bool large_mul(stackvec< size > &x, limb_span y) noexcept
Definition: fast_float.h:1946
span< limb > limb_span
Definition: fast_float.h:1620

References FASTFLOAT_TRY, fast_float::large_mul(), fast_float::small_mul(), and vec.

Referenced by fast_float::negative_digit_comp(), and pow10().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shl()

bool fast_float::bigint::shl ( size_t  n)
inlinenoexcept

Definition at line 2081 of file fast_float.h.

2081 {
2082 size_t rem = n % limb_bits;
2083 size_t div = n / limb_bits;
2084 if (rem != 0) {
2085 FASTFLOAT_TRY(shl_bits(rem));
2086 }
2087 if (div != 0) {
2089 }
2090 return true;
2091 }
bool shl_limbs(size_t n) noexcept
Definition: fast_float.h:2060
bool shl_bits(size_t n) noexcept
Definition: fast_float.h:2034

References FASTFLOAT_TRY, fast_float::limb_bits, shl_bits(), and shl_limbs().

Referenced by pow2(), and shl_bits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shl_bits()

bool fast_float::bigint::shl_bits ( size_t  n)
inlinenoexcept

Definition at line 2034 of file fast_float.h.

2034 {
2035 // Internally, for each item, we shift left by n, and add the previous
2036 // right shifted limb-bits.
2037 // For example, we transform (for u8) shifted left 2, to:
2038 // b10100100 b01000010
2039 // b10 b10010001 b00001000
2040 FASTFLOAT_DEBUG_ASSERT(n != 0);
2041 FASTFLOAT_DEBUG_ASSERT(n < sizeof(limb) * 8);
2042
2043 size_t shl = n;
2044 size_t shr = limb_bits - shl;
2045 limb prev = 0;
2046 for (size_t index = 0; index < vec.len(); index++) {
2047 limb xi = vec[index];
2048 vec[index] = (xi << shl) | (prev >> shr);
2049 prev = xi;
2050 }
2051
2052 limb carry = prev >> shr;
2053 if (carry != 0) {
2054 return vec.try_push(carry);
2055 }
2056 return true;
2057 }
#define FASTFLOAT_DEBUG_ASSERT(x)
Definition: fast_float.h:184
bool try_push(limb value) noexcept
Definition: fast_float.h:1682

References FASTFLOAT_DEBUG_ASSERT, fast_float::stackvec< size >::len(), fast_float::limb_bits, shl(), fast_float::stackvec< size >::try_push(), and vec.

Referenced by shl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shl_limbs()

bool fast_float::bigint::shl_limbs ( size_t  n)
inlinenoexcept

Definition at line 2060 of file fast_float.h.

2060 {
2061 FASTFLOAT_DEBUG_ASSERT(n != 0);
2062 if (n + vec.len() > vec.capacity()) {
2063 return false;
2064 } else if (!vec.is_empty()) {
2065 // move limbs
2066 limb* dst = vec.data + n;
2067 const limb* src = vec.data;
2068 ::memmove(dst, src, sizeof(limb) * vec.len());
2069 // fill in empty limbs
2070 limb* first = vec.data;
2071 limb* last = first + n;
2072 ::std::fill(first, last, 0);
2073 vec.set_len(n + vec.len());
2074 return true;
2075 } else {
2076 return true;
2077 }
2078 }
constexpr size_t capacity() const noexcept
Definition: fast_float.h:1673
void set_len(size_t len) noexcept
Definition: fast_float.h:1664

References fast_float::stackvec< size >::capacity(), fast_float::stackvec< size >::data, FASTFLOAT_DEBUG_ASSERT, fast_float::stackvec< size >::is_empty(), fast_float::stackvec< size >::len(), fast_float::stackvec< size >::set_len(), and vec.

Referenced by shl().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ vec

stackvec<bigint_limbs> fast_float::bigint::vec

Definition at line 1961 of file fast_float.h.

Referenced by add(), bigint(), bit_length(), compare(), ctlz(), hi64(), mul(), pow5(), shl_bits(), and shl_limbs().


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