Multi precision arithmetic in
.
More...
#include "c4e_elements.h"
Go to the source code of this file.
Functions | |
| C4eElemCmp | c4e_bigint_cmp (C4E_CONST C4eElement *a, C4E_CONST C4eElement *b) |
| Compares two (may be denormalized) big numbers. | |
| void | c4e_bigint_add (C4E_CONST C4eElement *a, C4E_CONST C4eElement *b, C4eElement *c) |
Addition of two big numbers . | |
| C4eSysBool | c4e_bigint_sub (C4E_CONST C4eElement *a, C4E_CONST C4eElement *b, C4eElement *c) |
The function subtracts two big numbers . | |
| C4eSysBool | c4e_bigint_dec (C4E_CONST C4eElement *b, C4eElement *c) |
Decrements a big number by 1. | |
| void | c4e_bigint_mul (C4E_CONST C4eElement *C4E_RESTRICT a, C4E_CONST C4eElement *C4E_RESTRICT b, C4eElement *C4E_RESTRICT c) |
Multiplication of two big numbers using the classical school book method. | |
| void | c4e_bigint_sqr (C4E_CONST C4eElement *C4E_RESTRICT b, C4eElement *C4E_RESTRICT c) |
Square of a big number . | |
| void | c4e_bigint_div (C4eElement *C4E_RESTRICT a, C4eElement *C4E_RESTRICT b, C4eElement *C4E_RESTRICT q) |
Division of two big numbers using the Pope and Stein algorithm. | |
| void | c4e_bigint_mod (C4eElement *C4E_RESTRICT a, C4eElement *C4E_RESTRICT b) |
Modulo division of two big numbers using the Pope and Stein algorithm. | |
| void | c4e_bigint_gcd (C4eElemTriple *a, C4eElemTriple *b, C4eArchSize n) |
Greatest Common Divisor of two numbers . It calculates the GCD of a->x and b->x together with the Bezout cofactors and in equation . | |
Multi precision arithmetic in
.
Definition in file c4e_bigint.h.
| C4eElemCmp c4e_bigint_cmp | ( | C4E_CONST C4eElement * | a, | |
| C4E_CONST C4eElement * | b | |||
| ) |
Compares two (may be denormalized) big numbers.
| [in] | a | First number. |
| [in] | b | Second number. |
| C4eElemCmpGT | if a is greater than b; | |
| C4eElemCmpLT | if a is less than b; | |
| C4eElemCmpEQ | if a is equal to b. |
| void c4e_bigint_add | ( | C4E_CONST C4eElement * | a, | |
| C4E_CONST C4eElement * | b, | |||
| C4eElement * | c | |||
| ) |
Addition of two big numbers
.
a and b have not to be normalized. But if they are normalized the result c is normalized too.c->digits must point to pre-allocated memory space for at least max (a->size, b->size) + 1 digits.| [in] | a | First summand. |
| [in] | b | Second summand. |
| [out] | c | Result of . It is allowed to set this argument pointing to a or b resp. c->digits pointing to a->digits or b->digits (accumulator mode). |
| C4eSysBool c4e_bigint_sub | ( | C4E_CONST C4eElement * | a, | |
| C4E_CONST C4eElement * | b, | |||
| C4eElement * | c | |||
| ) |
The function subtracts two big numbers
.
c->digits must point to pre-allocated memory space for at least max (a->size, b->size) digits.c is normalized in case it's sign (the return value) is positive, else it is not normalized.| [in] | a | Minuend. |
| [in] | b | Subtrahend. |
| [out] | c | Result of , if negative in two's-complement representation. It is allowed to set this parameter pointing to a or b resp. c->digits pointing to a->digits or b->digits (accumulator mode). |
| C4E_FALSE | if the result is positive | |
| C4E_TRUE | if the result is negative. In that case c is in two's-complement representation of size b->size. |
| C4eSysBool c4e_bigint_dec | ( | C4E_CONST C4eElement * | b, | |
| C4eElement * | c | |||
| ) |
Decrements a big number
by 1.
c->digits must point to pre-allocated memory space for at least b->size digits.| [in] | b | The number to decrement. |
| [out] | c | Result , which may alias b. |
| C4E_FALSE | if the result is positive | |
| C4E_TRUE | if the result is negative. In that case c is in two's-complement representation, with the same size as b. |
| void c4e_bigint_mul | ( | C4E_CONST C4eElement *C4E_RESTRICT | a, | |
| C4E_CONST C4eElement *C4E_RESTRICT | b, | |||
| C4eElement *C4E_RESTRICT | c | |||
| ) |
Multiplication of two big numbers
using the classical school book method.
a and b are normalized then c is normalized too. In the other cases c is not normalized. If c is normalized, then the resulting size is a->size + b->size or a->size + b->size - 1. a->size * b->size).a or b with c or aliasing a->digits or b->digits with c->digits is not allowed. c->digits must point to pre-allocated memory space for at least (a->size + b->size) digits.| [in] | a | First multiplier. |
| [in] | b | Second multiplier. |
| [out] | c | Result . |
| void c4e_bigint_sqr | ( | C4E_CONST C4eElement *C4E_RESTRICT | b, | |
| C4eElement *C4E_RESTRICT | c | |||
| ) |
Square of a big number
.
for large
(equivalent b->size).
, where
is the radix, it is based on the following simplification:
b with c or aliasing b->digits with c->digits is not allowed. c->digits must point to pre-allocated memory space for at least (2 * b->size) digits, at minimum one digit.| [in] | b | Argument to be squared. |
| [out] | c | Result . |
| void c4e_bigint_div | ( | C4eElement *C4E_RESTRICT | a, | |
| C4eElement *C4E_RESTRICT | b, | |||
| C4eElement *C4E_RESTRICT | q | |||
| ) |
Division of two big numbers
using the Pope and Stein algorithm.
Multi-Precision Division
a->size * b->size).b is temporary modified - so it must be writable. After function return it holds the same value as at function entry.a and b must be normalized. b)). a with b or aliasing a->digits with b->digits is not allowed. a->digits is also used as workplace, there must be pre-allocated memory space for at least (a->size + 1) digits. q->digits must point to pre-allocated memory space for at least (a->size - b->size + 1) digits.D. A. Pope and M. L. Stein: Multiple Precision Arithmetic. CACM, 3:652-654, 1960
G. E. Collins and D. R. Musser: Analysis of the Pope- Stein Division Algorithm. University of Wisconsin Computer Sciences Department, Technical Report #55, Jan 1969
D. E. Knuth: The Art of Computer Programming, Vol. 2 (Semi-Numerical Algorithms). Addison-Wesley, 1997
| [in,out] | a | Dividend as input, remainder as output. |
| [in] | b | Divisor (temporary modified). |
| [out] | q | Integer quotient q = floor(a / b). If q is NULL then no quotient will be returned. |
| void c4e_bigint_mod | ( | C4eElement *C4E_RESTRICT | a, | |
| C4eElement *C4E_RESTRICT | b | |||
| ) |
Modulo division of two big numbers
using the Pope and Stein algorithm.
Multi-Precision Division
a->size * b->size).b is temporary modified - so it must be writable. After function return it holds the same value as at function entry.a and b must be normalized. b)). a with b or aliasing a->digits with b->digits is not allowed. a->digits is also used as workplace, there must be pre-allocated memory space for at least (a->size + 1) digits.D. A. Pope and M. L. Stein: Multiple Precision Arithmetic. CACM, 3:652-654, 1960
G. E. Collins and D. R. Musser: Analysis of the Pope- Stein Division Algorithm. University of Wisconsin Computer Sciences Department, Technical Report #55, Jan 1969
D. E. Knuth: The Art of Computer Programming, Vol. 2 (Semi-Numerical Algorithms). Addison-Wesley, 1997
| [in,out] | a | Dividend as input, remainder as output. |
| [in] | b | Divisor (temporary modified). |
| void c4e_bigint_gcd | ( | C4eElemTriple * | a, | |
| C4eElemTriple * | b, | |||
| C4eArchSize | n | |||
| ) |
Greatest Common Divisor of two numbers
. It calculates the GCD of a->x and b->x together with the Bezout cofactors
and
in equation
.
the algorithm computes
in a->y and returns a->x in a->z, b->x in b->z, if n is zero.
and for example also
applies, then the Bezout cofactors will become (for this case):
, independent of the value of
. a->x.size * b->x.size). a->z resp. b->z means:
resp.
. With respect to Bezout's identity it satisfies the following equation:
and
are really coprime. Modular division of the identity above gives:
a->x and b->x must be normalized, e.g. using function c4e_elem_norm(). a->x and b->x are both zero (C4E_ELEM_IS_ZERO()). a->x and b->x plus (n / C4E_SYS_DIGIT_BITS + 1) digits.J. Stein: Computational problems associated with Racah algebra. Journal of Computational Physics, 1, 1967.
Bojanczyk, A. and R. P. Brent: A systolic algorithm for extended GCD computation. Computers & Mathematics with Applications, 14(4):233-238, 1987.
Burton S. Kaliski: The Montgomery Inverse and Its Applications. IEEE Transactions on Computers, 44(8):1064-1065, August 1995.
| [in,out] | a | As an input parameter a->x holds the number, for which the GCD with b->x is calculated. As an output it returns:
|
| [in,out] | b | As an input parameter b->x holds the number, for which the GCD with a->x is calculated. As an output it returns:
|
| [in] | n | The number n in equation . If n is zero it returns simply the Bezout cofactors in equation . |
1.6.1