home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 6
/
Sonderheft_6-96.iso
/
pd
/
libraries
/
bignum
/
developpers
/
doc
/
bignum.doc
next >
Wrap
Text File
|
1996-11-03
|
7KB
|
275 lines
----------------------------------
----------------------------------
BigNum library is a Ringard' Production 1996
©Allenbrand Brice
----------------------------------
----------------------------------
----------------------------------------------------------------------
BigNum.library v37.1
THE Multiprecision integer library !
This library is shareware. If you use it, please send : 10$ to
Allenbrand Brice
5, rue du Manège
68100 Mulhouse
FRANCE
If you have suggestions I'd be happy to answer them.
I'm looking for a multiplication FFT based algorithm.
----------------------------------------------------------------------
This package contains the library and the protos for C programming.
YOU MUST HAVE AT LEAST A 68020 PROCESSOR OR THE LIBRARY WON'T OPEN !!
----------------------------------------------------------------------
*)BigNum.library has been written using SAS/6.56 and do NOT need any ixemul
or some f...ing library. It takes advantage of the Amiga system for
maximum efficiency.
*)Today a BigNum is limited to 4500 digits and the library will need 200Kb RAM
*)The library will manage 50 BigNums at a time. All the allocations are made
during the opening of the library for speed-up efficiency.
*)All overflows or division by 0 are managed by the library. (Hope so...)
*)It is easy to Use (yes yes)
*)No Enforcer hits (sure)
----------------------------------------------------------------------
USAGE :
1) #include <proto/BigNum.h>
2) struct Library *BigNumBase;
3) At first, open the library with the common way.
4) Then declare your BigNum : PtrBigNum x,y,z,u,i,op......
5) Then INITIALIZE THEM : x=BigNumInit();y=BigNumInit()....
6) Make your computations......
.....
......
.....
7) After using, FREE THEM or you'll have warning message when you close
the library. If you forget it, this won't crash the machine or lose
memory, but it is an efficient way to know what if what you've done is
right
e.g if you Init 5 BigNums then call BigNumFree(5);
8) Close the library or you'll lose 200Kb of memory.
----------------------------------------------------------------------
Commands :
BigNumSetNul(x) x=0
BigNumSize(x) returns the greater n where 32768^(n-1)<x
BigNumIsEven(x) if x is even returns 1; 0 otherwise
BigNumAbsBigNum(x,y) x=abs(x)
BigNumIsNul(x) if x==0 returns 1; 0 otherwise
BigNumIsPositive(x) if x>=0 returns 1; 0 otherwise
BigNumNegative(x) x=-x
----------------------------------
/* Addition */
----------------------------------
void BigNumAdd(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=x+y
void BigNumDigitAdd(PtrBigNum x,int y);
x=x+y
----------------------------------
/* Division */
----------------------------------
void BigNumDiv(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=x/y
void BigNumDigitDiv(PtrBigNum x,int y,PtrBigNum z);
z=x/y
void BigNumRightShift(PtrBigNum x,PtrBigNum z);
z=x/2
void BigNumModulo(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=x mod y
void BigNumEDiv(PtrBigNum x,PtrBigNum y,PtrBigNum z,PtrBigNum Rest);
z=x/y and rest=x mod y
----------------------------------
/* Multiplication */
----------------------------------
void BigNumMul(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=x*y
void BigNumDigitMul(PtrBigNum x,int y);
x=x*y
void BigNumLeftShift(PtrBigNum x);
x=x*2
----------------------------------
/* Substraction */
----------------------------------
void BigNumSub(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=x-y
void BigNumDigitSub(PtrBigNum x,int y);
x=x-y
----------------------------------
/* Displaying */
----------------------------------
void BigNumDisplay(PtrBigNum z);
for debugging. Do not use.
void BigNumPrint(PtrBigNum x);
print(x) !!!!
----------------------------------
/* Conversion */
----------------------------------
void BigNumStrToBigNum(PtrBigNum x,char *S);
convert an ASCII string to a BigNum
void BigNumToStr(PtrBigNum x,char *y);
convert a BigNum to an ASCII string
void BigNumIntToBigNum(PtrBigNum z,int x);
convert an integer to a BigNum
int BigNumToInt(PtrBigNum z);
convert a BigNum to an integer
----------------------------------
/* Comparison */
----------------------------------
int BigNumCompare(PtrBigNum x,PtrBigNum y);
return 1 if x>y
return -1 if x<y
return 0 if x==y
int BigNumFastCompare(PtrBigNum x,PtrBigNum y);
Same as Compare but do not take look at the sign
----------------------------------
/* Prime tests */
----------------------------------
int BigNumDiffCarre(PtrBigNum n,PtrBigNum res,int lim);
lim must be <31. The higher it is, the precise will be the result
Take care, because the computation can be very long !!
If a factor of n was found, it is returned in res
The function returns -1 if n is surelyprime
1 if n is surely not prime
0 if n is probably prime
int BigNumRho(PtrBigNum n,PtrBigNum res,int lim);
lim must be <31. The higher it is, the precise will be the result
Take care, because the computation can be very long !!
If a factor of n was found, it is returned in res
The function returns 1 if n is probably prime
0 if n is not prime
int BigNumBrutePrime(PtrBigNum i,int aff);
Take care, because the computation can be very long !!
If a factor of n was found, it is printed if aff=1 otherwise
the function returns 1.
The function returns 1 if a factor was found
0 otherwise
----------------------------------
/* Div. */
----------------------------------
void BigNumRnd(int n,PtrBigNum z);
z will be a random number between 1 and 32768^(n-1)
void BigNumPgcd(PtrBigNum x,PtrBigNum y,PtrBigNum z);
z=pgcd(x,y)
void BigNumPuiModulo(PtrBigNum x,PtrBigNum y,PtrBigNum z,PtrBigNum t);
t=x^y modulo z
int BigNumSqrt(PtrBigNum x,PtrBigNum y);
y=sqrt(x)
The function returns 1 if y*y=x (perfect square), otherwise 0
void BigNumSwap(PtrBigNum x,PtrBigNum y);
swap x and y
void BigNumAssign(PtrBigNum x,PtrBigNum y);
x=y
----------------------------------
/* Alloc/Free */
----------------------------------
PtrBigNum BigNumInit(void);
Init a declared BigNum. DON'T FORGET IT !!
void BigNumFree(int i);
Free the last 'i' BigNum(s).
More will be done in the next version.......SURE !!!!