34 #define SR_HDL(A) ((long)(A)) 35 #define SR_TO_INT(SR) (((long)SR) >> 2) 43 #define DEFPREC 20 // minimum number of digits (output operations) 64 size_t bits = 1 + (size_t) ((
float)digits * 3.5);
65 size_t rb = 1 + (size_t) ((
float)rest * 3.5);
68 mpf_set_default_prec( db );
71 mpf_set_prec(*diff->
_mpfp(),32);
74 mpf_set_prec(*gmpRel->
_mpfp(),32);
75 mpf_set_d(*gmpRel->
_mpfp(),0.1);
76 mpf_pow_ui(*gmpRel->
_mpfp(),*gmpRel->
_mpfp(),digits);
83 if (*in ==
'-') { in++; neg=
TRUE; }
85 if ((s=strchr((
char *)in,
'E')) !=
NULL)
94 int len = strlen(in)+2;
95 char* c_in = (
char*)
omAlloc(len);
97 strcpy(&(c_in[1]), in);
99 if(mpf_set_str(
t, c_in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
104 if(mpf_set_str(
t, in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
106 if (neg) mpf_neg(
t,
t );
114 if (*in ==
'-') { in++; neg=
TRUE; }
116 if ((s=strchr(in,
'E')) !=
NULL)
123 if (E_found ||((s=strchr(in,
'e')) !=
NULL))
125 if ((*(s+1)!=
'+') && (*(s+1)!=
'-'))
127 int len = strlen(in)+3;
128 char* c_in = (
char*)
omAlloc(len);
132 strcpy(&(c_in[1]), in);
138 char * ss=strchr(c_in,
'e');
139 memmove(ss+2,s+1,strlen(s+1));
142 mpf_set_str(
t, c_in, 10 );
151 int len = strlen(in)+2;
152 char* c_in = (
char*)
omAlloc(len);
154 strcpy(&(c_in[1]), in);
156 mpf_set_str(
t, c_in, 10 );
161 mpf_set_str(
t, in, 10 );
163 if (neg) mpf_neg(
t,
t );
197 if (mpf_sgn(
t) != -(mpf_sgn(a.
t)))
202 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
207 mpf_add(
t,
t, a.
t );
209 mpf_set_prec(diff->
t, 32);
210 mpf_div(diff->
t, diff->
t, a.
t);
211 mpf_abs(diff->
t, diff->
t);
212 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
218 if (mpf_sgn(
t) != mpf_sgn(a.
t))
223 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
228 mpf_sub(
t,
t, a.
t );
230 mpf_set_prec(diff->
t, 32);
231 mpf_div(diff->
t, diff->
t, a.
t);
232 mpf_abs(diff->
t, diff->
t);
233 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
241 if(mpf_sgn(a.
t) != mpf_sgn(b.
t))
243 if((mpf_sgn(a.
t)==0) && (mpf_sgn(b.
t)==0))
245 mpf_sub(diff->
t, a.
t, b.
t);
246 mpf_div(diff->
t, diff->
t, a.
t);
247 mpf_abs(diff->
t, diff->
t);
248 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
256 return (mpf_sgn(
t ) == 0);
262 return (mpf_cmp_ui(
t , 1 ) == 0);
266 mpf_sub_ui(diff->
t,
t, 1);
267 mpf_abs(diff->
t, diff->
t);
268 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
278 return (mpf_cmp_si(
t , -1 ) == 0);
282 mpf_add_ui(diff->
t,
t, 1);
283 mpf_abs(diff->
t, diff->
t);
284 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
294 return mpf_cmp( a.
t, b.
t ) > 0;
300 return mpf_cmp( a.
t, b.
t ) < 0;
306 return mpf_cmp( a.
t, b.
t ) >= 0;
312 return mpf_cmp( a.
t, b.
t ) <= 0;
353 return (
sqrt( (a*a) + (b*b) ) );
367 a > b ? tmp= a : tmp=
b;
430 WerrorS(
"Ground field not implemented!");
434 WerrorS(
"Ground field not implemented!");
475 WerrorS(
"Can not map from field C to field R!");
479 WerrorS(
"Ground field not implemented!");
491 int sign= (in[0] ==
'-') ? 1 : 0;
497 sign ? strcpy(csign,
"-") : strcpy(csign,
"+");
500 sign ? strcpy(csign,
"-") : strcpy(csign,
" ");
504 sign ? strcpy(csign,
"-") : strcpy(csign,
"");
508 if ( strlen(in) == 0 )
510 *size= 2*
sizeof(char);
514 if ( ((
unsigned int)
ABS(exponent) <= oprec)
517 if ( exponent+sign < (
int)strlen(in) )
519 int eexponent= (exponent >= 0) ? 0 : -exponent;
520 int eeexponent= (exponent >= 0) ? exponent : 0;
521 *size= (strlen(in)+15+eexponent) *
sizeof(
char);
526 strncat(out,in+sign,eeexponent);
530 else if ( exponent > 0 )
535 memset(out+strlen(out),
'0',eexponent);
537 strcat(out,in+sign+eeexponent);
539 else if ( exponent+sign > (
int)strlen(in) )
541 *size= (strlen(in)+exponent+12)*
sizeof(
char);
544 sprintf(out,
"%s%s",csign,in+sign);
545 memset(out+strlen(out),
'0',exponent-strlen(in)+sign);
549 *size= (strlen(in)+2) *
sizeof(
char) + 10;
552 sprintf(out,
"%s%s",csign,in+sign);
560 while ( exponent / d > 0 )
565 *size= (strlen(in)+12+c) *
sizeof(
char) + 10;
568 sprintf(out,
"%s0.%se%s%d",csign,in+sign,exponent>=0?
"+":
"",(
int)exponent);
587 insize= (oprec+2) *
sizeof(
char) + 10;
590 mpf_get_str(in,&exponent,10,oprec,*(r.
mpfp()));
604 out= (
char*)
omAlloc( (strlen(nout)+1) *
sizeof(char) );
611 char *out= (
char*)
omAlloc( (1024) *
sizeof(char) );
612 sprintf(out,
"% .10f",(
double)r);
632 a.
r * b.
i + a.
i * b.
r);
638 (a.
i * b.
r - a.
r * b.
i) / d);
658 i =
r * b.
i +
i * b.
r;
671 r = (
r * b.
r +
i * b.
i) / d;
672 i = (
i * b.
r -
r * b.
i) / d;
708 const char * complex_parameter =
"I";
714 N = strlen(complex_parameter);
719 char *out,*in_imag,*in_real;
730 int len=(strlen(in_real)+strlen(in_imag)+7+
N)*
sizeof(
char);
734 sprintf(out,
"(%s%s%s*%s)",in_real,c.
imag().
sign()>=0?
"+":
"-",complex_parameter,in_imag);
738 sprintf(out,
"%s", complex_parameter);
740 sprintf(out,
"-%s", complex_parameter);
742 sprintf(out,
"(%s%s*%s)",c.
imag().
sign()>=0?
"":
"-", complex_parameter,in_imag);
747 int len=(strlen(in_real)+strlen(in_imag)+9) *
sizeof(
char);
751 sprintf(out,
"(%s%s%s)",in_real,c.
imag().
sign()>=0?
"+I*":
"-I*",in_imag);
753 sprintf(out,
"(%s%s)",c.
imag().
sign()>=0?
"I*":
"-I*",in_imag);
755 omFree( (
void *) in_real );
756 omFree( (
void *) in_imag );
771 if ( digits < 1 )
return true;
773 eps=
pow(10.0,(
int)digits);
781 return (c->
real() < eps && (c->
imag() < eps && c->
imag() > epsm));
783 return (c->
real() > epsm && (c->
imag() < eps && c->
imag() > epsm));
793 mpf_set_prec(*ar.
_mpfp(), 32);
794 mpf_set_prec(*ai.
_mpfp(), 32);
798 if (ai < *gmpRel) this->imag(0.0);
803 if (ar < *gmpRel) this->real(0.0);
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
char * nicifyFloatStr(char *in, mp_exp_t exponent, size_t oprec, int *size, int thesign)
const CanonicalForm int s
gmp_float exp(const gmp_float &a)
friend gmp_float operator/(const gmp_float &a, const gmp_float &b)
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
friend bool operator>=(const gmp_float &a, const gmp_float &b)
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
#define omFreeSize(addr, size)
friend bool operator==(const gmp_float &a, const gmp_float &b)
gmp_float log(const gmp_float &a)
void setFromStr(const char *in)
friend gmp_float operator+(const gmp_float &a, const gmp_float &b)
void WerrorS(const char *s)
gmp_complex numbers based on
bool complexNearZero(gmp_complex *c, int digits)
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
gmp_complex & operator+=(const gmp_complex &a)
friend bool operator>(const gmp_float &a, const gmp_float &b)
Coefficient rings, fields and other domains suitable for Singular polynomials.
const CanonicalForm CFMap CFMap & N
gmp_float numberToFloat(number num, const coeffs src)
The main handler for Singular numbers which are suitable for Singular polynomials.
gmp_float hypot(const gmp_float &a, const gmp_float &b)
gmp_complex & operator-=(const gmp_complex &a)
gmp_float sqrt(const gmp_float &a)
gmp_float abs(const gmp_float &a)
const mpf_t * mpfp() const
gmp_float cos(const gmp_float &a)
gmp_float & operator-=(const gmp_float &a)
friend gmp_float operator-(const gmp_float &a, const gmp_float &b)
void nlNormalize(number &x, const coeffs r)
gmp_complex & operator/=(const gmp_complex &a)
char * floatToStr(const gmp_float &r, const unsigned int oprec)
gmp_float numberFieldToFloat(number num, int k, const coeffs src)
gmp_complex & operator*=(const gmp_complex &a)
static gmp_float * gmpRel
gmp_float & operator+=(const gmp_float &a)
gmp_float max(const gmp_float &a, const gmp_float &b)
friend bool operator<=(const gmp_float &a, const gmp_float &b)
friend gmp_float operator*(const gmp_float &a, const gmp_float &b)
char * complexToStr(gmp_complex &c, const unsigned int oprec, const coeffs src)
int exponent(const CanonicalForm &f, int q)
int exponent ( const CanonicalForm & f, int q )
void setGMPFloatDigits(size_t digits, size_t rest)
Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of...
friend bool operator<(const gmp_float &a, const gmp_float &b)
Rational pow(const Rational &a, int e)
gmp_float sin(const gmp_float &a)