source: git/libpolys/coeffs/longrat.h @ d663f2

spielwiese
Last change on this file since d663f2 was d663f2, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: fixing longrat-related bugs (due to the Uglyness in p_Numbers.h!)
  • Property mode set to 100644
File size: 3.8 KB
Line 
1#ifndef LONGRAT_H
2#define LONGRAT_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT: computation with long rational numbers
9*/
10#include <misc/auxiliary.h>
11#include <omalloc/omalloc.h>
12
13#include <coeffs/si_gmp.h>
14#include <coeffs/coeffs.h>
15
16#define SR_HDL(A) ((long)(A))
17
18#define SR_INT    1L
19#define INT_TO_SR(INT)  ((number) (((long)INT << 2) + SR_INT))
20#define SR_TO_INT(SR)   (((long)SR) >> 2)
21
22#define MP_SMALL 1
23
24
25struct snumber;
26typedef struct snumber  *number;
27struct snumber
28{
29  mpz_t z;
30  mpz_t n;
31#if defined(LDEBUG)
32  int debug;
33#endif
34  BOOLEAN s;
35};
36
37// allow inlining only from p_Numbers.h and if ! LDEBUG
38
39#if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG)
40#define LINLINE static inline
41#else
42#define LINLINE
43#undef DO_LINLINE
44#endif // DO_LINLINE
45
46LINLINE BOOLEAN  nlEqual(number a, number b, const coeffs r);
47LINLINE number   nlInit(int i, const coeffs r);
48number nlRInit (long i);
49LINLINE BOOLEAN  nlIsOne(number a, const coeffs r);
50LINLINE BOOLEAN  nlIsZero(number za, const coeffs r);
51LINLINE number   nlCopy(number a, const coeffs r);
52LINLINE number   nl_Copy(number a, const coeffs r);
53LINLINE void     nlDelete(number *a, const coeffs r);
54LINLINE number   nlNeg(number za, const coeffs r);
55LINLINE number   nlAdd(number la, number li, const coeffs r);
56LINLINE number   nlSub(number la, number li, const coeffs r);
57LINLINE number   nlMult(number a, number b, const coeffs r);
58
59BOOLEAN nlInitChar(coeffs r, void*);
60
61number   nlInit2 (int i, int j, const coeffs r);
62number   nlInit2gmp (mpz_t i, mpz_t j);
63
64// number nlInitMPZ(mpz_t m, const coeffs r);
65// void nlMPZ(mpz_t m, number &n, const coeffs r);
66
67number   nlGcd(number a, number b, const coeffs r);
68number   nlLcm(number a, number b, const coeffs r);   /*special routine !*/
69BOOLEAN  nlGreater(number a, number b, const coeffs r);
70BOOLEAN  nlIsMOne(number a, const coeffs r);
71int      nlInt(number &n, const coeffs r);
72number   nlBigInt(number &n);
73
74#ifdef HAVE_RINGS
75number nlMapGMP(number from, const coeffs src, const coeffs dst);
76void     nlGMP(number &i, number n, const coeffs r);
77#endif
78
79BOOLEAN  nlGreaterZero(number za, const coeffs r);
80number   nlInvers(number a, const coeffs r);
81void     nlNormalize(number &x, const coeffs r);
82number   nlDiv(number a, number b, const coeffs r);
83number   nlExactDiv(number a, number b, const coeffs r);
84number   nlIntDiv(number a, number b, const coeffs r);
85number   nlIntMod(number a, number b, const coeffs r);
86void     nlPower(number x, int exp, number *lu, const coeffs r);
87const char *   nlRead (const char *s, number *a, const coeffs r);
88void     nlWrite(number &a, const coeffs r);
89int      nlModP(number n, int p, const coeffs r);
90int      nlSize(number n, const coeffs r);
91number   nlGetDenom(number &n, const coeffs r);
92number   nlGetNumerator(number &n, const coeffs r);
93void     nlCoeffWrite(const coeffs r);
94number   nlChineseRemainder(number *x, number *q,int rl, const coeffs C);
95number   nlFarey(number nN, number nP, const coeffs CF);
96
97#ifdef LDEBUG
98BOOLEAN  nlDBTest(number a, const char *f, const int l);
99#endif
100extern number nlOne;
101
102nMapFunc nlSetMap(const coeffs src, const coeffs dst);
103
104extern omBin rnumber_bin;
105
106#define FREE_RNUMBER(x) omFreeBin((void *)x, rnumber_bin)
107#define ALLOC_RNUMBER() (number)omAllocBin(rnumber_bin)
108#define ALLOC0_RNUMBER() (number)omAlloc0Bin(rnumber_bin)
109
110// in-place operations
111void nlInpGcd(number &a, number b, const coeffs r);
112void nlInpIntDiv(number &a, number b, const coeffs r);
113
114LINLINE void nlInpAdd(number &a, number b, const coeffs r);
115LINLINE void nlInpMult(number &a, number b, const coeffs r);
116
117#ifdef LDEBUG
118#define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r)
119BOOLEAN nlDBTest(number a, char *f,int l, const coeffs r);
120#else
121#define nlTest(a, r) ((void)0)
122#endif
123
124#endif
125
126
Note: See TracBrowser for help on using the repository browser.