/* * giants.h * * Header file for large-integer arithmetic library * giants.c. * * */ /* 2^(16*MAX_SHORTS)-1 will fit into a giant. */ #define MAX_SHORTS ((1<<20)+(1<<8)) #define INFINITY (-1) #define FALSE 0 #define TRUE 1 #define COLUMNWIDTH 64 #define DIVIDEBYZERO 1 /* error codes */ #define OVERFLOW 2 #define SIGN 3 #define OVERRANGE 4 #define AUTO_MUL 0 #define GRAMMAR_MUL 1 #define FFT_MUL 2 #define USE_ASSEMBLER_MUL 1 #define TWOPI (2 * 3.14159265358979323846) #define SQRT2 1.41421356237309504880 #define SQRTHALF 0.70710678118654752440 #define TWO16 65536.0 #define TWOM16 0.0000152587890625 #define MAX_DIGITS 10000 /* Decimal digit ceiling in I/O * routines. */ #define BREAK_SHORTS 400 /* Number of shorts at which FFT * breaks over. */ #define min(a,b) ((a)<(b)? (a) : (b)) #define max(a,b) ((a)>(b)? (a) : (b)) #define STEPS 32 /* Maximum number of recursive steps * needed to calculate gcds of * integers */ #define GCDLIMIT 5000 /* The limit below which hgcd is too * ponderous */ #define INTLIMIT 31 /* The limit below which ordinary * ints will be used */ #define gin(x) gread(x,stdin) #define gout(x) gwriteln(x,stdout) typedef struct _giant { int sign; /* number of shorts = abs(sign) */ unsigned short n[1]; } *giant; typedef struct _gmatrix { giant ul, ur, ll, lr; /* upper left, upper right, etc. */ } *gmatrix; typedef struct { double re, im; } complex; /* * Creates a new giant, numshorts = INFINITY invokes the maximum * MAX_SHORTS. */ giant newgiant(int numshorts); /* Returns the bit-length n; e.g. n=7 returns 3. */ int bitlen(giant n); /* Returns the value of the pos bit of n. */ int bitval(giant n, int pos); int iszero(giant g); /* Returns whether g is zero. */ int isone(giant g); /* Returns whether g is one. */ /* Copies one giant to another. */ void gtog(giant src, giant dest); /* Gives a giant an int value. */ void itog(int n, giant g); /* Returns the sign of g: -1, 0, 1. */ int gsign(giant g); /* Returns 1, 0, -1 as a>b, a=b, a