Data Structures | Macros | Functions | Variables
shortfl.cc File Reference
#include <misc/auxiliary.h>
#include <misc/mylimits.h>
#include <reporter/reporter.h>
#include "numbers.h"
#include "coeffs.h"
#include "mpr_complex.h"
#include "shortfl.h"
#include "longrat.h"
#include <string.h>
#include <math.h>

Go to the source code of this file.

Data Structures

union  nf
 

Macros

#define SR_HDL(A)   ((long)(A))
 
#define IS_INT(A)   ((A)->s==3)
 
#define IS_IMM(A)   (SR_HDL(A) & SR_INT)
 
#define GET_NOM(A)   ((A)->z)
 
#define GET_DENOM(A)   ((A)->n)
 

Functions

BOOLEAN nrGreaterZero (number k, const coeffs r)
 
number nrMult (number a, number b, const coeffs r)
 
number nrInit (long i, const coeffs r)
 
long nrInt (number &n, const coeffs r)
 
number nrAdd (number a, number b, const coeffs r)
 
number nrSub (number a, number b, const coeffs r)
 
void nrPower (number a, int i, number *result, const coeffs r)
 
BOOLEAN nrIsZero (number a, const coeffs r)
 
BOOLEAN nrIsOne (number a, const coeffs r)
 
BOOLEAN nrIsMOne (number a, const coeffs r)
 
number nrDiv (number a, number b, const coeffs r)
 
number nrNeg (number c, const coeffs r)
 
number nrInvers (number c, const coeffs r)
 
BOOLEAN nrGreater (number a, number b, const coeffs r)
 
BOOLEAN nrEqual (number a, number b, const coeffs r)
 
void nrWrite (number a, const coeffs r)
 
const char * nrRead (const char *s, number *a, const coeffs r)
 
BOOLEAN nrDBTest (number a, const coeffs r, const char *f, const int l)
 
nMapFunc nrSetMap (const coeffs src, const coeffs dst)
 Get a mapping function from src into the domain of this type: n_R. More...
 
number nrMapQ (number from, const coeffs r, const coeffs aRing)
 
float nrFloat (number n)
 Converts a n_R number into a float. Needed by Maps. More...
 
void nrCoeffWrite (const coeffs r, BOOLEAN)
 
int nrSize (number n, const coeffs)
 
BOOLEAN nrDBTest (number a, const char *f, const int l, const coeffs r)
 
static number nrMapP (number from, const coeffs aRing, const coeffs r)
 
static number nrMapLongR (number from, const coeffs aRing, const coeffs r)
 
static number nrMapC (number from, const coeffs aRing, const coeffs r)
 
number nrMapZ (number from, const coeffs aRing, const coeffs r)
 
static char * nrCoeffString (const coeffs r)
 
BOOLEAN nrInitChar (coeffs n, void *p)
 Initialize r. More...
 

Variables

static const n_coeffType ID = n_R
 Our Type! More...
 
static const float nrEps = 1.0e-3
 

Macro Definition Documentation

#define GET_DENOM (   A)    ((A)->n)
#define GET_NOM (   A)    ((A)->z)
#define IS_IMM (   A)    (SR_HDL(A) & SR_INT)
#define IS_INT (   A)    ((A)->s==3)
#define SR_HDL (   A)    ((long)(A))

Function Documentation

number nrAdd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 144 of file shortfl.cc.

145 {
146  assume( getCoeffType(r) == ID );
147 
148  float x = nf(a).F();
149  float y = nf(b).F();
150  float f = x + y;
151  if (x > 0.0)
152  {
153  if (y < 0.0)
154  {
155  x = f / (x - y);
156  if (x < 0.0)
157  x = -x;
158  if (x < nrEps)
159  f = 0.0;
160  }
161  }
162  else
163  {
164  if (y > 0.0)
165  {
166  x = f / (y - x);
167  if (x < 0.0)
168  x = -x;
169  if (x < nrEps)
170  f = 0.0;
171  }
172  }
173  return nf(f).N();
174 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static const float nrEps
Definition: shortfl.cc:60
FILE * f
Definition: checklibs.c:7
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
Variable x
Definition: cfModGcd.cc:4023
number N() const
Definition: gnumpfl.cc:67
const poly b
Definition: syzextra.cc:213
static char* nrCoeffString ( const coeffs  r)
static

Definition at line 728 of file shortfl.cc.

729 {
730  return omStrDup("real");
731 }
#define omStrDup(s)
Definition: omAllocDecl.h:263
void nrCoeffWrite ( const coeffs  r,
BOOLEAN   
)

Definition at line 84 of file shortfl.cc.

85 {
86  assume( getCoeffType(r) == ID );
87  PrintS("// characteristic : 0 (real)\n"); /* R */
88 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
#define assume(x)
Definition: mod2.h:405
void PrintS(const char *s)
Definition: reporter.cc:294
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
BOOLEAN nrDBTest ( number  a,
const coeffs  r,
const char *  f,
const int  l 
)
BOOLEAN nrDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 415 of file shortfl.cc.

416 {
417  assume( getCoeffType(r) == ID );
418 
419  return TRUE;
420 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
#define TRUE
Definition: auxiliary.h:144
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number nrDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 233 of file shortfl.cc.

234 {
235  assume( getCoeffType(r) == ID );
236 
237  float n = nf(b).F();
238  if (n == 0.0)
239  {
240  WerrorS(nDivBy0);
241  return nf((float)0.0).N();
242  }
243  else
244  return nf(nf(a).F() / n).N();
245 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void WerrorS(const char *s)
Definition: feFopen.cc:23
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
const char *const nDivBy0
Definition: numbers.h:83
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
number N() const
Definition: gnumpfl.cc:67
const poly b
Definition: syzextra.cc:213
BOOLEAN nrEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 274 of file shortfl.cc.

275 {
276  assume( getCoeffType(r) == ID );
277 
278  number x = nrSub(a,b,r);
279  return nf(x).F() == nf((float)0.0).F();
280 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:176
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
Variable x
Definition: cfModGcd.cc:4023
const poly b
Definition: syzextra.cc:213
float nrFloat ( number  n)

Converts a n_R number into a float. Needed by Maps.

Definition at line 78 of file shortfl.cc.

79 {
80  return nf(n).F();
81 }
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
Definition: gnumpfl.cc:60
float F() const
Definition: gnumpfl.cc:66
BOOLEAN nrGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 267 of file shortfl.cc.

268 {
269  assume( getCoeffType(r) == ID );
270 
271  return nf(a).F() > nf(b).F();
272 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
const poly b
Definition: syzextra.cc:213
BOOLEAN nrGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 91 of file shortfl.cc.

92 {
93  assume( getCoeffType(r) == ID );
94 
95  return nf(k).F() >= 0.0;
96 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
int k
Definition: cfEzgcd.cc:93
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
number nrInit ( long  i,
const coeffs  r 
)

Definition at line 108 of file shortfl.cc.

109 {
110  assume( getCoeffType(r) == ID );
111 
112  float f = (float)i;
113  return nf(nf(f).F()).N();
114 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
BOOLEAN nrInitChar ( coeffs  n,
void *  p 
)

Initialize r.

Definition at line 733 of file shortfl.cc.

734 {
735  assume( getCoeffType(n) == ID );
736 
737  assume( p == NULL );
738 
739  n->is_field=TRUE;
740  n->is_domain=TRUE;
741  n->rep=n_rep_float;
742 
743  //n->cfKillChar = ndKillChar; /* dummy */
744  n->ch = 0;
745  n->cfCoeffString = nrCoeffString;
746 
747  n->cfInit = nrInit;
748  n->cfInt = nrInt;
749  n->cfAdd = nrAdd;
750  n->cfSub = nrSub;
751  n->cfMult = nrMult;
752  n->cfDiv = nrDiv;
753  n->cfExactDiv= nrDiv;
754  n->cfInpNeg = nrNeg;
755  n->cfInvers= nrInvers;
756  //n->cfCopy = ndCopy;
757  n->cfGreater = nrGreater;
758  n->cfEqual = nrEqual;
759  n->cfIsZero = nrIsZero;
760  n->cfIsOne = nrIsOne;
761  n->cfIsMOne = nrIsMOne;
762  n->cfGreaterZero = nrGreaterZero;
763  n->cfWriteLong = nrWrite;
764  n->cfRead = nrRead;
765  //n->cfPower = nrPower;
766  n->cfSetMap = nrSetMap;
767  n->cfCoeffWrite = nrCoeffWrite;
768 
769  /* nName= ndName; */
770  /*nSize = ndSize;*/
771 #ifdef LDEBUG
772  //n->cfDBTest=ndDBTest; // not yet implemented: nrDBTest;
773 #endif
774 
775  //n->nCoeffIsEqual = ndCoeffIsEqual;
776 
777  n->float_len = SHORT_REAL_LENGTH;
778  n->float_len2 = SHORT_REAL_LENGTH;
779 
780  // TODO: Any variables?
781  return FALSE;
782 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
BOOLEAN nrGreaterZero(number k, const coeffs r)
Definition: shortfl.cc:91
number nrMult(number a, number b, const coeffs r)
Definition: shortfl.cc:98
BOOLEAN nrEqual(number a, number b, const coeffs r)
Definition: shortfl.cc:274
#define SHORT_REAL_LENGTH
Definition: numbers.h:54
#define FALSE
Definition: auxiliary.h:140
number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:176
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:144
number nrDiv(number a, number b, const coeffs r)
Definition: shortfl.cc:233
const char * nrRead(const char *s, number *a, const coeffs r)
Definition: shortfl.cc:344
number nrAdd(number a, number b, const coeffs r)
Definition: shortfl.cc:144
void nrWrite(number a, const coeffs r)
Definition: shortfl.cc:282
#define assume(x)
Definition: mod2.h:405
BOOLEAN nrIsMOne(number a, const coeffs r)
Definition: shortfl.cc:224
number nrInvers(number c, const coeffs r)
Definition: shortfl.cc:247
nMapFunc nrSetMap(const coeffs src, const coeffs dst)
Get a mapping function from src into the domain of this type: n_R.
Definition: shortfl.cc:697
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number nrInit(long i, const coeffs r)
Definition: shortfl.cc:108
void nrCoeffWrite(const coeffs r, BOOLEAN)
Definition: shortfl.cc:84
#define NULL
Definition: omList.c:10
BOOLEAN nrIsOne(number a, const coeffs r)
Definition: shortfl.cc:215
static char * nrCoeffString(const coeffs r)
Definition: shortfl.cc:728
number nrNeg(number c, const coeffs r)
Definition: shortfl.cc:260
long nrInt(number &n, const coeffs r)
Definition: shortfl.cc:119
BOOLEAN nrIsZero(number a, const coeffs r)
Definition: shortfl.cc:208
BOOLEAN nrGreater(number a, number b, const coeffs r)
Definition: shortfl.cc:267
(float), see shortfl.h
Definition: coeffs.h:115
long nrInt ( number &  n,
const coeffs  r 
)

Definition at line 119 of file shortfl.cc.

120 {
121  assume( getCoeffType(r) == ID );
122 
123  long i;
124  float f = nf(n).F();
125  if (((float)(-MAX_INT_VAL-1) <= f) || ((float)MAX_INT_VAL >= f))
126  i = (long)f;
127  else
128  i = 0;
129  return i;
130 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
const int MAX_INT_VAL
Definition: mylimits.h:12
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
number nrInvers ( number  c,
const coeffs  r 
)

Definition at line 247 of file shortfl.cc.

248 {
249  assume( getCoeffType(r) == ID );
250 
251  float n = nf(c).F();
252  if (n == 0.0)
253  {
254  WerrorS(nDivBy0);
255  return nf((float)0.0).N();
256  }
257  return nf(1.0 / n).N();
258 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void WerrorS(const char *s)
Definition: feFopen.cc:23
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
const char *const nDivBy0
Definition: numbers.h:83
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
number N() const
Definition: gnumpfl.cc:67
BOOLEAN nrIsMOne ( number  a,
const coeffs  r 
)

Definition at line 224 of file shortfl.cc.

225 {
226  assume( getCoeffType(r) == ID );
227 
228  float aa=nf(a).F()+1.0;
229  if (aa<0.0) aa=-aa;
230  return (aa<nrEps);
231 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static const float nrEps
Definition: shortfl.cc:60
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
BOOLEAN nrIsOne ( number  a,
const coeffs  r 
)

Definition at line 215 of file shortfl.cc.

216 {
217  assume( getCoeffType(r) == ID );
218 
219  float aa=nf(a).F()-1.0;
220  if (aa<0.0) aa=-aa;
221  return (aa<nrEps);
222 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static const float nrEps
Definition: shortfl.cc:60
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
BOOLEAN nrIsZero ( number  a,
const coeffs  r 
)

Definition at line 208 of file shortfl.cc.

209 {
210  assume( getCoeffType(r) == ID );
211 
212  return (0.0 == nf(a).F());
213 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
static number nrMapC ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 442 of file shortfl.cc.

443 {
444  assume( getCoeffType(r) == ID );
445  assume( getCoeffType(aRing) == n_long_C );
446 
447  gmp_float h = ((gmp_complex*)from)->real();
448  float t =(float)mpf_get_d((mpf_srcptr)&h);
449  return nf(t).N();
450 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
gmp_complex numbers based on
Definition: mpr_complex.h:178
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
complex floating point (GMP) numbers
Definition: coeffs.h:41
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
static Poly * h
Definition: janet.cc:978
static number nrMapLongR ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 433 of file shortfl.cc.

434 {
435  assume( getCoeffType(r) == ID );
436  assume( getCoeffType(aRing) == n_long_R );
437 
438  float t =(float)mpf_get_d((mpf_srcptr)from);
439  return nf(t).N();
440 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
real floating point (GMP) numbers
Definition: coeffs.h:34
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
static number nrMapP ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 423 of file shortfl.cc.

424 {
425  assume( getCoeffType(r) == ID );
426  assume( getCoeffType(aRing) == n_Zp );
427 
428  int i = (int)((long)from);
429  float f = (float)i;
430  return nf(f).N();
431 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
{p < 2^31}
Definition: coeffs.h:30
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
number nrMapQ ( number  from,
const coeffs  r,
const coeffs  aRing 
)

Definition at line 453 of file shortfl.cc.

454 {
455 /* in longrat.h
456 #define SR_INT 1
457 #define mpz_size1(A) (ABS((A)->_mp_size))
458 */
459 #define SR_HDL(A) ((long)(A))
460 #define IS_INT(A) ((A)->s==3)
461 #define IS_IMM(A) (SR_HDL(A) & SR_INT)
462 #define GET_NOM(A) ((A)->z)
463 #define GET_DENOM(A) ((A)->n)
464 
465  assume( getCoeffType(r) == ID );
466  assume( aRing->rep == n_rep_gap_rat );
467 
468  mpz_ptr z;
469  mpz_ptr zz=NULL;
470  if (IS_IMM(from))
471  {
472  zz=(mpz_ptr)omAlloc(sizeof(mpz_t));
473  mpz_init_set_si(zz,SR_TO_INT(from));
474  z=zz;
475  }
476  else
477  {
478  /* read out the enumerator */
479  z=GET_NOM(from);
480  }
481 
482  int i = mpz_size1(z);
483  mpf_t e;
484  mpf_init(e);
485  mpf_set_z(e,z);
486  int sign= mpf_sgn(e);
487  mpf_abs (e, e);
488 
489  if (zz!=NULL)
490  {
491  mpz_clear(zz);
492  omFreeSize(zz,sizeof(mpz_t));
493  }
494  /* if number was an integer, we are done*/
495  if(IS_IMM(from)|| IS_INT(from))
496  {
497  if(i>4)
498  {
499  WerrorS("float overflow");
500  return nf(0.0).N();
501  }
502  double basis;
503  signed long int exp;
504  basis = mpf_get_d_2exp(&exp, e);
505  float f= sign*ldexp(basis,exp);
506  mpf_clear(e);
507  return nf(f).N();
508  }
509 
510  /* else read out the denominator */
511  mpz_ptr n = GET_DENOM(from);
512  int j = mpz_size1(n);
513  if(j-i>4)
514  {
515  WerrorS("float overflow");
516  mpf_clear(e);
517  return nf(0.0).N();
518  }
519  mpf_t d;
520  mpf_init(d);
521  mpf_set_z(d,n);
522 
523  /* and compute the quotient */
524  mpf_t q;
525  mpf_init(q);
526  mpf_div(q,e,d);
527 
528  double basis;
529  signed long int exp;
530  basis = mpf_get_d_2exp(&exp, q);
531  float f = sign*ldexp(basis,exp);
532  mpf_clear(e);
533  mpf_clear(d);
534  mpf_clear(q);
535  return nf(f).N();
536 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
#define GET_NOM(A)
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void WerrorS(const char *s)
Definition: feFopen.cc:23
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: gnumpfl.cc:60
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
#define SR_TO_INT(SR)
Definition: longrat.h:67
(number), see longrat.h
Definition: coeffs.h:110
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:10
#define IS_INT(A)
number N() const
Definition: gnumpfl.cc:67
p exp[i]
Definition: DebugPrint.cc:39
#define GET_DENOM(A)
#define IS_IMM(A)
int sign(const CanonicalForm &a)
number nrMapZ ( number  from,
const coeffs  aRing,
const coeffs  r 
)

Definition at line 538 of file shortfl.cc.

539 {
540  assume( getCoeffType(r) == ID );
541  assume( aRing->rep == n_rep_gap_gmp );
542 
543  mpz_ptr z;
544  mpz_ptr zz=NULL;
545  if (IS_IMM(from))
546  {
547  zz=(mpz_ptr)omAlloc(sizeof(mpz_t));
548  mpz_init_set_si(zz,SR_TO_INT(from));
549  z=zz;
550  }
551  else
552  {
553  /* read out the enumerator */
554  z=(mpz_ptr)from;
555  }
556 
557  int i = mpz_size1(z);
558  mpf_t e;
559  mpf_init(e);
560  mpf_set_z(e,z);
561  int sign= mpf_sgn(e);
562  mpf_abs (e, e);
563 
564  if (zz!=NULL)
565  {
566  mpz_clear(zz);
567  omFreeSize(zz,sizeof(mpz_t));
568  }
569  if(i>4)
570  {
571  WerrorS("float overflow");
572  return nf(0.0).N();
573  }
574  double basis;
575  signed long int exp;
576  basis = mpf_get_d_2exp(&exp, e);
577  float f= sign*ldexp(basis,exp);
578  mpf_clear(e);
579  return nf(f).N();
580 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
(), see rinteger.h, new impl.
Definition: coeffs.h:111
void WerrorS(const char *s)
Definition: feFopen.cc:23
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:10
number N() const
Definition: gnumpfl.cc:67
p exp[i]
Definition: DebugPrint.cc:39
#define IS_IMM(A)
int sign(const CanonicalForm &a)
number nrMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 98 of file shortfl.cc.

99 {
100  assume( getCoeffType(r) == ID );
101 
102  return nf(nf(a).F() * nf(b).F()).N();
103 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
const poly b
Definition: syzextra.cc:213
number nrNeg ( number  c,
const coeffs  r 
)

Definition at line 260 of file shortfl.cc.

261 {
262  assume( getCoeffType(r) == ID );
263 
264  return nf(-nf(c).F()).N();
265 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
void nrPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)
const char * nrRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 344 of file shortfl.cc.

345 {
346 
347  assume( getCoeffType(r) == ID );
348 
349  static const char *nIllegalChar="illegal character in number";
350 
351  const char *t;
352  const char *start=s;
353  float z1,z2;
354  float n=1.0;
355 
356  s = nrEatr(s, &z1);
357  if (*s == '/')
358  {
359  if (s==start) { WerrorS(nIllegalChar);return s; }
360  s++;
361  s = nrEatr(s, &z2);
362  if (z2==0.0)
363  WerrorS(nDivBy0);
364  else
365  z1 /= z2;
366  }
367  else if (*s =='.')
368  {
369  if (s==start) { WerrorS(nIllegalChar);return s; }
370  s++;
371  t = s;
372  while (*t >= '0' && *t <= '9')
373  {
374  t++;
375  n *= 10.0;
376  }
377  s = nrEatr(s, &z2);
378  z1 = (z1*n + z2) / n;
379  if (*s=='e')
380  {
381  int e=0; /* exponent */
382  int si=1;/* sign of exponent */
383  s++;
384  if (*s=='+') s++;
385  else if (*s=='-') {s++; si=-1; }
386  while (*s >= '0' && *s <= '9')
387  {
388  e=e*10+(*s)-'0';
389  s++;
390  }
391  if (si==1)
392  {
393  while (e>0) {z1*=10.0; e--; }
394  }
395  else
396  {
397  while (e>0) {z1/=10.0; e--; }
398  }
399  }
400  }
401  *a = nf(z1).N();
402  return s;
403 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void WerrorS(const char *s)
Definition: feFopen.cc:23
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
const char *const nDivBy0
Definition: numbers.h:83
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number N() const
Definition: gnumpfl.cc:67
nMapFunc nrSetMap ( const coeffs  src,
const coeffs  dst 
)

Get a mapping function from src into the domain of this type: n_R.

Definition at line 697 of file shortfl.cc.

698 {
699  assume( getCoeffType(dst) == ID );
700 
701  if (src->rep==n_rep_gap_rat) /*Q, Z */
702  {
703  return nrMapQ;
704  }
705  if (src->rep==n_rep_gap_gmp) /*Q, Z */
706  {
707  return nrMapZ;
708  }
709  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
710  {
711  return nrMapLongR;
712  }
713  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
714  {
715  return ndCopyMap;
716  }
717  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
718  {
719  return nrMapP;
720  }
721  if ((src->rep==n_rep_gmp_complex) && nCoeff_is_long_C(src))
722  {
723  return nrMapC;
724  }
725  return NULL;
726 }
static number nrMapP(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:423
number nrMapZ(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:538
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
static number nrMapLongR(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:433
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:818
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:239
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:892
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:834
(), see rinteger.h, new impl.
Definition: coeffs.h:111
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:895
static number nrMapC(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:442
#define assume(x)
Definition: mod2.h:405
(gmp_complex), see gnumpc.h
Definition: coeffs.h:117
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number nrMapQ(number from, const coeffs r, const coeffs aRing)
Definition: shortfl.cc:453
(number), see longrat.h
Definition: coeffs.h:110
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:116
(int), see modulop.h
Definition: coeffs.h:109
(float), see shortfl.h
Definition: coeffs.h:115
int nrSize ( number  n,
const coeffs   
)

Definition at line 132 of file shortfl.cc.

133 {
134  float f = nf(n).F();
135  int i = (int)f;
136  /* basically return the largest integer in n;
137  only if this happens to be zero although n != 0,
138  return 1;
139  (this code ensures that zero has the size zero) */
140  if ((f != 0.0) & (i == 0)) i = 1;
141  return i;
142 }
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
Definition: gnumpfl.cc:60
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
float F() const
Definition: gnumpfl.cc:66
number nrSub ( number  a,
number  b,
const coeffs  r 
)

Definition at line 176 of file shortfl.cc.

177 {
178  assume( getCoeffType(r) == ID );
179 
180  float x = nf(a).F();
181  float y = nf(b).F();
182  float f = x - y;
183  if (x > 0.0)
184  {
185  if (y > 0.0)
186  {
187  x = f / (x + y);
188  if (x < 0.0)
189  x = -x;
190  if (x < nrEps)
191  f = 0.0;
192  }
193  }
194  else
195  {
196  if (y < 0.0)
197  {
198  x = f / (x + y);
199  if (x < 0.0)
200  x = -x;
201  if (x < nrEps)
202  f = 0.0;
203  }
204  }
205  return nf(f).N();
206 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
static const float nrEps
Definition: shortfl.cc:60
FILE * f
Definition: checklibs.c:7
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
float F() const
Definition: gnumpfl.cc:66
Variable x
Definition: cfModGcd.cc:4023
number N() const
Definition: gnumpfl.cc:67
const poly b
Definition: syzextra.cc:213
void nrWrite ( number  a,
const coeffs  r 
)

Definition at line 282 of file shortfl.cc.

283 {
284  assume( getCoeffType(r) == ID );
285 
286  char ch[11];
287  int n = sprintf(ch,"%9.3e", nf(a).F());
288  if (ch[0] == '-')
289  {
290  char* chbr = new char[n+3];
291  memcpy(&chbr[2],&ch[1],n-1);
292  chbr[0] = '-';
293  chbr[1] = '(';
294  chbr[n+1] = ')';
295  chbr[n+2] = '\0';
296  StringAppendS(chbr);
297  delete chbr;
298  }
299  else
300  StringAppend("(%s)",ch);
301 }
static const n_coeffType ID
Our Type!
Definition: shortfl.cc:27
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
Definition: gnumpfl.cc:60
#define assume(x)
Definition: mod2.h:405
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422

Variable Documentation

const n_coeffType ID = n_R
static

Our Type!

Definition at line 27 of file shortfl.cc.

const float nrEps = 1.0e-3
static

Definition at line 60 of file shortfl.cc.