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 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()

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

Definition at line 141 of file shortfl.cc.

142 {
143  assume( getCoeffType(r) == n_R );
144 
145  float x = nf(a).F();
146  float y = nf(b).F();
147  float f = x + y;
148  if (x > 0.0)
149  {
150  if (y < 0.0)
151  {
152  x = f / (x - y);
153  if (x < 0.0)
154  x = -x;
155  if (x < nrEps)
156  f = 0.0;
157  }
158  }
159  else
160  {
161  if (y > 0.0)
162  {
163  x = f / (y - x);
164  if (x < 0.0)
165  x = -x;
166  if (x < nrEps)
167  f = 0.0;
168  }
169  }
170  return nf(f).N();
171 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
const poly a
Definition: syzextra.cc:212
f
Definition: cfModGcd.cc:4022
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static const float nrEps
Definition: shortfl.cc:57
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63
Variable x
Definition: cfModGcd.cc:4023
const poly b
Definition: syzextra.cc:213
number N() const
Definition: gnumpfl.cc:64

§ nrCoeffString()

static char* nrCoeffString ( const coeffs  r)
static

Definition at line 725 of file shortfl.cc.

726 {
727  return omStrDup("real");
728 }
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ nrCoeffWrite()

void nrCoeffWrite ( const coeffs  r,
BOOLEAN   
)

Definition at line 81 of file shortfl.cc.

82 {
83  assume( getCoeffType(r) == n_R );
84  PrintS("// characteristic : 0 (real)\n"); /* R */
85 }
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425

§ nrDBTest() [1/2]

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

§ nrDBTest() [2/2]

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

Definition at line 412 of file shortfl.cc.

413 {
414  assume( getCoeffType(r) == n_R );
415 
416  return TRUE;
417 }
#define TRUE
Definition: auxiliary.h:98
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425

§ nrDiv()

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

Definition at line 230 of file shortfl.cc.

231 {
232  assume( getCoeffType(r) == n_R );
233 
234  float n = nf(b).F();
235  if (n == 0.0)
236  {
237  WerrorS(nDivBy0);
238  return nf((float)0.0).N();
239  }
240  else
241  return nf(nf(a).F() / n).N();
242 }
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425
float F() const
Definition: gnumpfl.cc:63
const poly b
Definition: syzextra.cc:213
number N() const
Definition: gnumpfl.cc:64

§ nrEqual()

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

Definition at line 271 of file shortfl.cc.

272 {
273  assume( getCoeffType(r) == n_R );
274 
275  number x = nrSub(a,b,r);
276  return nf(x).F() == nf((float)0.0).F();
277 }
const poly a
Definition: syzextra.cc:212
number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:173
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63
Variable x
Definition: cfModGcd.cc:4023
const poly b
Definition: syzextra.cc:213

§ nrFloat()

float nrFloat ( number  n)

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

Definition at line 75 of file shortfl.cc.

76 {
77  return nf(n).F();
78 }
Definition: gnumpfl.cc:57
float F() const
Definition: gnumpfl.cc:63

§ nrGreater()

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

Definition at line 264 of file shortfl.cc.

265 {
266  assume( getCoeffType(r) == n_R );
267 
268  return nf(a).F() > nf(b).F();
269 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63
const poly b
Definition: syzextra.cc:213

§ nrGreaterZero()

BOOLEAN nrGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 88 of file shortfl.cc.

89 {
90  assume( getCoeffType(r) == n_R );
91 
92  return nf(k).F() >= 0.0;
93 }
int k
Definition: cfEzgcd.cc:93
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63

§ nrInit()

number nrInit ( long  i,
const coeffs  r 
)

Definition at line 105 of file shortfl.cc.

106 {
107  assume( getCoeffType(r) == n_R );
108 
109  float f = (float)i;
110  return nf(nf(f).F()).N();
111 }
f
Definition: cfModGcd.cc:4022
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
number N() const
Definition: gnumpfl.cc:64

§ nrInitChar()

BOOLEAN nrInitChar ( coeffs  n,
void *  p 
)

Initialize r.

Definition at line 730 of file shortfl.cc.

731 {
732  assume( getCoeffType(n) == n_R );
733 
734  assume( p == NULL );
735 
736  n->is_field=TRUE;
737  n->is_domain=TRUE;
738  n->rep=n_rep_float;
739 
740  //n->cfKillChar = ndKillChar; /* dummy */
741  n->ch = 0;
742  n->cfCoeffString = nrCoeffString;
743 
744  n->cfInit = nrInit;
745  n->cfInt = nrInt;
746  n->cfAdd = nrAdd;
747  n->cfSub = nrSub;
748  n->cfMult = nrMult;
749  n->cfDiv = nrDiv;
750  n->cfExactDiv= nrDiv;
751  n->cfInpNeg = nrNeg;
752  n->cfInvers= nrInvers;
753  //n->cfCopy = ndCopy;
754  n->cfGreater = nrGreater;
755  n->cfEqual = nrEqual;
756  n->cfIsZero = nrIsZero;
757  n->cfIsOne = nrIsOne;
758  n->cfIsMOne = nrIsMOne;
759  n->cfGreaterZero = nrGreaterZero;
760  n->cfWriteLong = nrWrite;
761  n->cfRead = nrRead;
762  //n->cfPower = nrPower;
763  n->cfSetMap = nrSetMap;
764  n->cfCoeffWrite = nrCoeffWrite;
765 
766  /* nName= ndName; */
767  /*nSize = ndSize;*/
768 #ifdef LDEBUG
769  //n->cfDBTest=ndDBTest; // not yet implemented: nrDBTest;
770 #endif
771 
772  //n->nCoeffIsEqual = ndCoeffIsEqual;
773 
774  n->float_len = SHORT_REAL_LENGTH;
775  n->float_len2 = SHORT_REAL_LENGTH;
776 
777  // TODO: Any variables?
778  return FALSE;
779 }
BOOLEAN nrGreaterZero(number k, const coeffs r)
Definition: shortfl.cc:88
number nrMult(number a, number b, const coeffs r)
Definition: shortfl.cc:95
BOOLEAN nrEqual(number a, number b, const coeffs r)
Definition: shortfl.cc:271
#define SHORT_REAL_LENGTH
Definition: numbers.h:54
#define FALSE
Definition: auxiliary.h:94
number nrSub(number a, number b, const coeffs r)
Definition: shortfl.cc:173
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:98
number nrDiv(number a, number b, const coeffs r)
Definition: shortfl.cc:230
single prescision (6,6) real numbers
Definition: coeffs.h:32
const char * nrRead(const char *s, number *a, const coeffs r)
Definition: shortfl.cc:341
number nrAdd(number a, number b, const coeffs r)
Definition: shortfl.cc:141
void nrWrite(number a, const coeffs r)
Definition: shortfl.cc:279
#define assume(x)
Definition: mod2.h:394
BOOLEAN nrIsMOne(number a, const coeffs r)
Definition: shortfl.cc:221
number nrInvers(number c, const coeffs r)
Definition: shortfl.cc:244
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:694
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
number nrInit(long i, const coeffs r)
Definition: shortfl.cc:105
void nrCoeffWrite(const coeffs r, BOOLEAN)
Definition: shortfl.cc:81
#define NULL
Definition: omList.c:10
BOOLEAN nrIsOne(number a, const coeffs r)
Definition: shortfl.cc:212
static char * nrCoeffString(const coeffs r)
Definition: shortfl.cc:725
number nrNeg(number c, const coeffs r)
Definition: shortfl.cc:257
long nrInt(number &n, const coeffs r)
Definition: shortfl.cc:116
BOOLEAN nrIsZero(number a, const coeffs r)
Definition: shortfl.cc:205
BOOLEAN nrGreater(number a, number b, const coeffs r)
Definition: shortfl.cc:264
(float), see shortfl.h
Definition: coeffs.h:116

§ nrInt()

long nrInt ( number &  n,
const coeffs  r 
)

Definition at line 116 of file shortfl.cc.

117 {
118  assume( getCoeffType(r) == n_R );
119 
120  long i;
121  float f = nf(n).F();
122  if (((float)(-MAX_INT_VAL-1) <= f) || ((float)MAX_INT_VAL >= f))
123  i = (long)f;
124  else
125  i = 0;
126  return i;
127 }
f
Definition: cfModGcd.cc:4022
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63

§ nrInvers()

number nrInvers ( number  c,
const coeffs  r 
)

Definition at line 244 of file shortfl.cc.

245 {
246  assume( getCoeffType(r) == n_R );
247 
248  float n = nf(c).F();
249  if (n == 0.0)
250  {
251  WerrorS(nDivBy0);
252  return nf((float)0.0).N();
253  }
254  return nf(1.0 / n).N();
255 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425
float F() const
Definition: gnumpfl.cc:63
number N() const
Definition: gnumpfl.cc:64

§ nrIsMOne()

BOOLEAN nrIsMOne ( number  a,
const coeffs  r 
)

Definition at line 221 of file shortfl.cc.

222 {
223  assume( getCoeffType(r) == n_R );
224 
225  float aa=nf(a).F()+1.0;
226  if (aa<0.0) aa=-aa;
227  return (aa<nrEps);
228 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static const float nrEps
Definition: shortfl.cc:57
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63

§ nrIsOne()

BOOLEAN nrIsOne ( number  a,
const coeffs  r 
)

Definition at line 212 of file shortfl.cc.

213 {
214  assume( getCoeffType(r) == n_R );
215 
216  float aa=nf(a).F()-1.0;
217  if (aa<0.0) aa=-aa;
218  return (aa<nrEps);
219 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static const float nrEps
Definition: shortfl.cc:57
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63

§ nrIsZero()

BOOLEAN nrIsZero ( number  a,
const coeffs  r 
)

Definition at line 205 of file shortfl.cc.

206 {
207  assume( getCoeffType(r) == n_R );
208 
209  return (0.0 == nf(a).F());
210 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425

§ nrMapC()

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

Definition at line 439 of file shortfl.cc.

440 {
441  assume( getCoeffType(r) == n_R );
442  assume( getCoeffType(aRing) == n_long_C );
443 
444  gmp_float h = ((gmp_complex*)from)->real();
445  float t =(float)mpf_get_d((mpf_srcptr)&h);
446  return nf(t).N();
447 }
gmp_complex numbers based on
Definition: mpr_complex.h:178
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425
static Poly * h
Definition: janet.cc:978
number N() const
Definition: gnumpfl.cc:64

§ nrMapLongR()

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

Definition at line 430 of file shortfl.cc.

431 {
432  assume( getCoeffType(r) == n_R );
433  assume( getCoeffType(aRing) == n_long_R );
434 
435  float t =(float)mpf_get_d((mpf_srcptr)from);
436  return nf(t).N();
437 }
real floating point (GMP) numbers
Definition: coeffs.h:34
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
number N() const
Definition: gnumpfl.cc:64

§ nrMapP()

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

Definition at line 420 of file shortfl.cc.

421 {
422  assume( getCoeffType(r) == n_R );
423  assume( getCoeffType(aRing) == n_Zp );
424 
425  int i = (int)((long)from);
426  float f = (float)i;
427  return nf(f).N();
428 }
f
Definition: cfModGcd.cc:4022
{p < 2^31}
Definition: coeffs.h:30
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
number N() const
Definition: gnumpfl.cc:64

§ nrMapQ()

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

Definition at line 450 of file shortfl.cc.

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

§ nrMapZ()

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

Definition at line 535 of file shortfl.cc.

536 {
537  assume( getCoeffType(r) == n_R );
538  assume( aRing->rep == n_rep_gap_gmp );
539 
540  mpz_ptr z;
541  mpz_ptr zz=NULL;
542  if (IS_IMM(from))
543  {
544  zz=(mpz_ptr)omAlloc(sizeof(mpz_t));
545  mpz_init_set_si(zz,SR_TO_INT(from));
546  z=zz;
547  }
548  else
549  {
550  /* read out the enumerator */
551  z=(mpz_ptr)from;
552  }
553 
554  int i = mpz_size1(z);
555  mpf_t e;
556  mpf_init(e);
557  mpf_set_z(e,z);
558  int sign= mpf_sgn(e);
559  mpf_abs (e, e);
560 
561  if (zz!=NULL)
562  {
563  mpz_clear(zz);
564  omFreeSize(zz,sizeof(mpz_t));
565  }
566  if(i>4)
567  {
568  WerrorS("float overflow");
569  return nf(0.0).N();
570  }
571  double basis;
572  signed long int exp;
573  basis = mpf_get_d_2exp(&exp, e);
574  float f= sign*ldexp(basis,exp);
575  mpf_clear(e);
576  return nf(f).N();
577 }
f
Definition: cfModGcd.cc:4022
#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:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
#define SR_TO_INT(SR)
Definition: longrat.h:70
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:10
p exp[i]
Definition: DebugPrint.cc:39
number N() const
Definition: gnumpfl.cc:64
static int sign(int x)
Definition: ring.cc:3328
#define IS_IMM(A)

§ nrMult()

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

Definition at line 95 of file shortfl.cc.

96 {
97  assume( getCoeffType(r) == n_R );
98 
99  return nf(nf(a).F() * nf(b).F()).N();
100 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
const poly b
Definition: syzextra.cc:213
number N() const
Definition: gnumpfl.cc:64

§ nrNeg()

number nrNeg ( number  c,
const coeffs  r 
)

Definition at line 257 of file shortfl.cc.

258 {
259  assume( getCoeffType(r) == n_R );
260 
261  return nf(-nf(c).F()).N();
262 }
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
number N() const
Definition: gnumpfl.cc:64

§ nrPower()

void nrPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)

§ nrRead()

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

Definition at line 341 of file shortfl.cc.

342 {
343 
344  assume( getCoeffType(r) == n_R );
345 
346  static const char *nIllegalChar="illegal character in number";
347 
348  const char *t;
349  const char *start=s;
350  float z1,z2;
351  float n=1.0;
352 
353  s = nrEatr(s, &z1);
354  if (*s == '/')
355  {
356  if (s==start) { WerrorS(nIllegalChar);return s; }
357  s++;
358  s = nrEatr(s, &z2);
359  if (z2==0.0)
360  WerrorS(nDivBy0);
361  else
362  z1 /= z2;
363  }
364  else if (*s =='.')
365  {
366  if (s==start) { WerrorS(nIllegalChar);return s; }
367  s++;
368  t = s;
369  while (*t >= '0' && *t <= '9')
370  {
371  t++;
372  n *= 10.0;
373  }
374  s = nrEatr(s, &z2);
375  z1 = (z1*n + z2) / n;
376  if (*s=='e')
377  {
378  int e=0; /* exponent */
379  int si=1;/* sign of exponent */
380  s++;
381  if (*s=='+') s++;
382  else if (*s=='-') {s++; si=-1; }
383  while (*s >= '0' && *s <= '9')
384  {
385  e=e*10+(*s)-'0';
386  s++;
387  }
388  if (si==1)
389  {
390  while (e>0) {z1*=10.0; e--; }
391  }
392  else
393  {
394  while (e>0) {z1/=10.0; e--; }
395  }
396  }
397  }
398  *a = nf(z1).N();
399  return s;
400 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425
number N() const
Definition: gnumpfl.cc:64

§ nrSetMap()

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 694 of file shortfl.cc.

695 {
696  assume( getCoeffType(dst) == n_R );
697 
698  if (src->rep==n_rep_gap_rat) /*Q, Z */
699  {
700  return nrMapQ;
701  }
702  if (src->rep==n_rep_gap_gmp) /*Q, Z */
703  {
704  return nrMapZ;
705  }
706  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
707  {
708  return nrMapLongR;
709  }
710  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
711  {
712  return ndCopyMap;
713  }
714  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
715  {
716  return nrMapP;
717  }
718  if ((src->rep==n_rep_gmp_complex) && nCoeff_is_long_C(src))
719  {
720  return nrMapC;
721  }
722  return NULL;
723 }
static number nrMapP(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:420
number nrMapZ(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:535
static number nrMapLongR(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:430
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:834
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:244
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:908
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:853
(), see rinteger.h, new impl.
Definition: coeffs.h:112
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:911
single prescision (6,6) real numbers
Definition: coeffs.h:32
static number nrMapC(number from, const coeffs aRing, const coeffs r)
Definition: shortfl.cc:439
#define assume(x)
Definition: mod2.h:394
(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:425
number nrMapQ(number from, const coeffs r, const coeffs aRing)
Definition: shortfl.cc:450
(number), see longrat.h
Definition: coeffs.h:111
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:117
(int), see modulop.h
Definition: coeffs.h:110
(float), see shortfl.h
Definition: coeffs.h:116

§ nrSize()

int nrSize ( number  n,
const coeffs   
)

Definition at line 129 of file shortfl.cc.

130 {
131  float f = nf(n).F();
132  int i = (int)f;
133  /* basically return the largest integer in n;
134  only if this happens to be zero although n != 0,
135  return 1;
136  (this code ensures that zero has the size zero) */
137  if ((f != 0.0) & (i == 0)) i = 1;
138  return i;
139 }
f
Definition: cfModGcd.cc:4022
Definition: gnumpfl.cc:57
int i
Definition: cfEzgcd.cc:123
float F() const
Definition: gnumpfl.cc:63

§ nrSub()

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

Definition at line 173 of file shortfl.cc.

174 {
175  assume( getCoeffType(r) == n_R );
176 
177  float x = nf(a).F();
178  float y = nf(b).F();
179  float f = x - y;
180  if (x > 0.0)
181  {
182  if (y > 0.0)
183  {
184  x = f / (x + y);
185  if (x < 0.0)
186  x = -x;
187  if (x < nrEps)
188  f = 0.0;
189  }
190  }
191  else
192  {
193  if (y < 0.0)
194  {
195  x = f / (x + y);
196  if (x < 0.0)
197  x = -x;
198  if (x < nrEps)
199  f = 0.0;
200  }
201  }
202  return nf(f).N();
203 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
const poly a
Definition: syzextra.cc:212
f
Definition: cfModGcd.cc:4022
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
static const float nrEps
Definition: shortfl.cc:57
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:425
float F() const
Definition: gnumpfl.cc:63
Variable x
Definition: cfModGcd.cc:4023
const poly b
Definition: syzextra.cc:213
number N() const
Definition: gnumpfl.cc:64

§ nrWrite()

void nrWrite ( number  a,
const coeffs  r 
)

Definition at line 279 of file shortfl.cc.

280 {
281  assume( getCoeffType(r) == n_R );
282 
283  char ch[11];
284  int n = sprintf(ch,"%9.3e", nf(a).F());
285  if (ch[0] == '-')
286  {
287  char* chbr = new char[n+3];
288  memcpy(&chbr[2],&ch[1],n-1);
289  chbr[0] = '-';
290  chbr[1] = '(';
291  chbr[n+1] = ')';
292  chbr[n+2] = '\0';
293  StringAppendS(chbr);
294  delete chbr;
295  }
296  else
297  StringAppend("(%s)",ch);
298 }
const poly a
Definition: syzextra.cc:212
Definition: gnumpfl.cc:57
single prescision (6,6) real numbers
Definition: coeffs.h:32
#define assume(x)
Definition: mod2.h:394
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:425

Variable Documentation

§ nrEps

const float nrEps = 1.0e-3
static

Definition at line 57 of file shortfl.cc.