Loading...
Searching...
No Matches
longrat0.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT -
* IO for long rational numbers (Hubert Grassmann)
*/
#include <stdio.h>
#include <string.h>
#include "misc/auxiliary.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
VAR omBin rnumber_bin = omGetSpecBin(sizeof(snumber)); // TODO: move this into coeffs-struct (for Q)?!
#define SR_HDL(A) ((long)(A))
//#define SR_INT 1 // already in longrat.h
//#define INT_TO_SR(INT) ((number) (((long)INT << 2) + SR_INT))
#define SR_TO_INT(SR) (((long)SR) >> 2)
/*2
* extracts the number a from s, returns the rest
*/
const char * nlRead (const char *s, number *a, const coeffs r)
{
if (*s<'0' || *s>'9')
{
*a = INT_TO_SR(1); /* nlInit(1) */
return s;
}
*a=(number)ALLOC_RNUMBER();
{
(*a)->s = 3;
#if defined(LDEBUG)
(*a)->debug=123456;
#endif
mpz_ptr z=(*a)->z;
mpz_ptr n=(*a)->n;
mpz_init(z);
s = nEatLong((char *)s, z);
if (*s == '/')
{
mpz_init(n);
(*a)->s = 0;
s++;
s = nEatLong((char *)s, n);
if (mpz_cmp_si(n,0L)==0)
{
WerrorS(nDivBy0);
mpz_clear(n);
(*a)->s = 3;
}
else if (mpz_cmp_si(n,1L)==0)
{
mpz_clear(n);
(*a)->s=3;
}
}
if (mpz_cmp_si(z,0L)==0)
{
mpz_clear(z);
FREE_RNUMBER(*a);
*a=INT_TO_SR(0);
}
else if ((*a)->s==3)
{
number nlShort3_noinline(number x);
*a=nlShort3_noinline(*a);
}
else
{
number aa=*a;
nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
*a=aa;
}
}
return s;
}
/*2
* write a rational number
*/
void nlWrite (number a, const coeffs)
{
char *s,*z;
if (SR_HDL(a) & SR_INT)
{
StringAppend("%ld",SR_TO_INT(a));
}
else if (a==NULL)
{
StringAppendS("o");
}
else
{
int l=mpz_sizeinbase(a->z,10);
if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
l+=2;
s=(char*)omAlloc(l);
z=mpz_get_str(s,10,a->z);
StringAppendS(z);
if (a->s!=3)
{
StringAppendS("/");
z=mpz_get_str(s,10,a->n);
StringAppendS(z);
}
omFreeSize((void *)s,l);
}
}
#if 0
void nlDebugWrite (number a)
{
char *s,*z;
if (SR_HDL(a) & SR_INT)
{
Print("%ld",SR_TO_INT(a));
}
else if (a==NULL)
{
PrintS("o");
}
else
{
int l=mpz_sizeinbase(a->z,10);
if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
l+=2;
s=(char*)omAlloc(l);
z=mpz_get_str(s,10,a->z);
PrintS(z);
if (a->s!=3)
{
PrintS("/");
z=mpz_get_str(s,10,a->n);
PrintS(z);
}
omFreeSize((void *)s,l);
}
}
#endif
auxiliary.h
All the auxiliary stuff.
si_max
static int si_max(const int a, const int b)
Definition auxiliary.h:125
l
int l
Definition cfEzgcd.cc:100
x
Variable x
Definition cfModGcd.cc:4090
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
ALLOC_RNUMBER
#define ALLOC_RNUMBER()
Definition coeffs.h:94
FREE_RNUMBER
#define FREE_RNUMBER(x)
Definition coeffs.h:93
rnumber_bin
EXTERN_VAR omBin rnumber_bin
Definition coeffs.h:91
Print
#define Print
Definition emacs.cc:80
StringAppend
#define StringAppend
Definition emacs.cc:79
s
const CanonicalForm int s
Definition facAbsFact.cc:51
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
VAR
#define VAR
Definition globaldefs.h:5
nlRead
const char * nlRead(const char *s, number *a, const coeffs r)
Definition longrat0.cc:31
nlWrite
void nlWrite(number a, const coeffs)
Definition longrat0.cc:90
SR_HDL
#define SR_HDL(A)
Definition longrat0.cc:22
SR_TO_INT
#define SR_TO_INT(SR)
Definition longrat0.cc:25
nlShort3_noinline
number nlShort3_noinline(number x)
Definition longrat.cc:159
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1481
longrat.h
SR_INT
#define SR_INT
Definition longrat.h:67
INT_TO_SR
#define INT_TO_SR(INT)
Definition longrat.h:68
snumber
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition longrat.h:49
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
nEatLong
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition numbers.cc:713
numbers.h
nDivBy0
const char *const nDivBy0
Definition numbers.h:90
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omGetSpecBin
#define omGetSpecBin(size)
Definition omBin.h:11
NULL
#define NULL
Definition omList.c:12
omBin
omBin_t * omBin
Definition omStructs.h:12
StringAppendS
void StringAppendS(const char *st)
Definition reporter.cc:107
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
reporter.h