MCPcopy Create free account
hub / github.com/davisking/dlib / increment

Method increment

dlib/bigint/bigint_kernel_2.cpp:1736–1781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1734// ----------------------------------------------------------------------------------------
1735
1736 void bigint_kernel_2::
1737 increment (
1738 const data_record* source,
1739 data_record* dest
1740 ) const
1741 {
1742 uint16* s = source->number;
1743 uint16* d = dest->number;
1744 uint16* end = s + source->digits_used;
1745 while (true)
1746 {
1747 *d = *s + 1;
1748
1749 // if there was no carry then break out of the loop
1750 if (*d != 0)
1751 {
1752 dest->digits_used = source->digits_used;
1753
1754 // copy the rest of the digits over to d
1755 ++d; ++s;
1756 while (s != end)
1757 {
1758 *d = *s;
1759 ++d;
1760 ++s;
1761 }
1762
1763 break;
1764 }
1765
1766
1767 ++s;
1768
1769 // if we have hit the end of s and there was a carry up to this point
1770 // then just make the next digit 1 and add one to the digits used
1771 if (s == end)
1772 {
1773 ++d;
1774 dest->digits_used = source->digits_used + 1;
1775 *d = 1;
1776 break;
1777 }
1778
1779 ++d;
1780 }
1781 }
1782
1783// ----------------------------------------------------------------------------------------
1784

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected