chsvlib
chsv helper source code

◆ memsub_BE_inplace()

bool Chusov::Memory::memsub_BE_inplace ( void *  pResult,
const void *  pMinuend,
std::size_t  cb 
)
noexcept

Subtracts an arbitrary-precision integer from another arbitrary-precision integer in place of the latter and returns the resulting borrow bit. The operands and the result are considered to be in the Big-Endian byte order.

Parameters
[in,out]pResultA pointer to a buffer which on input holds the subtrahend and on output receives the difference.
[in]pMinuendA pointer to a byte vector which holds the minuend of the operation.
cbByte size of the operands and the capacity of the output buffer.
Returns
true if a borrow has taken place and false otherwise.

The subtraction is carried out modulo bcb, where b = 2CHAR_BIT is a number of values that a byte can represent.

All of the integers are specified with vectors in the Big-Endian byte order. That is, if n = cb - 1, the subtrahend addressed by pResult and the minuend addressed by pMinuend respectively specified with vectors \(V_X = \{x_0,\dots, x_n\}\) and \(V_Y = \{y_0,\dots, y_n\}\), where \(x_0\) and \(y_0\) are the first bytes of the vectors, then the respective integers are defined as \(X=\sum_{i=0}^{n}x_{n-i}\cdot b^i\) and \(Y=\sum_{i=0}^{n}y_{n-i}\cdot b^i\). The difference \(X - Y\) is also written to pResult in the Big-Endian byte order.

To subtract numbers given in the Little-Endian byte order use memsub_LE_inplace.

To produce the difference in place of a minuend, rather than subtrahend, use the memnegsub_BE_inplace function.

To produce the difference in a separate buffer and leave the input integrals unmodified, use memsub_BE_copy or memsub_BE.

See also
memsub_LE_inplace;
memnegsub_BE_inplace;
memsub_BE_copy;
memsub_BE;
memdecr_BE;
memneg_BE;
memadd_BE;
memmul_BE;
memfmsub_BE;
memdiv_BE.