My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
longrat0.cc File Reference
#include <stdio.h>
#include <string.h>
#include "misc/auxiliary.h"
#include "omalloc/omalloc.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"

Go to the source code of this file.

Macros

#define SR_HDL(A)   ((long)(A))
 
#define SR_TO_INT(SR)   (((long)SR) >> 2)
 

Functions

const char * nlRead (const char *s, number *a, const coeffs r)
 
void nlWrite (number a, const coeffs)
 

Variables

omBin rnumber_bin = omGetSpecBin(sizeof(snumber))
 

Macro Definition Documentation

◆ SR_HDL

#define SR_HDL (   A)    ((long)(A))

Definition at line 24 of file longrat0.cc.

◆ SR_TO_INT

#define SR_TO_INT (   SR)    (((long)SR) >> 2)

Definition at line 27 of file longrat0.cc.

Function Documentation

◆ nlRead()

const char* nlRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 32 of file longrat0.cc.

33 {
34  if (*s<'0' || *s>'9')
35  {
36  *a = INT_TO_SR(1); /* nlInit(1) */
37  return s;
38  }
39  *a=(number)ALLOC_RNUMBER();
40  {
41  (*a)->s = 3;
42 #if defined(LDEBUG)
43  (*a)->debug=123456;
44 #endif
45  mpz_ptr z=(*a)->z;
46  mpz_ptr n=(*a)->n;
47  mpz_init(z);
48  s = nEatLong((char *)s, z);
49  if (*s == '/')
50  {
51  mpz_init(n);
52  (*a)->s = 0;
53  s++;
54  s = nEatLong((char *)s, n);
55  if (mpz_cmp_si(n,0L)==0)
56  {
58  mpz_clear(n);
59  (*a)->s = 3;
60  }
61  else if (mpz_cmp_si(n,1L)==0)
62  {
63  mpz_clear(n);
64  (*a)->s=3;
65  }
66  }
67  if (mpz_cmp_si(z,0L)==0)
68  {
69  mpz_clear(z);
70  FREE_RNUMBER(*a);
71  *a=INT_TO_SR(0);
72  }
73  else if ((*a)->s==3)
74  {
75  number nlShort3_noinline(number x);
76  *a=nlShort3_noinline(*a);
77  }
78  else
79  {
80  number aa=*a;
81  nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
82  *a=aa;
83  }
84  }
85  return s;
86 }

◆ nlWrite()

void nlWrite ( number  a,
const  coeffs 
)

Definition at line 91 of file longrat0.cc.

92 {
93  char *s,*z;
94  if (SR_HDL(a) & SR_INT)
95  {
96  StringAppend("%ld",SR_TO_INT(a));
97  }
98  else if (a==NULL)
99  {
100  StringAppendS("o");
101  }
102  else
103  {
104  int l=mpz_sizeinbase(a->z,10);
105  if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
106  l+=2;
107  s=(char*)omAlloc(l);
108  z=mpz_get_str(s,10,a->z);
109  StringAppendS(z);
110  if (a->s!=3)
111  {
112  StringAppendS("/");
113  z=mpz_get_str(s,10,a->n);
114  StringAppendS(z);
115  }
116  omFreeSize((void *)s,l);
117  }
118 }

Variable Documentation

◆ rnumber_bin

omBin rnumber_bin = omGetSpecBin(sizeof(snumber))

Definition at line 20 of file longrat0.cc.

ALLOC_RNUMBER
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:107
x
Variable x
Definition: cfModGcd.cc:4023
nDivBy0
const char *const nDivBy0
Definition: numbers.h:89
SR_TO_INT
#define SR_TO_INT(SR)
Definition: longrat0.cc:26
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
nEatLong
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition: numbers.cc:652
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1345
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
FREE_RNUMBER
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
SR_HDL
#define SR_HDL(A)
Definition: longrat0.cc:23
SR_INT
#define SR_INT
Definition: longrat.h:66
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
NULL
#define NULL
Definition: omList.c:10
l
int l
Definition: cfEzgcd.cc:93
nlShort3_noinline
number nlShort3_noinline(number x)
Definition: longrat.cc:165
StringAppend
#define StringAppend
Definition: emacs.cc:79
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
INT_TO_SR
#define INT_TO_SR(INT)
Definition: longrat.h:67