@@ -67,7 +67,7 @@ template <limb_t size> struct stackvec {
6767 // index from the end of the container
6868 FASTFLOAT_CONSTEXPR14 const limb &rindex (limb_t index) const noexcept {
6969 FASTFLOAT_DEBUG_ASSERT (index < length);
70- limb_t rindex = static_cast < limb_t >( length - index - 1 ) ;
70+ auto rindex = length - index - 1 ;
7171 return data[rindex];
7272 }
7373
@@ -100,7 +100,7 @@ template <limb_t size> struct stackvec {
100100 FASTFLOAT_CONSTEXPR20 void extend_unchecked (limb_span s) noexcept {
101101 limb *ptr = data + length;
102102 std::copy_n (s.ptr , s.len (), ptr);
103- set_len (static_cast < limb_t >( len () + s.len ()));
103+ set_len (len () + static_cast < limb_t >( s.len ()));
104104 }
105105
106106 // try to add items to the vector, returning if items were added
@@ -119,7 +119,7 @@ template <limb_t size> struct stackvec {
119119 FASTFLOAT_CONSTEXPR20
120120 void resize_unchecked (limb_t new_len, limb value) noexcept {
121121 if (new_len > len ()) {
122- limb_t count = new_len - len ();
122+ auto count = new_len - len ();
123123 limb *first = data + len ();
124124 limb *last = first + count;
125125 ::std::fill (first, last, value);
@@ -258,9 +258,8 @@ scalar_mul(limb x, limb y, limb &carry) noexcept {
258258// add scalar value to bigint starting from offset.
259259// used in grade school multiplication
260260template <limb_t size>
261- inline FASTFLOAT_CONSTEXPR20 bool small_add_from (stackvec<size> &vec, limb y,
262- limb_t start) noexcept {
263- limb carry = y;
261+ inline FASTFLOAT_CONSTEXPR20 bool
262+ small_add_from (stackvec<size> &vec, limb carry, limb_t start) noexcept {
264263 bool overflow;
265264 while (carry != 0 && start < vec.len ()) {
266265 vec[start] = scalar_add (vec[start], carry, overflow);
@@ -301,8 +300,9 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
301300 limb_t start) noexcept {
302301 // the effective x buffer is from `xstart..x.len()`, so exit early
303302 // if we can't get that current range.
304- if (x.len () < start || y.len () > static_cast <limb_t >(x.len () - start)) {
305- FASTFLOAT_TRY (x.try_resize (static_cast <limb_t >(y.len () + start), 0 ));
303+ if (x.len () < start ||
304+ y.len () > static_cast <uint_fast16_t >(x.len () - start)) {
305+ FASTFLOAT_TRY (x.try_resize (static_cast <limb_t >(y.len ()) + start, 0 ));
306306 }
307307
308308 bool carry = false ;
@@ -321,7 +321,7 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
321321
322322 // handle overflow
323323 if (carry) {
324- FASTFLOAT_TRY (small_add_from (x, 1 , static_cast <limb_t >(y.len () + start) ));
324+ FASTFLOAT_TRY (small_add_from (x, 1 , static_cast <limb_t >(y.len ()) + start));
325325 }
326326 return true ;
327327}
@@ -343,7 +343,7 @@ FASTFLOAT_CONSTEXPR20 bool long_mul(stackvec<size> &x, limb_span y) noexcept {
343343 if (y.len () != 0 ) {
344344 limb y0 = y[0 ];
345345 FASTFLOAT_TRY (small_mul (x, y0));
346- for (limb_t index = 1 ; index != y.len (); ++index) {
346+ for (limb_t index = 1 ; index < y.len (); ++index) {
347347 limb yi = y[index];
348348 stackvec<size> zi;
349349 if (yi != 0 ) {
@@ -584,8 +584,8 @@ struct bigint : pow5_tables<> {
584584
585585 // get the number of bits in the bigint.
586586 FASTFLOAT_CONSTEXPR20 bigint_bits_t bit_length () const noexcept {
587- bigint_bits_t lz = ctlz ();
588- return static_cast <fast_float:: bigint_bits_t >( limb_bits * vec.len () - lz) ;
587+ auto lz = ctlz ();
588+ return limb_bits * vec.len () - lz;
589589 }
590590
591591 FASTFLOAT_CONSTEXPR20 bool mul (limb y) noexcept { return small_mul (vec, y); }
0 commit comments