32 #define SR_HDL(A) ((long)(A)) 33 #define SR_TO_INT(SR) (((long)SR) >> 2) 41 #define DEFPREC 20 // minimum number of digits (output operations) 62 size_t bits = 1 + (size_t) ((
float)digits * 3.5);
63 size_t rb = 1 + (size_t) ((
float)rest * 3.5);
66 mpf_set_default_prec( db );
69 mpf_set_prec(*diff->
_mpfp(),32);
72 mpf_set_prec(*gmpRel->
_mpfp(),32);
73 mpf_set_d(*gmpRel->
_mpfp(),0.1);
74 mpf_pow_ui(*gmpRel->
_mpfp(),*gmpRel->
_mpfp(),digits);
81 if (*in ==
'-') { in++; neg=
TRUE; }
83 if ((s=strchr((
char *)in,
'E')) !=
NULL)
92 int len = strlen(in)+2;
93 char* c_in = (
char*)
omAlloc(len);
95 strcpy(&(c_in[1]), in);
97 if(mpf_set_str(
t, c_in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
102 if(mpf_set_str(
t, in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
104 if (neg) mpf_neg(
t,
t );
112 if (*in ==
'-') { in++; neg=
TRUE; }
114 if ((s=strchr(in,
'E')) !=
NULL)
121 if (E_found ||((s=strchr(in,
'e')) !=
NULL))
123 if ((*(s+1)!=
'+') && (*(s+1)!=
'-'))
125 int len = strlen(in)+3;
126 char* c_in = (
char*)
omAlloc(len);
130 strcpy(&(c_in[1]), in);
136 char * ss=strchr(c_in,
'e');
137 memmove(ss+2,s+1,strlen(s+1));
140 mpf_set_str(
t, c_in, 10 );
149 int len = strlen(in)+2;
150 char* c_in = (
char*)
omAlloc(len);
152 strcpy(&(c_in[1]), in);
154 mpf_set_str(
t, c_in, 10 );
159 mpf_set_str(
t, in, 10 );
161 if (neg) mpf_neg(
t,
t );
195 if (mpf_sgn(
t) != -(mpf_sgn(a.
t)))
200 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
205 mpf_add(
t,
t, a.
t );
207 mpf_set_prec(diff->
t, 32);
208 mpf_div(diff->
t, diff->
t, a.
t);
209 mpf_abs(diff->
t, diff->
t);
210 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
216 if (mpf_sgn(
t) != mpf_sgn(a.
t))
221 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
226 mpf_sub(
t,
t, a.
t );
228 mpf_set_prec(diff->
t, 32);
229 mpf_div(diff->
t, diff->
t, a.
t);
230 mpf_abs(diff->
t, diff->
t);
231 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
239 if(mpf_sgn(a.
t) != mpf_sgn(b.
t))
241 if((mpf_sgn(a.
t)==0) && (mpf_sgn(b.
t)==0))
243 mpf_sub(diff->
t, a.
t, b.
t);
244 mpf_div(diff->
t, diff->
t, a.
t);
245 mpf_abs(diff->
t, diff->
t);
246 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
254 return (mpf_sgn(
t ) == 0);
260 return (mpf_cmp_ui(
t , 1 ) == 0);
264 mpf_sub_ui(diff->
t,
t, 1);
265 mpf_abs(diff->
t, diff->
t);
266 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
276 return (mpf_cmp_si(
t , -1 ) == 0);
280 mpf_add_ui(diff->
t,
t, 1);
281 mpf_abs(diff->
t, diff->
t);
282 if(mpf_cmp(diff->
t, gmpRel->
t) < 0)
292 return mpf_cmp( a.
t, b.
t ) > 0;
298 return mpf_cmp( a.
t, b.
t ) < 0;
304 return mpf_cmp( a.
t, b.
t ) >= 0;
310 return mpf_cmp( a.
t, b.
t ) <= 0;
351 return (
sqrt( (a*a) + (b*b) ) );
365 a > b ? tmp= a : tmp=
b;
428 WerrorS(
"Ground field not implemented!");
432 WerrorS(
"Ground field not implemented!");
473 WerrorS(
"Can not map from field C to field R!");
477 WerrorS(
"Ground field not implemented!");
489 int sign= (in[0] ==
'-') ? 1 : 0;
495 sign ? strcpy(csign,
"-") : strcpy(csign,
"+");
498 sign ? strcpy(csign,
"-") : strcpy(csign,
" ");
502 sign ? strcpy(csign,
"-") : strcpy(csign,
"");
506 if ( strlen(in) == 0 )
508 *size= 2*
sizeof(char);
512 if ( ((
unsigned int)
ABS(exponent) <= oprec)
515 if ( exponent+sign < (
int)strlen(in) )
517 int eexponent= (exponent >= 0) ? 0 : -exponent;
518 int eeexponent= (exponent >= 0) ? exponent : 0;
519 *size= (strlen(in)+15+eexponent) *
sizeof(
char);
524 strncat(out,in+sign,eeexponent);
528 else if ( exponent > 0 )
533 memset(out+strlen(out),
'0',eexponent);
535 strcat(out,in+sign+eeexponent);
537 else if ( exponent+sign > (
int)strlen(in) )
539 *size= (strlen(in)+exponent+12)*
sizeof(
char);
542 sprintf(out,
"%s%s",csign,in+sign);
543 memset(out+strlen(out),
'0',exponent-strlen(in)+sign);
547 *size= (strlen(in)+2) *
sizeof(
char) + 10;
550 sprintf(out,
"%s%s",csign,in+sign);
558 while ( exponent / d > 0 )
563 *size= (strlen(in)+12+c) *
sizeof(
char) + 10;
566 sprintf(out,
"%s0.%se%s%d",csign,in+sign,exponent>=0?
"+":
"",(
int)exponent);
585 insize= (oprec+2) *
sizeof(
char) + 10;
588 mpf_get_str(in,&exponent,10,oprec,*(r.
mpfp()));
602 out= (
char*)
omAlloc( (strlen(nout)+1) *
sizeof(char) );
609 char *out= (
char*)
omAlloc( (1024) *
sizeof(char) );
610 sprintf(out,
"% .10f",(
double)r);
630 a.
r * b.
i + a.
i * b.
r);
636 (a.
i * b.
r - a.
r * b.
i) / d);
656 i = r * b.
i +
i * b.
r;
669 r = (r * b.
r +
i * b.
i) / d;
670 i = (
i * b.
r - r * b.
i) / d;
706 const char * complex_parameter =
"I";
712 N = strlen(complex_parameter);
717 char *out,*in_imag,*in_real;
728 int len=(strlen(in_real)+strlen(in_imag)+7+
N)*
sizeof(
char);
732 sprintf(out,
"(%s%s%s*%s)",in_real,c.
imag().
sign()>=0?
"+":
"-",complex_parameter,in_imag);
736 sprintf(out,
"%s", complex_parameter);
738 sprintf(out,
"-%s", complex_parameter);
740 sprintf(out,
"(%s%s*%s)",c.
imag().
sign()>=0?
"":
"-", complex_parameter,in_imag);
745 int len=(strlen(in_real)+strlen(in_imag)+9) *
sizeof(
char);
749 sprintf(out,
"(%s%s%s)",in_real,c.
imag().
sign()>=0?
"+I*":
"-I*",in_imag);
751 sprintf(out,
"(%s%s)",c.
imag().
sign()>=0?
"I*":
"-I*",in_imag);
753 omFree( (
void *) in_real );
754 omFree( (
void *) in_imag );
769 if ( digits < 1 )
return true;
771 eps=
pow(10.0,(
int)digits);
779 return (c->
real() < eps && (c->
imag() < eps && c->
imag() > epsm));
781 return (c->
real() > epsm && (c->
imag() < eps && c->
imag() > epsm));
791 mpf_set_prec(*ar.
_mpfp(), 32);
792 mpf_set_prec(*ai.
_mpfp(), 32);
796 if (ai < *gmpRel) this->imag(0.0);
801 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 numberFieldToFloat(number num, int cf)
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_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)