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

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

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

Variables

static const SI_FLOAT nrEps = 1.0e-3
 

Macro Definition Documentation

◆ GET_DENOM

#define GET_DENOM (   A)    ((A)->n)

◆ GET_NOM

#define GET_NOM (   A)    ((A)->z)

◆ IS_IMM

#define IS_IMM (   A)    (SR_HDL(A) & SR_INT)

◆ IS_INT

#define IS_INT (   A)    ((A)->s==3)

◆ SR_HDL

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

Function Documentation

◆ nrAdd()

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

Definition at line 110 of file shortfl.cc.

111 {
112  assume( getCoeffType(r) == n_R );
113 
114  SI_FLOAT x = nf(a).F();
115  SI_FLOAT y = nf(b).F();
116  SI_FLOAT f = x + y;
117  if (x > 0.0)
118  {
119  if (y < 0.0)
120  {
121  x = f / (x - y);
122  if (x < 0.0)
123  x = -x;
124  if (x < nrEps)
125  f = 0.0;
126  }
127  }
128  else
129  {
130  if (y > 0.0)
131  {
132  x = f / (y - x);
133  if (x < 0.0)
134  x = -x;
135  if (x < nrEps)
136  f = 0.0;
137  }
138  }
139  return nf(f).N();
140 }
#define SI_FLOAT
Definition: shortfl.h:15
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
Variable x
Definition: cfModGcd.cc:4023
static const SI_FLOAT nrEps
Definition: shortfl.cc:38
number N() const
Definition: gnumpfl.cc:33

◆ nrCoeffName()

static char* nrCoeffName ( const coeffs  r)
static

Definition at line 704 of file shortfl.cc.

705 {
706  return (char*)"Float()";
707 }

◆ nrCoeffString()

static char* nrCoeffString ( const coeffs  r)
static

Definition at line 699 of file shortfl.cc.

700 {
701  return omStrDup("Float()");
702 }
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ nrCoeffWrite()

static void nrCoeffWrite ( const coeffs  r,
BOOLEAN   
)
static

Definition at line 62 of file shortfl.cc.

63 {
64  assume( getCoeffType(r) == n_R );
65  PrintS("Float()"); /* R */
66 }
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
void PrintS(const char *s)
Definition: reporter.cc:284
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421

◆ nrDBTest() [1/2]

static BOOLEAN nrDBTest ( number  a,
const coeffs  r,
const char *  f,
const int  l 
)
static

◆ nrDBTest() [2/2]

static BOOLEAN nrDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)
static

Definition at line 386 of file shortfl.cc.

387 {
388  assume( getCoeffType(r) == n_R );
389 
390  return TRUE;
391 }
#define TRUE
Definition: auxiliary.h:100
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421

◆ nrDiv()

static number nrDiv ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 199 of file shortfl.cc.

200 {
201  assume( getCoeffType(r) == n_R );
202 
203  SI_FLOAT n = nf(b).F();
204  if (n == 0.0)
205  {
206  WerrorS(nDivBy0);
207  return nf((SI_FLOAT)0.0).N();
208  }
209  else
210  return nf(nf(a).F() / n).N();
211 }
#define SI_FLOAT
Definition: shortfl.h:15
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
#define assume(x)
Definition: mod2.h:390
const char *const nDivBy0
Definition: numbers.h:88
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
number N() const
Definition: gnumpfl.cc:33

◆ nrEqual()

static BOOLEAN nrEqual ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 240 of file shortfl.cc.

241 {
242  assume( getCoeffType(r) == n_R );
243 
244  number x = nrSub(a,b,r);
245  return nf(x).F() == nf((SI_FLOAT)0.0).F();
246 }
#define SI_FLOAT
Definition: shortfl.h:15
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
static number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:142
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
Variable x
Definition: cfModGcd.cc:4023

◆ nrFloat()

SI_FLOAT nrFloat ( number  n)

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

Definition at line 56 of file shortfl.cc.

57 {
58  return nf(n).F();
59 }
Definition: gnumpfl.cc:26
SI_FLOAT F() const
Definition: gnumpfl.cc:32

◆ nrGreater()

static BOOLEAN nrGreater ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 233 of file shortfl.cc.

234 {
235  assume( getCoeffType(r) == n_R );
236 
237  return nf(a).F() > nf(b).F();
238 }
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32

◆ nrGreaterZero()

static BOOLEAN nrGreaterZero ( number  k,
const coeffs  r 
)
static

Definition at line 69 of file shortfl.cc.

70 {
71  assume( getCoeffType(r) == n_R );
72 
73  return nf(k).F() >= 0.0;
74 }
int k
Definition: cfEzgcd.cc:92
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32

◆ nrInit()

static number nrInit ( long  i,
const coeffs  r 
)
static

Definition at line 86 of file shortfl.cc.

87 {
88  assume( getCoeffType(r) == n_R );
89 
90  SI_FLOAT f = (SI_FLOAT)i;
91  return nf(nf(f).F()).N();
92 }
#define SI_FLOAT
Definition: shortfl.h:15
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrInitChar()

BOOLEAN nrInitChar ( coeffs  n,
void *  p 
)

Initialize r.

Definition at line 709 of file shortfl.cc.

710 {
711  assume( getCoeffType(n) == n_R );
712 
713  assume( p == NULL );
714 
715  n->is_field=TRUE;
716  n->is_domain=TRUE;
717  n->rep=n_rep_float;
718 
719  //n->cfKillChar = ndKillChar; /* dummy */
720  n->ch = 0;
721  n->cfCoeffString = nrCoeffString;
722  n->cfCoeffName = nrCoeffName;
723 
724  n->cfInit = nrInit;
725  n->cfInt = nrInt;
726  n->cfAdd = nrAdd;
727  n->cfSub = nrSub;
728  n->cfMult = nrMult;
729  n->cfDiv = nrDiv;
730  n->cfExactDiv= nrDiv;
731  n->cfInpNeg = nrNeg;
732  n->cfInvers= nrInvers;
733  //n->cfCopy = ndCopy;
734  n->cfGreater = nrGreater;
735  n->cfEqual = nrEqual;
736  n->cfIsZero = nrIsZero;
737  n->cfIsOne = nrIsOne;
738  n->cfIsMOne = nrIsMOne;
739  n->cfGreaterZero = nrGreaterZero;
740  n->cfWriteLong = nrWrite;
741  n->cfRead = nrRead;
742  //n->cfPower = nrPower;
743  n->cfSetMap = nrSetMap;
744  n->cfCoeffWrite = nrCoeffWrite;
745 
746  /* nName= ndName; */
747  /*nSize = ndSize;*/
748 #ifdef LDEBUG
749  n->cfDBTest=nrDBTest; // not yet implemented: nrDBTest;
750 #endif
751 
752  //n->nCoeffIsEqual = ndCoeffIsEqual;
753 
754  n->float_len = SHORT_REAL_LENGTH;
755  n->float_len2 = SHORT_REAL_LENGTH;
756 
757  // TODO: Any variables?
758  return FALSE;
759 }
static BOOLEAN nrDBTest(number a, const coeffs r, const char *f, const int l)
static number nrAdd(number a, number b, const coeffs r)
Definition: shortfl.cc:110
static BOOLEAN nrIsOne(number a, const coeffs r)
Definition: shortfl.cc:181
static BOOLEAN nrGreater(number a, number b, const coeffs r)
Definition: shortfl.cc:233
static 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:668
#define SHORT_REAL_LENGTH
Definition: numbers.h:57
static number nrInit(long i, const coeffs r)
Definition: shortfl.cc:86
#define FALSE
Definition: auxiliary.h:96
static number nrNeg(number c, const coeffs r)
Definition: shortfl.cc:226
static BOOLEAN nrIsZero(number a, const coeffs r)
Definition: shortfl.cc:174
#define TRUE
Definition: auxiliary.h:100
static char * nrCoeffName(const coeffs r)
Definition: shortfl.cc:704
single prescision (6,6) real numbers
Definition: coeffs.h:32
static number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:142
#define assume(x)
Definition: mod2.h:390
static BOOLEAN nrIsMOne(number a, const coeffs r)
Definition: shortfl.cc:190
static void nrCoeffWrite(const coeffs r, BOOLEAN)
Definition: shortfl.cc:62
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define NULL
Definition: omList.c:12
static void nrWrite(number a, const coeffs r)
Definition: shortfl.cc:248
static number nrDiv(number a, number b, const coeffs r)
Definition: shortfl.cc:199
static number nrInvers(number c, const coeffs r)
Definition: shortfl.cc:213
static BOOLEAN nrGreaterZero(number k, const coeffs r)
Definition: shortfl.cc:69
static const char * nrRead(const char *s, number *a, const coeffs r)
Definition: shortfl.cc:315
static char * nrCoeffString(const coeffs r)
Definition: shortfl.cc:699
int p
Definition: cfModGcd.cc:4019
static long nrInt(number &n, const coeffs r)
Definition: shortfl.cc:97
static number nrMult(number a, number b, const coeffs r)
Definition: shortfl.cc:76
static BOOLEAN nrEqual(number a, number b, const coeffs r)
Definition: shortfl.cc:240
(float), see shortfl.h
Definition: coeffs.h:116

◆ nrInt()

static long nrInt ( number &  n,
const coeffs  r 
)
static

Definition at line 97 of file shortfl.cc.

98 {
99  assume( getCoeffType(r) == n_R );
100 
101  long i;
102  SI_FLOAT f = nf(n).F();
103  if (((SI_FLOAT)(-MAX_INT_VAL-1) <= f) || ((SI_FLOAT)MAX_INT_VAL >= f))
104  i = (long)f;
105  else
106  i = 0;
107  return i;
108 }
#define SI_FLOAT
Definition: shortfl.h:15
const int MAX_INT_VAL
Definition: mylimits.h:12
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32

◆ nrInvers()

static number nrInvers ( number  c,
const coeffs  r 
)
static

Definition at line 213 of file shortfl.cc.

214 {
215  assume( getCoeffType(r) == n_R );
216 
217  SI_FLOAT n = nf(c).F();
218  if (n == 0.0)
219  {
220  WerrorS(nDivBy0);
221  return nf((SI_FLOAT)0.0).N();
222  }
223  return nf(1.0 / n).N();
224 }
#define SI_FLOAT
Definition: shortfl.h:15
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
const char *const nDivBy0
Definition: numbers.h:88
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
number N() const
Definition: gnumpfl.cc:33

◆ nrIsMOne()

static BOOLEAN nrIsMOne ( number  a,
const coeffs  r 
)
static

Definition at line 190 of file shortfl.cc.

191 {
192  assume( getCoeffType(r) == n_R );
193 
194  SI_FLOAT aa=nf(a).F()+1.0;
195  if (aa<0.0) aa=-aa;
196  return (aa<nrEps);
197 }
#define SI_FLOAT
Definition: shortfl.h:15
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
static const SI_FLOAT nrEps
Definition: shortfl.cc:38

◆ nrIsOne()

static BOOLEAN nrIsOne ( number  a,
const coeffs  r 
)
static

Definition at line 181 of file shortfl.cc.

182 {
183  assume( getCoeffType(r) == n_R );
184 
185  SI_FLOAT aa=nf(a).F()-1.0;
186  if (aa<0.0) aa=-aa;
187  return (aa<nrEps);
188 }
#define SI_FLOAT
Definition: shortfl.h:15
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
static const SI_FLOAT nrEps
Definition: shortfl.cc:38

◆ nrIsZero()

static BOOLEAN nrIsZero ( number  a,
const coeffs  r 
)
static

Definition at line 174 of file shortfl.cc.

175 {
176  assume( getCoeffType(r) == n_R );
177 
178  return (0.0 == nf(a).F());
179 }
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421

◆ nrMapC()

static number nrMapC ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 413 of file shortfl.cc.

414 {
415  assume( getCoeffType(r) == n_R );
416  assume( getCoeffType(aRing) == n_long_C );
417 
418  gmp_float h = ((gmp_complex*)from)->real();
419  SI_FLOAT t =(SI_FLOAT)mpf_get_d((mpf_srcptr)&h);
420  return nf(t).N();
421 }
#define SI_FLOAT
Definition: shortfl.h:15
gmp_complex numbers based on
Definition: mpr_complex.h:178
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
complex floating point (GMP) numbers
Definition: coeffs.h:42
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
STATIC_VAR Poly * h
Definition: janet.cc:971
number N() const
Definition: gnumpfl.cc:33

◆ nrMapLongR()

static number nrMapLongR ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 404 of file shortfl.cc.

405 {
406  assume( getCoeffType(r) == n_R );
407  assume( getCoeffType(aRing) == n_long_R );
408 
409  SI_FLOAT t =(SI_FLOAT)mpf_get_d((mpf_srcptr)from);
410  return nf(t).N();
411 }
#define SI_FLOAT
Definition: shortfl.h:15
real floating point (GMP) numbers
Definition: coeffs.h:34
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrMapP()

static number nrMapP ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 394 of file shortfl.cc.

395 {
396  assume( getCoeffType(r) == n_R );
397  assume( getCoeffType(aRing) == n_Zp );
398 
399  int i = (int)((long)from);
400  SI_FLOAT f = (SI_FLOAT)i;
401  return nf(f).N();
402 }
#define SI_FLOAT
Definition: shortfl.h:15
{p < 2^31}
Definition: coeffs.h:30
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrMapQ()

static number nrMapQ ( number  from,
const coeffs  r,
const coeffs  aRing 
)
static

Definition at line 424 of file shortfl.cc.

425 {
426 /* in longrat.h
427 #define SR_INT 1
428 #define mpz_size1(A) (ABS((A)->_mp_size))
429 */
430 #define SR_HDL(A) ((long)(A))
431 #define IS_INT(A) ((A)->s==3)
432 #define IS_IMM(A) (SR_HDL(A) & SR_INT)
433 #define GET_NOM(A) ((A)->z)
434 #define GET_DENOM(A) ((A)->n)
435 
436  assume( getCoeffType(r) == n_R );
437  assume( aRing->rep == n_rep_gap_rat );
438 
439  mpz_ptr z;
440  mpz_ptr zz=NULL;
441  if (IS_IMM(from))
442  {
443  zz=(mpz_ptr)omAlloc(sizeof(mpz_t));
444  mpz_init_set_si(zz,SR_TO_INT(from));
445  z=zz;
446  }
447  else
448  {
449  /* read out the enumerator */
450  z=GET_NOM(from);
451  }
452 
453  int i = mpz_size1(z);
454  mpf_t e;
455  mpf_init(e);
456  mpf_set_z(e,z);
457  int sign= mpf_sgn(e);
458  mpf_abs (e, e);
459 
460  if (zz!=NULL)
461  {
462  mpz_clear(zz);
463  omFreeSize(zz,sizeof(mpz_t));
464  }
465  /* if number was an integer, we are done*/
466  if(IS_IMM(from)|| IS_INT(from))
467  {
468  if(i>4)
469  {
470  WerrorS("SI_FLOAT overflow");
471  return nf(0.0).N();
472  }
473  double basis;
474  signed long int exp;
475  basis = mpf_get_d_2exp(&exp, e);
476  SI_FLOAT f= sign*ldexp(basis,exp);
477  mpf_clear(e);
478  return nf(f).N();
479  }
480 
481  /* else read out the denominator */
482  mpz_ptr n = GET_DENOM(from);
483  int j = mpz_size1(n);
484  if(j-i>4)
485  {
486  WerrorS("SI_FLOAT overflow");
487  mpf_clear(e);
488  return nf(0.0).N();
489  }
490  mpf_t d;
491  mpf_init(d);
492  mpf_set_z(d,n);
493 
494  /* and compute the quotient */
495  mpf_t q;
496  mpf_init(q);
497  mpf_div(q,e,d);
498 
499  double basis;
500  signed long int exp;
501  basis = mpf_get_d_2exp(&exp, q);
502  SI_FLOAT f = sign*ldexp(basis,exp);
503  mpf_clear(e);
504  mpf_clear(d);
505  mpf_clear(q);
506  return nf(f).N();
507 }
#define SI_FLOAT
Definition: shortfl.h:15
int j
Definition: facHensel.cc:105
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
#define GET_NOM(A)
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define SR_TO_INT(SR)
Definition: longrat.h:68
(number), see longrat.h
Definition: coeffs.h:111
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:12
#define IS_INT(A)
#define GET_DENOM(A)
number N() const
Definition: gnumpfl.cc:33
static int sign(int x)
Definition: ring.cc:3375
#define IS_IMM(A)

◆ nrMapZ()

static number nrMapZ ( number  from,
const coeffs  aRing,
const coeffs  r 
)
static

Definition at line 509 of file shortfl.cc.

510 {
511  assume( getCoeffType(r) == n_R );
512  assume( aRing->rep == n_rep_gap_gmp );
513 
514  mpz_ptr z;
515  mpz_ptr zz=NULL;
516  if (IS_IMM(from))
517  {
518  zz=(mpz_ptr)omAlloc(sizeof(mpz_t));
519  mpz_init_set_si(zz,SR_TO_INT(from));
520  z=zz;
521  }
522  else
523  {
524  /* read out the enumerator */
525  z=(mpz_ptr)from;
526  }
527 
528  int i = mpz_size1(z);
529  mpf_t e;
530  mpf_init(e);
531  mpf_set_z(e,z);
532  int sign= mpf_sgn(e);
533  mpf_abs (e, e);
534 
535  if (zz!=NULL)
536  {
537  mpz_clear(zz);
538  omFreeSize(zz,sizeof(mpz_t));
539  }
540  if(i>4)
541  {
542  WerrorS("float overflow");
543  return nf(0.0).N();
544  }
545  double basis;
546  signed long int exp;
547  basis = mpf_get_d_2exp(&exp, e);
548  SI_FLOAT f= sign*ldexp(basis,exp);
549  mpf_clear(e);
550  return nf(f).N();
551 }
#define SI_FLOAT
Definition: shortfl.h:15
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
(), see rinteger.h, new impl.
Definition: coeffs.h:112
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define omAlloc(size)
Definition: omAllocDecl.h:210
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define SR_TO_INT(SR)
Definition: longrat.h:68
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:12
number N() const
Definition: gnumpfl.cc:33
static int sign(int x)
Definition: ring.cc:3375
#define IS_IMM(A)

◆ nrMult()

static number nrMult ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 76 of file shortfl.cc.

77 {
78  assume( getCoeffType(r) == n_R );
79 
80  return nf(nf(a).F() * nf(b).F()).N();
81 }
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrNeg()

static number nrNeg ( number  c,
const coeffs  r 
)
static

Definition at line 226 of file shortfl.cc.

227 {
228  assume( getCoeffType(r) == n_R );
229 
230  return nf(-nf(c).F()).N();
231 }
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrRead()

static const char* nrRead ( const char *  s,
number *  a,
const coeffs  r 
)
static

Definition at line 315 of file shortfl.cc.

316 {
317 
318  assume( getCoeffType(r) == n_R );
319 
320  static const char *nIllegalChar="illegal character in number";
321 
322  const char *t;
323  const char *start=s;
324  SI_FLOAT z1,z2;
325  SI_FLOAT n=1.0;
326 
327  s = nrEatr(s, &z1);
328  if (*s == '/')
329  {
330  if (s==start) { WerrorS(nIllegalChar);return s; }
331  s++;
332  s = nrEatr(s, &z2);
333  if (z2==0.0)
334  WerrorS(nDivBy0);
335  else
336  z1 /= z2;
337  }
338  else if (*s =='.')
339  {
340  if (s==start) { WerrorS(nIllegalChar);return s; }
341  s++;
342  t = s;
343  while (*t >= '0' && *t <= '9')
344  {
345  t++;
346  n *= 10.0;
347  }
348  s = nrEatr(s, &z2);
349  z1 = (z1*n + z2) / n;
350  if (*s=='e')
351  {
352  int e=0; /* exponent */
353  int si=1;/* sign of exponent */
354  s++;
355  if (*s=='+') s++;
356  else if (*s=='-') {s++; si=-1; }
357  while (*s >= '0' && *s <= '9')
358  {
359  e=e*10+(*s)-'0';
360  s++;
361  }
362  if (si==1)
363  {
364  while (e>0) {z1*=10.0; e--; }
365  }
366  else
367  {
368  while (e>0) {z1/=10.0; e--; }
369  }
370  }
371  }
372  *a = nf(z1).N();
373  return s;
374 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define SI_FLOAT
Definition: shortfl.h:15
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
const char *const nDivBy0
Definition: numbers.h:88
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
number N() const
Definition: gnumpfl.cc:33

◆ nrSetMap()

static nMapFunc nrSetMap ( const coeffs  src,
const coeffs  dst 
)
static

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

Definition at line 668 of file shortfl.cc.

669 {
670  assume( getCoeffType(dst) == n_R );
671 
672  if (src->rep==n_rep_gap_rat) /*Q, Z */
673  {
674  return nrMapQ;
675  }
676  if (src->rep==n_rep_gap_gmp) /*Q, Z */
677  {
678  return nrMapZ;
679  }
680  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
681  {
682  return nrMapLongR;
683  }
684  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
685  {
686  return ndCopyMap;
687  }
688  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
689  {
690  return nrMapP;
691  }
692  if ((src->rep==n_rep_gmp_complex) && nCoeff_is_long_C(src))
693  {
694  return nrMapC;
695  }
696  return NULL;
697 }
static number nrMapP(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:394
static number nrMapZ(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:509
static number nrMapLongR(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:404
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:913
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:858
(), see rinteger.h, new impl.
Definition: coeffs.h:112
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:916
single prescision (6,6) real numbers
Definition: coeffs.h:32
static number nrMapC(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:413
#define assume(x)
Definition: mod2.h:390
(gmp_complex), see gnumpc.h
Definition: coeffs.h:118
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
(number), see longrat.h
Definition: coeffs.h:111
static number nrMapQ(number from, const coeffs r, const coeffs aRing)
Definition: shortfl.cc:424
#define NULL
Definition: omList.c:12
(gmp_float), see
Definition: coeffs.h:117
(int), see modulop.h
Definition: coeffs.h:110
(float), see shortfl.h
Definition: coeffs.h:116

◆ nrSub()

static number nrSub ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 142 of file shortfl.cc.

143 {
144  assume( getCoeffType(r) == n_R );
145 
146  SI_FLOAT x = nf(a).F();
147  SI_FLOAT y = nf(b).F();
148  SI_FLOAT f = x - y;
149  if (x > 0.0)
150  {
151  if (y > 0.0)
152  {
153  x = f / (x + y);
154  if (x < 0.0)
155  x = -x;
156  if (x < nrEps)
157  f = 0.0;
158  }
159  }
160  else
161  {
162  if (y < 0.0)
163  {
164  x = f / (x + y);
165  if (x < 0.0)
166  x = -x;
167  if (x < nrEps)
168  f = 0.0;
169  }
170  }
171  return nf(f).N();
172 }
#define SI_FLOAT
Definition: shortfl.h:15
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
CanonicalForm b
Definition: cfModGcd.cc:4044
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
SI_FLOAT F() const
Definition: gnumpfl.cc:32
Variable x
Definition: cfModGcd.cc:4023
static const SI_FLOAT nrEps
Definition: shortfl.cc:38
number N() const
Definition: gnumpfl.cc:33

◆ nrWrite()

static void nrWrite ( number  a,
const coeffs  r 
)
static

Definition at line 248 of file shortfl.cc.

249 {
250  assume( getCoeffType(r) == n_R );
251 
252  //#if SIZEOF_DOUBLE == SIZEOF_LONG
253  //char ch[16];
254  //int n = sprintf(ch,"%12.6e", nf(a).F());
255  //#else
256  char ch[11];
257  int n = sprintf(ch,"%9.3e", nf(a).F());
258  //#endif
259  if (ch[0] == '-')
260  {
261  char* chbr = new char[n+3];
262  memcpy(&chbr[2],&ch[1],n-1);
263  chbr[0] = '-';
264  chbr[1] = '(';
265  chbr[n+1] = ')';
266  chbr[n+2] = '\0';
267  StringAppendS(chbr);
268  delete[] chbr;
269  }
270  else
271  StringAppend("(%s)",ch);
272 }
Definition: gnumpfl.cc:26
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:390
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:79
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421

Variable Documentation

◆ nrEps

const SI_FLOAT nrEps = 1.0e-3
static

Definition at line 38 of file shortfl.cc.