My Project
Loading...
Searching...
No Matches
longrat0.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT -
6* IO for long rational numbers (Hubert Grassmann)
7*/
8
9#include <stdio.h>
10#include <string.h>
11
12#include "misc/auxiliary.h"
13#include "reporter/reporter.h"
14
15#include "coeffs/coeffs.h"
16#include "coeffs/numbers.h"
17#include "coeffs/longrat.h"
18
19VAR omBin rnumber_bin = omGetSpecBin(sizeof(snumber)); // TODO: move this into coeffs-struct (for Q)?!
20
21
22#define SR_HDL(A) ((long)(A))
23//#define SR_INT 1 // already in longrat.h
24//#define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))
25#define SR_TO_INT(SR) (((long)SR) >> 2)
26
27
28/*2
29* extracts the number a from s, returns the rest
30*/
31const char * nlRead (const char *s, number *a, const coeffs r)
32{
33 if (*s<'0' || *s>'9')
34 {
35 *a = INT_TO_SR(1); /* nlInit(1) */
36 return s;
37 }
38 *a=(number)ALLOC_RNUMBER();
39 {
40 (*a)->s = 3;
41#if defined(LDEBUG)
42 (*a)->debug=123456;
43#endif
44 mpz_ptr z=(*a)->z;
45 mpz_ptr n=(*a)->n;
46 mpz_init(z);
47 s = nEatLong((char *)s, z);
48 if (*s == '/')
49 {
50 mpz_init(n);
51 (*a)->s = 0;
52 s++;
53 s = nEatLong((char *)s, n);
54 if (mpz_cmp_si(n,0L)==0)
55 {
57 mpz_clear(n);
58 (*a)->s = 3;
59 }
60 else if (mpz_cmp_si(n,1L)==0)
61 {
62 mpz_clear(n);
63 (*a)->s=3;
64 }
65 }
66 if (mpz_cmp_si(z,0L)==0)
67 {
68 mpz_clear(z);
69 FREE_RNUMBER(*a);
70 *a=INT_TO_SR(0);
71 }
72 else if ((*a)->s==3)
73 {
74 number nlShort3_noinline(number x);
75 *a=nlShort3_noinline(*a);
76 }
77 else
78 {
79 number aa=*a;
80 nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
81 *a=aa;
82 }
83 }
84 return s;
85}
86
87/*2
88* write a rational number
89*/
90void nlWrite (number a, const coeffs)
91{
92 char *s,*z;
93 if (SR_HDL(a) & SR_INT)
94 {
95 StringAppend("%ld",SR_TO_INT(a));
96 }
97 else if (a==NULL)
98 {
99 StringAppendS("o");
100 }
101 else
102 {
103 int l=mpz_sizeinbase(a->z,10);
104 if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
105 l+=2;
106 s=(char*)omAlloc(l);
107 z=mpz_get_str(s,10,a->z);
108 StringAppendS(z);
109 if (a->s!=3)
110 {
111 StringAppendS("/");
112 z=mpz_get_str(s,10,a->n);
113 StringAppendS(z);
114 }
115 omFreeSize((void *)s,l);
116 }
117}
118
119#if 0
120void nlDebugWrite (number a)
121{
122 char *s,*z;
123 if (SR_HDL(a) & SR_INT)
124 {
125 Print("%ld",SR_TO_INT(a));
126 }
127 else if (a==NULL)
128 {
129 PrintS("o");
130 }
131 else
132 {
133 int l=mpz_sizeinbase(a->z,10);
134 if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
135 l+=2;
136 s=(char*)omAlloc(l);
137 z=mpz_get_str(s,10,a->z);
138 PrintS(z);
139 if (a->s!=3)
140 {
141 PrintS("/");
142 z=mpz_get_str(s,10,a->n);
143 PrintS(z);
144 }
145 omFreeSize((void *)s,l);
146 }
147}
148#endif
All the auxiliary stuff.
static int si_max(const int a, const int b)
Definition: auxiliary.h:124
int l
Definition: cfEzgcd.cc:100
Variable x
Definition: cfModGcd.cc:4082
Coefficient rings, fields and other domains suitable for Singular polynomials.
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
#define Print
Definition: emacs.cc:80
#define StringAppend
Definition: emacs.cc:79
const CanonicalForm int s
Definition: facAbsFact.cc:51
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define VAR
Definition: globaldefs.h:5
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:31
VAR omBin rnumber_bin
Definition: longrat0.cc:19
void nlWrite(number a, const coeffs)
Definition: longrat0.cc:90
#define SR_HDL(A)
Definition: longrat0.cc:22
#define SR_TO_INT(SR)
Definition: longrat0.cc:25
number nlShort3_noinline(number x)
Definition: longrat.cc:159
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1486
#define SR_INT
Definition: longrat.h:67
#define INT_TO_SR(INT)
Definition: longrat.h:68
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition: longrat.h:49
The main handler for Singular numbers which are suitable for Singular polynomials.
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition: numbers.cc:718
const char *const nDivBy0
Definition: numbers.h:89
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omGetSpecBin(size)
Definition: omBin.h:11
#define NULL
Definition: omList.c:12
omBin_t * omBin
Definition: omStructs.h:12
void StringAppendS(const char *st)
Definition: reporter.cc:107
void PrintS(const char *s)
Definition: reporter.cc:284