/*************************************************************** * * * gint.h * * * * Header file for large-integer arithmetic library giants * * * * Updates: * * 18 Jul 99 REC Added fer_mod(). * * 30 Apr 98 JF USE_ASSEMBLER_MUL removed * * 29 Apr 98 JF Function prototypes cleaned up * * 20 Apr 97 RDW * * * * (c) 1997 Perfectly Scientific, Inc. * * All Rights Reserved. * * * ***************************************************************/ #define EXT __declspec(dllexport) /*************************************************************** * * * Error Codes * * * ***************************************************************/ #define OVFLOW 2 #define SIGN 3 #define AUTO_MUL 0 #define GRAMMAR_MUL 1 #define FFT_MUL 2 #define KARAT_MUL 3 /*************************************************************** * * * Preprocessor definitions * * * ***************************************************************/ /* * 2^(16*MAX_SHORTS)-1 will fit into a giant, but take care: * one usually has squares, etc. of giants involved, and * every intermediate giant in a calculation must fit into * this many shorts. Thus, if you want systematically to effect * arithmetic on B-bit operands, you need MAX_SHORTS > B/8, * preferably a tad larger than this; e.g. MAX_SHORTS > B/7. */ #define MAX_SHORTS (1<<19) #define D_MAX 600 #define NUM_PRIMES 6542 /* PrimePi[2^16]. */ #define INFINITY (-1) #define FALSE 0 #define TRUE 1 #define TWOPI (double)(2*3.1415926535897932384626433) #define SQRTHALF (double)(0.707106781186547524400844362104) #define TWO16 (double)(65536.0) #define TWOM16 (double)(0.0000152587890625) // Decimal digit ceiling in digit-input routines. #define MAX_DIGITS 10000 // Next, mumber of shorts per operand at which Karatsuba breaks over. #define KARAT_BREAK 40 // Next, mumber of shorts per operand at which FFT breaks over. #define FFT_BREAK 200 #define newmin(a,b) ((a)<(b)? (a) : (b)) #define newmax(a,b) ((a)>(b)? (a) : (b)) // The limit below which hgcd is too ponderous #define GCDLIMIT 5000 // The limit below which ordinary ints will be used #define INTLIMIT 31 // Size by which to increment the stack used in pushg() and popg(). #define STACK_GROW 16 /*************************************************************** * * * Structure definitions * * * ***************************************************************/ typedef struct { int sign; unsigned short n[1]; /* number of shorts = abs(sign) */ } giantstruct; typedef giantstruct *giant; typedef struct _matrix { giant ul; /* upper left */ giant ur; /* upper right */ giant ll; /* lower left */ giant lr; /* lower right */ } *gmatrix; typedef struct { double re; double im; } complex; #define MSGMAX 257 typedef struct { int yes; int parnr; char * plasterror; char * pversion; char version [MSGMAX]; char lasterror [MSGMAX]; } einfo; #define SZMAX 32000 typedef struct { int sz; char TheData [SZMAX]; } results; /*************************************************************** * * * Function Prototypes * * * ***************************************************************/ /*************************************************************** * * * Initialization and utility functions * * * ***************************************************************/ // trig lookups. void init_sinCos(int); double s_sin(int); double s_cos(int); void init_ellmul (long size); int xergint (char *srname, int info); // stack handling functions. EXT giant popg (void); EXT void pushg (int); // Creates a new giant, numshorts = INFINITY invokes the maximum MAX_SHORTS. EXT giant newgiant (int numshorts); // Creates a new giant matrix, but does not malloc the component giants. EXT gmatrix newgmatrix (void); // Returns the bit-length n; e.g. n=7 returns 3. EXT int bitlen (giant n); // Returns the value of the pos bit of n. EXT int bitval (giant n, int pos); // Returns whether g is one. EXT int isone (giant g); // Returns whether g is zero. EXT int isZero (giant g); // Copies one giant to another. EXT void gtog (giant src, giant dest); // Integer <-> giant. EXT void itog (int n, giant g); EXT signed int gtoi (giant); // Returns the sign of g: -1, 0, 1. EXT int gsign (giant g); // Returns 1, 0, -1 as a>b, a=b, a