[35aab3] | 1 | #ifndef LONGRAT_H |
---|
| 2 | #define LONGRAT_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
[341696] | 6 | /* $Id$ */ |
---|
[35aab3] | 7 | /* |
---|
| 8 | * ABSTRACT: computation with long rational numbers |
---|
| 9 | */ |
---|
[18cb65] | 10 | #include <misc/auxiliary.h> |
---|
| 11 | #include <omalloc/omalloc.h> |
---|
[9eb0f9] | 12 | #include <coeffs/si_gmp.h> |
---|
| 13 | #include <coeffs/coeffs.h> |
---|
[7d90aa] | 14 | |
---|
[ffde366] | 15 | #define SR_HDL(A) ((long)(A)) |
---|
| 16 | |
---|
[7447d8] | 17 | #define SR_INT 1L |
---|
[7d90aa] | 18 | #define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT)) |
---|
[35aab3] | 19 | #define SR_TO_INT(SR) (((long)SR) >> 2) |
---|
| 20 | |
---|
| 21 | #define MP_SMALL 1 |
---|
| 22 | |
---|
| 23 | #define mpz_size1(A) (ABS((A)->_mp_size)) |
---|
| 24 | //#define mpz_size1(A) mpz_size(A) |
---|
| 25 | |
---|
| 26 | struct snumber; |
---|
| 27 | typedef struct snumber *number; |
---|
| 28 | struct snumber |
---|
| 29 | { |
---|
[502f7e8] | 30 | mpz_t z; |
---|
| 31 | mpz_t n; |
---|
[35aab3] | 32 | #if defined(LDEBUG) |
---|
| 33 | int debug; |
---|
| 34 | #endif |
---|
| 35 | BOOLEAN s; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | // allow inlining only from p_Numbers.h and if ! LDEBUG |
---|
| 39 | |
---|
| 40 | #if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG) |
---|
| 41 | #define LINLINE static inline |
---|
| 42 | #else |
---|
| 43 | #define LINLINE |
---|
| 44 | #undef DO_LINLINE |
---|
| 45 | #endif // DO_LINLINE |
---|
| 46 | |
---|
[7d90aa] | 47 | LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r); |
---|
| 48 | LINLINE number nlInit(int i, const coeffs r); |
---|
[ea11dc] | 49 | number nlRInit (long i); |
---|
[7d90aa] | 50 | LINLINE BOOLEAN nlIsOne(number a, const coeffs r); |
---|
| 51 | LINLINE BOOLEAN nlIsZero(number za, const coeffs r); |
---|
[a642c64] | 52 | LINLINE number nlCopy(number a, const coeffs r); |
---|
[7d90aa] | 53 | LINLINE number nl_Copy(number a, const coeffs r); |
---|
| 54 | LINLINE void nlDelete(number *a, const coeffs r); |
---|
| 55 | LINLINE number nlNeg(number za, const coeffs r); |
---|
| 56 | LINLINE number nlAdd(number la, number li, const coeffs r); |
---|
| 57 | LINLINE number nlSub(number la, number li, const coeffs r); |
---|
| 58 | LINLINE number nlMult(number a, number b, const coeffs r); |
---|
[35aab3] | 59 | |
---|
[1cce47] | 60 | BOOLEAN nlInitChar(coeffs r, void*); |
---|
[51d835] | 61 | |
---|
[a642c64] | 62 | number nlInit2 (int i, int j, const coeffs r); |
---|
[a1ab2a] | 63 | number nlInit2gmp (mpz_t i, mpz_t j); |
---|
[7d90aa] | 64 | number nlGcd(number a, number b, const coeffs r); |
---|
| 65 | number nlLcm(number a, number b, const coeffs r); /*special routine !*/ |
---|
| 66 | BOOLEAN nlGreater(number a, number b, const coeffs r); |
---|
| 67 | BOOLEAN nlIsMOne(number a, const coeffs r); |
---|
| 68 | int nlInt(number &n, const coeffs r); |
---|
[7f7573] | 69 | number nlBigInt(number &n); |
---|
[f1c465f] | 70 | |
---|
[894f5b1] | 71 | #ifdef HAVE_RINGS |
---|
[4d1ae5] | 72 | void nlGMP(number &i, number n, const coeffs r); |
---|
[894f5b1] | 73 | #endif |
---|
[f1c465f] | 74 | |
---|
[7d90aa] | 75 | BOOLEAN nlGreaterZero(number za, const coeffs r); |
---|
| 76 | number nlInvers(number a, const coeffs r); |
---|
| 77 | void nlNormalize(number &x, const coeffs r); |
---|
| 78 | number nlDiv(number a, number b, const coeffs r); |
---|
| 79 | number nlExactDiv(number a, number b, const coeffs r); |
---|
| 80 | number nlIntDiv(number a, number b, const coeffs r); |
---|
| 81 | number nlIntMod(number a, number b, const coeffs r); |
---|
| 82 | void nlPower(number x, int exp, number *lu, const coeffs r); |
---|
| 83 | const char * nlRead (const char *s, number *a, const coeffs r); |
---|
| 84 | void nlWrite(number &a, const coeffs r); |
---|
[0fb5991] | 85 | int nlModP(number n, int p, const coeffs r); |
---|
[7d90aa] | 86 | int nlSize(number n, const coeffs r); |
---|
| 87 | number nlGetDenom(number &n, const coeffs r); |
---|
| 88 | number nlGetNumerator(number &n, const coeffs r); |
---|
[8167af] | 89 | void nlCoeffWrite(const coeffs r); |
---|
[35aab3] | 90 | #ifdef LDEBUG |
---|
[85e68dd] | 91 | BOOLEAN nlDBTest(number a, const char *f, const int l); |
---|
[35aab3] | 92 | #endif |
---|
| 93 | extern number nlOne; |
---|
| 94 | |
---|
[7d90aa] | 95 | nMapFunc nlSetMap(const coeffs src, const coeffs dst); |
---|
[35aab3] | 96 | |
---|
[f9201c] | 97 | extern omBin rnumber_bin; |
---|
[7d90aa] | 98 | |
---|
| 99 | |
---|
| 100 | #define FREE_RNUMBER(x) omFreeBin((void *)x, rnumber_bin) |
---|
[896561] | 101 | #define ALLOC_RNUMBER() (number)omAllocBin(rnumber_bin) |
---|
| 102 | #define ALLOC0_RNUMBER() (number)omAlloc0Bin(rnumber_bin) |
---|
[35aab3] | 103 | |
---|
| 104 | // in-place operations |
---|
[7d90aa] | 105 | void nlInpGcd(number &a, number b, const coeffs r); |
---|
| 106 | void nlInpIntDiv(number &a, number b, const coeffs r); |
---|
[9f1a52] | 107 | |
---|
| 108 | LINLINE void nlInpAdd(number &a, number b, const coeffs r); |
---|
[7d90aa] | 109 | LINLINE void nlInpMult(number &a, number b, const coeffs r); |
---|
[35aab3] | 110 | |
---|
[3149a5] | 111 | number nlFarey(number nP, number nN); |
---|
| 112 | |
---|
[aaf0b6] | 113 | #ifdef LDEBUG |
---|
[2b957a] | 114 | #define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r) |
---|
| 115 | BOOLEAN nlDBTest(number a, char *f,int l, const coeffs r); |
---|
[aaf0b6] | 116 | #else |
---|
[2b957a] | 117 | #define nlTest(a, r) ((void)0) |
---|
[aaf0b6] | 118 | #endif |
---|
| 119 | |
---|
[35aab3] | 120 | #endif |
---|
| 121 | |
---|
| 122 | |
---|