Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 45 lines (41 sloc) 1.095 kb
e549ccf added libtommath-0.32
Tom St Denis authored
1 #include <tommath.h>
2 #ifdef BN_MP_CLAMP_C
57354e1 added libtommath-0.12
Tom St Denis authored
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 *
c1da6aa added libtommath-0.25
Tom St Denis authored
5 * LibTomMath is a library that provides multiple-precision
57354e1 added libtommath-0.12
Tom St Denis authored
6 * integer arithmetic as well as number theoretic functionality.
7 *
c1da6aa added libtommath-0.25
Tom St Denis authored
8 * The library was designed directly after the MPI library by
57354e1 added libtommath-0.12
Tom St Denis authored
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
11 *
12 * The library is free for all purposes without any express
13 * guarantee it works.
14 *
333aebc added libtommath-0.41
Tom St Denis authored
15 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
57354e1 added libtommath-0.12
Tom St Denis authored
16 */
17
b66471f added libtommath-0.13
Tom St Denis authored
18 /* trim unused digits
19 *
20 * This is used to ensure that leading zero digits are
21 * trimed and the leading "used" digit will be non-zero
22 * Typically very fast. Also fixes the sign if there
23 * are no more leading digits
24 */
57354e1 added libtommath-0.12
Tom St Denis authored
25 void
26 mp_clamp (mp_int * a)
27 {
c1da6aa added libtommath-0.25
Tom St Denis authored
28 /* decrease used while the most significant digit is
29 * zero.
30 */
14161e8 added libtommath-0.16
Tom St Denis authored
31 while (a->used > 0 && a->dp[a->used - 1] == 0) {
57354e1 added libtommath-0.12
Tom St Denis authored
32 --(a->used);
14161e8 added libtommath-0.16
Tom St Denis authored
33 }
c1da6aa added libtommath-0.25
Tom St Denis authored
34
35 /* reset the sign flag if used == 0 */
57354e1 added libtommath-0.12
Tom St Denis authored
36 if (a->used == 0) {
37 a->sign = MP_ZPOS;
38 }
39 }
e549ccf added libtommath-0.32
Tom St Denis authored
40 #endif
9294e79 added libtommath-0.36
Tom St Denis authored
41
42 /* $Source$ */
43 /* $Revision$ */
44 /* $Date$ */
Something went wrong with that request. Please try again.