source: git/libpolys/coeffs/longrat.h @ 4154bb

spielwiese
Last change on this file since 4154bb was d101b1, checked in by Oleksandr Motsak <http://goo.gl/mcpzY>, 11 years ago
Silence some warnings about statements without effect Insired by [039a51b3aa3c77c2b7bae73d24de8521df45aed2]
  • Property mode set to 100644
File size: 5.6 KB
Line 
1#ifndef LONGRAT_H
2#define LONGRAT_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/*
7* ABSTRACT: computation with long rational numbers
8*/
9#include <misc/auxiliary.h>
10#include <omalloc/omalloc.h>
11
12#include <coeffs/si_gmp.h>
13#include <coeffs/coeffs.h>
14
15struct snumber;
16typedef struct snumber  *number;
17
18/*-----------------------------------------------------------------*/
19/**
20**  'SR_INT' is the type of those integers small enough to fit into  29  bits.
21**  Therefor the value range of this small integers is: $-2^{28}...2^{28}-1$.
22**
23**  Small integers are represented by an immediate integer handle, containing
24**  the value instead of pointing  to  it,  which  has  the  following  form:
25**
26**      +-------+-------+-------+-------+- - - -+-------+-------+-------+
27**      | guard | sign  | bit   | bit   |       | bit   | tag   | tag   |
28**      | bit   | bit   | 27    | 26    |       | 0     | 0     | 1     |
29**      +-------+-------+-------+-------+- - - -+-------+-------+-------+
30**
31**  Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
32**  This distuingishes immediate integers from other handles which  point  to
33**  structures aligned on 4 byte boundaries and therefor have last bit  zero.
34**  (The second bit is reserved as tag to allow extensions of  this  scheme.)
35**  Using immediates as pointers and dereferencing them gives address errors.
36**
37**  To aid overflow check the most significant two bits must always be equal,
38**  that is to say that the sign bit of immediate integers has a  guard  bit.
39**
40**  The macros 'INT_TO_SR' and 'SR_TO_INT' should be used to convert  between
41**  a small integer value and its representation as immediate integer handle.
42**
43**  Large integers and rationals are represented by z and n
44**  where n may be undefined (if s==3)
45**  NULL represents only deleted values
46*/
47
48struct snumber
49{
50  mpz_t z; //< Zaehler
51  mpz_t n; //< Nenner
52#if defined(LDEBUG)
53  int debug;
54#endif
55
56  /**
57   * parameter s in number:
58   * 0 (or FALSE): not normalised rational
59   * 1 (or TRUE):  normalised rational
60   * 3          :  integer with n==NULL
61   **/
62  BOOLEAN s; //< integer parameter
63};
64
65#define SR_HDL(A) ((long)(A))
66
67#define SR_INT    1L
68#define INT_TO_SR(INT)  ((number) (((long)INT << 2) + SR_INT))
69#define SR_TO_INT(SR)   (((long)SR) >> 2)
70
71#define MP_SMALL 1
72
73
74
75// allow inlining only from p_Numbers.h and if ! LDEBUG
76
77#if defined(DO_LINLINE) && defined(P_NUMBERS_H) && !defined(LDEBUG)
78#define LINLINE static inline
79#else
80#define LINLINE
81#undef DO_LINLINE
82#endif // DO_LINLINE
83
84LINLINE BOOLEAN  nlEqual(number a, number b, const coeffs r);
85LINLINE number   nlInit(long i, const coeffs r);
86number nlRInit (long i);
87LINLINE BOOLEAN  nlIsOne(number a, const coeffs r);
88LINLINE BOOLEAN  nlIsZero(number za, const coeffs r);
89LINLINE number   nlCopy(number a, const coeffs r);
90LINLINE number   nl_Copy(number a, const coeffs r);
91LINLINE void     nlDelete(number *a, const coeffs r);
92LINLINE number   nlNeg(number za, const coeffs r);
93LINLINE number   nlAdd(number la, number li, const coeffs r);
94LINLINE number   nlSub(number la, number li, const coeffs r);
95LINLINE number   nlMult(number a, number b, const coeffs r);
96
97BOOLEAN nlInitChar(coeffs r, void*);
98
99number   nlInit2 (int i, int j, const coeffs r);
100number   nlInit2gmp (mpz_t i, mpz_t j);
101
102// number nlInitMPZ(mpz_t m, const coeffs r);
103// void nlMPZ(mpz_t m, number &n, const coeffs r);
104
105number   nlGcd(number a, number b, const coeffs r);
106number nlExtGcd(number a, number b, number *s, number *t, const coeffs);
107number   nlLcm(number a, number b, const coeffs r);   /*special routine !*/
108BOOLEAN  nlGreater(number a, number b, const coeffs r);
109BOOLEAN  nlIsMOne(number a, const coeffs r);
110int      nlInt(number &n, const coeffs r);
111number   nlBigInt(number &n);
112
113#ifdef HAVE_RINGS
114number nlMapGMP(number from, const coeffs src, const coeffs dst);
115void     nlGMP(number &i, number n, const coeffs r);
116#endif
117
118BOOLEAN  nlGreaterZero(number za, const coeffs r);
119number   nlInvers(number a, const coeffs r);
120void     nlNormalize(number &x, const coeffs r);
121number   nlDiv(number a, number b, const coeffs r);
122number   nlExactDiv(number a, number b, const coeffs r);
123number   nlIntDiv(number a, number b, const coeffs r);
124number   nlIntMod(number a, number b, const coeffs r);
125void     nlPower(number x, int exp, number *lu, const coeffs r);
126const char *   nlRead (const char *s, number *a, const coeffs r);
127void     nlWrite(number &a, const coeffs r);
128
129/// Map q \in QQ \to Zp
130number nlModP(number q, const coeffs Q, const coeffs Zp);
131
132int      nlSize(number n, const coeffs r);
133number   nlGetDenom(number &n, const coeffs r);
134number   nlGetNumerator(number &n, const coeffs r);
135void     nlCoeffWrite(const coeffs r, BOOLEAN details);
136number   nlChineseRemainder(number *x, number *q,int rl, const coeffs C);
137number   nlFarey(number nN, number nP, const coeffs CF);
138
139#ifdef LDEBUG
140BOOLEAN  nlDBTest(number a, const char *f, const int l);
141#endif
142extern number nlOne;
143
144nMapFunc nlSetMap(const coeffs src, const coeffs dst);
145
146extern omBin rnumber_bin;
147
148#define FREE_RNUMBER(x) omFreeBin((void *)x, rnumber_bin)
149#define ALLOC_RNUMBER() (number)omAllocBin(rnumber_bin)
150#define ALLOC0_RNUMBER() (number)omAlloc0Bin(rnumber_bin)
151
152// in-place operations
153void nlInpGcd(number &a, number b, const coeffs r);
154void nlInpIntDiv(number &a, number b, const coeffs r);
155
156LINLINE void nlInpAdd(number &a, number b, const coeffs r);
157LINLINE void nlInpMult(number &a, number b, const coeffs r);
158
159#ifdef LDEBUG
160#define nlTest(a, r) nlDBTest(a,__FILE__,__LINE__, r)
161BOOLEAN nlDBTest(number a, char *f,int l, const coeffs r);
162#else
163#define nlTest(a, r) do {} while (0)
164#endif
165
166#endif
167
168
Note: See TracBrowser for help on using the repository browser.