MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / large_add_from

Function large_add_from

Source/external/fast_float.h:2114–2141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2112// used in grade school multiplication
2113template <uint16_t size>
2114FASTFLOAT_CONSTEXPR20
2115bool large_add_from(stackvec<size>& x, limb_span y, size_t start) noexcept {
2116 // the effective x buffer is from `xstart..x.len()`, so exit early
2117 // if we can't get that current range.
2118 if (x.len() < start || y.len() > x.len() - start) {
2119 FASTFLOAT_TRY(x.try_resize(y.len() + start, 0));
2120 }
2121
2122 bool carry = false;
2123 for (size_t index = 0; index < y.len(); index++) {
2124 limb xi = x[index + start];
2125 limb yi = y[index];
2126 bool c1 = false;
2127 bool c2 = false;
2128 xi = scalar_add(xi, yi, c1);
2129 if (carry) {
2130 xi = scalar_add(xi, 1, c2);
2131 }
2132 x[index + start] = xi;
2133 carry = c1 | c2;
2134 }
2135
2136 // handle overflow
2137 if (carry) {
2138 FASTFLOAT_TRY(small_add_from(x, 1, y.len() + start));
2139 }
2140 return true;
2141}
2142
2143// add bigint to bigint.
2144template <uint16_t size>

Callers 1

long_mulFunction · 0.85

Calls 4

scalar_addFunction · 0.85
small_add_fromFunction · 0.85
try_resizeMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected