[35aab3] | 1 | #ifndef LONGRAT_H |
---|
| 2 | #define LONGRAT_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
| 6 | /* |
---|
| 7 | * ABSTRACT: computation with long rational numbers |
---|
| 8 | */ |
---|
[18cb65] | 9 | #include <misc/auxiliary.h> |
---|
| 10 | #include <omalloc/omalloc.h> |
---|
[2bc4f5] | 11 | |
---|
[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 | |
---|
| 24 | struct snumber; |
---|
| 25 | typedef struct snumber *number; |
---|
| 26 | struct snumber |
---|
| 27 | { |
---|
[502f7e8] | 28 | mpz_t z; |
---|
| 29 | mpz_t n; |
---|
[35aab3] | 30 | #if defined(LDEBUG) |
---|
| 31 | int debug; |
---|
| 32 | #endif |
---|
| 33 | BOOLEAN s; |
---|
| 34 | }; |
---|
| 35 | |
---|
| 36 | // allow inlining only from p_Numbers.h and if ! LDEBUG |
---|
| 37 | |
---|
| 38 | #if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG) |
---|
| 39 | #define LINLINE static inline |
---|
| 40 | #else |
---|
| 41 | #define LINLINE |
---|
| 42 | #undef DO_LINLINE |
---|
| 43 | #endif // DO_LINLINE |
---|
| 44 | |
---|
[7d90aa] | 45 | LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r); |
---|
[2f3764] | 46 | LINLINE number nlInit(long i, const coeffs r); |
---|
[ea11dc] | 47 | number nlRInit (long i); |
---|
[7d90aa] | 48 | LINLINE BOOLEAN nlIsOne(number a, const coeffs r); |
---|
| 49 | LINLINE BOOLEAN nlIsZero(number za, const coeffs r); |
---|
[a642c64] | 50 | LINLINE number nlCopy(number a, const coeffs r); |
---|
[7d90aa] | 51 | LINLINE number nl_Copy(number a, const coeffs r); |
---|
| 52 | LINLINE void nlDelete(number *a, const coeffs r); |
---|
| 53 | LINLINE number nlNeg(number za, const coeffs r); |
---|
| 54 | LINLINE number nlAdd(number la, number li, const coeffs r); |
---|
| 55 | LINLINE number nlSub(number la, number li, const coeffs r); |
---|
| 56 | LINLINE number nlMult(number a, number b, const coeffs r); |
---|
[35aab3] | 57 | |
---|
[1cce47] | 58 | BOOLEAN nlInitChar(coeffs r, void*); |
---|
[51d835] | 59 | |
---|
[a642c64] | 60 | number nlInit2 (int i, int j, const coeffs r); |
---|
[a1ab2a] | 61 | number nlInit2gmp (mpz_t i, mpz_t j); |
---|
[d663f2] | 62 | |
---|
| 63 | // number nlInitMPZ(mpz_t m, const coeffs r); |
---|
| 64 | // void nlMPZ(mpz_t m, number &n, const coeffs r); |
---|
| 65 | |
---|
[7d90aa] | 66 | number nlGcd(number a, number b, const coeffs r); |
---|
| 67 | number nlLcm(number a, number b, const coeffs r); /*special routine !*/ |
---|
| 68 | BOOLEAN nlGreater(number a, number b, const coeffs r); |
---|
| 69 | BOOLEAN nlIsMOne(number a, const coeffs r); |
---|
| 70 | int nlInt(number &n, const coeffs r); |
---|
[7f7573] | 71 | number nlBigInt(number &n); |
---|
[f1c465f] | 72 | |
---|
[894f5b1] | 73 | #ifdef HAVE_RINGS |
---|
[6cc7f5] | 74 | number nlMapGMP(number from, const coeffs src, const coeffs dst); |
---|
[4d1ae5] | 75 | void nlGMP(number &i, number n, const coeffs r); |
---|
[894f5b1] | 76 | #endif |
---|
[f1c465f] | 77 | |
---|
[7d90aa] | 78 | BOOLEAN nlGreaterZero(number za, const coeffs r); |
---|
| 79 | number nlInvers(number a, const coeffs r); |
---|
| 80 | void nlNormalize(number &x, const coeffs r); |
---|
| 81 | number nlDiv(number a, number b, const coeffs r); |
---|
| 82 | number nlExactDiv(number a, number b, const coeffs r); |
---|
| 83 | number nlIntDiv(number a, number b, const coeffs r); |
---|
| 84 | number nlIntMod(number a, number b, const coeffs r); |
---|
| 85 | void nlPower(number x, int exp, number *lu, const coeffs r); |
---|
| 86 | const char * nlRead (const char *s, number *a, const coeffs r); |
---|
| 87 | void nlWrite(number &a, const coeffs r); |
---|
[79020f] | 88 | |
---|
| 89 | /// Map q \in QQ \to Zp |
---|
| 90 | number nlModP(number q, const coeffs Q, const coeffs Zp); |
---|
| 91 | |
---|
[7d90aa] | 92 | int nlSize(number n, const coeffs r); |
---|
| 93 | number nlGetDenom(number &n, const coeffs r); |
---|
| 94 | number nlGetNumerator(number &n, const coeffs r); |
---|
[03f7b5] | 95 | void nlCoeffWrite(const coeffs r, BOOLEAN details); |
---|
[e8c8d5] | 96 | number nlChineseRemainder(number *x, number *q,int rl, const coeffs C); |
---|
| 97 | number nlFarey(number nN, number nP, const coeffs CF); |
---|
[045efb] | 98 | |
---|
[35aab3] | 99 | #ifdef LDEBUG |
---|
[85e68dd] | 100 | BOOLEAN nlDBTest(number a, const char *f, const int l); |
---|
[35aab3] | 101 | #endif |
---|
| 102 | extern number nlOne; |
---|
| 103 | |
---|
[7d90aa] | 104 | nMapFunc nlSetMap(const coeffs src, const coeffs dst); |
---|
[35aab3] | 105 | |
---|
[f9201c] | 106 | extern omBin rnumber_bin; |
---|
[7d90aa] | 107 | |
---|
| 108 | #define FREE_RNUMBER(x) omFreeBin((void *)x, rnumber_bin) |
---|
[896561] | 109 | #define ALLOC_RNUMBER() (number)omAllocBin(rnumber_bin) |
---|
| 110 | #define ALLOC0_RNUMBER() (number)omAlloc0Bin(rnumber_bin) |
---|
[35aab3] | 111 | |
---|
| 112 | // in-place operations |
---|
[7d90aa] | 113 | void nlInpGcd(number &a, number b, const coeffs r); |
---|
| 114 | void nlInpIntDiv(number &a, number b, const coeffs r); |
---|
[9f1a52] | 115 | |
---|
| 116 | LINLINE void nlInpAdd(number &a, number b, const coeffs r); |
---|
[7d90aa] | 117 | LINLINE void nlInpMult(number &a, number b, const coeffs r); |
---|
[35aab3] | 118 | |
---|
[aaf0b6] | 119 | #ifdef LDEBUG |
---|
[2b957a] | 120 | #define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r) |
---|
| 121 | BOOLEAN nlDBTest(number a, char *f,int l, const coeffs r); |
---|
[aaf0b6] | 122 | #else |
---|
[2b957a] | 123 | #define nlTest(a, r) ((void)0) |
---|
[aaf0b6] | 124 | #endif |
---|
| 125 | |
---|
[35aab3] | 126 | #endif |
---|
| 127 | |
---|
| 128 | |
---|