1 /* LibTomFloat, multiple-precision floating-point library
3 * LibTomFloat is a library that provides multiple-precision
4 * floating-point artihmetic as well as trigonometric functionality.
6 * This library requires the public domain LibTomMath to be installed.
8 * This library is free for all purposes without any express
11 * Tom St Denis, tomstdenis@iahu.ca, http://float.libtomcrypt.org
15 int mpf_normalize(mp_float
*a
)
26 cb
= mp_count_bits(&(a
->mantissa
));
31 /* round it, add 1 after shift if diff-1'th bit is 1 */
32 c
= a
->mantissa
.dp
[diff
/DIGIT_BIT
] & (1U<<(diff
%DIGIT_BIT
));
33 if ((err
= mp_div_2d(&(a
->mantissa
), diff
, &(a
->mantissa
), NULL
)) != MP_OKAY
) {
38 return mp_add_d(&(a
->mantissa
), 1, &(a
->mantissa
));
42 } else if (cb
< a
->radix
) {
43 if (mp_iszero(&(a
->mantissa
)) == MP_YES
) {
44 return mpf_const_0(a
);
48 return mp_mul_2d(&(a
->mantissa
), diff
, &(a
->mantissa
));