Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_clamp.c
blob463f22dc05b69de809c18a348224f35d6dc0a87c
1 #include "tommath_private.h"
2 #ifdef MP_CLAMP_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* trim unused digits
8 * This is used to ensure that leading zero digits are
9 * trimmed and the leading "used" digit will be non-zero
10 * Typically very fast. Also fixes the sign if there
11 * are no more leading digits
13 void mp_clamp(mp_int *a)
15 /* decrease used while the most significant digit is
16 * zero.
18 while ((a->used > 0) && (a->dp[a->used - 1] == 0u)) {
19 --(a->used);
22 /* reset the sign flag if zero */
23 if (mp_iszero(a)) {
24 a->sign = MP_ZPOS;
27 #endif