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!");
486 WerrorS(
"Can not map from field C to field R!");
490 WerrorS(
"Ground field not implemented!");
502 int sign= (in[0] ==
'-') ? 1 : 0;
508 sign ? strcpy(csign,
"-") : strcpy(csign,
"+");
511 sign ? strcpy(csign,
"-") : strcpy(csign,
" ");
515 sign ? strcpy(csign,
"-") : strcpy(csign,
"");
519 if ( strlen(in) == 0 )
521 *size= 2*
sizeof(char);
525 if ( ((
unsigned int)
ABS(exponent) <= oprec)
528 if ( exponent+sign < (
int)strlen(in) )
530 int eexponent= (exponent >= 0) ? 0 : -exponent;
531 int eeexponent= (exponent >= 0) ? exponent : 0;
532 *size= (strlen(in)+15+eexponent) *
sizeof(
char);
537 strncat(out,in+sign,eeexponent);
541 else if ( exponent > 0 )
546 memset(out+strlen(out),
'0',eexponent);
548 strcat(out,in+sign+eeexponent);
550 else if ( exponent+sign > (
int)strlen(in) )
552 *size= (strlen(in)+exponent+12)*
sizeof(
char);
555 sprintf(out,
"%s%s",csign,in+sign);
556 memset(out+strlen(out),
'0',exponent-strlen(in)+sign);
560 *size= (strlen(in)+2) *
sizeof(
char) + 10;
563 sprintf(out,
"%s%s",csign,in+sign);
571 while ( exponent / d > 0 )
576 *size= (strlen(in)+12+c) *
sizeof(
char) + 10;
579 sprintf(out,
"%s0.%se%s%d",csign,in+sign,exponent>=0?
"+":
"",(
int)exponent);
598 insize= (oprec+2) *
sizeof(
char) + 10;
601 mpf_get_str(in,&exponent,10,oprec,*(r.
mpfp()));
604 && (exponent < (
int)oprec)
605 && (strlen(in)-(in[0]==
'-'?1:0) == oprec) )
608 insize= (exponent+oprec+2) *
sizeof(
char) + 10;
610 int newprec= exponent+oprec;
611 mpf_get_str(in,&exponent,10,newprec,*(r.
mpfp()));
615 out= (
char*)
omAlloc( (strlen(nout)+1) *
sizeof(char) );
622 char *out= (
char*)
omAlloc( (1024) *
sizeof(char) );
623 sprintf(out,
"% .10f",(
double)r);
643 a.
r * b.
i + a.
i * b.
r);
649 (a.
i * b.
r - a.
r * b.
i) / d);
669 i =
r * b.
i +
i * b.
r;
682 r = (
r * b.
r +
i * b.
i) / d;
683 i = (
i * b.
r -
r * b.
i) / d;
719 const char * complex_parameter =
"I";
725 N = strlen(complex_parameter);
730 char *out,*in_imag,*in_real;
741 int len=(strlen(in_real)+strlen(in_imag)+7+
N)*
sizeof(
char);
745 sprintf(out,
"(%s%s%s*%s)",in_real,c.
imag().
sign()>=0?
"+":
"-",complex_parameter,in_imag);
749 sprintf(out,
"%s", complex_parameter);
751 sprintf(out,
"-%s", complex_parameter);
753 sprintf(out,
"(%s%s*%s)",c.
imag().
sign()>=0?
"":
"-", complex_parameter,in_imag);
758 int len=(strlen(in_real)+strlen(in_imag)+9) *
sizeof(
char);
762 sprintf(out,
"(%s%s%s)",in_real,c.
imag().
sign()>=0?
"+I*":
"-I*",in_imag);
764 sprintf(out,
"(%s%s)",c.
imag().
sign()>=0?
"I*":
"-I*",in_imag);
766 omFree( (
void *) in_real );
767 omFree( (
void *) in_imag );
782 if ( digits < 1 )
return true;
784 eps=
pow(10.0,(
int)digits);
792 return (c->
real() < eps && (c->
imag() < eps && c->
imag() > epsm));
794 return (c->
real() > epsm && (c->
imag() < eps && c->
imag() > epsm));
804 mpf_set_prec(*ar.
_mpfp(), 32);
805 mpf_set_prec(*ai.
_mpfp(), 32);
809 if (ai < *gmpRel) this->
imag(0.0);
814 if (ar < *gmpRel) this->
real(0.0);
const mpf_t * mpfp() const
bool operator==(const gmp_float &a, const gmp_float &b)
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)
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
#define omFreeSize(addr, size)
gmp_float operator+(const gmp_float &a, const gmp_float &b)
gmp_float log(const gmp_float &a)
void setFromStr(const char *in)
void WerrorS(const char *s)
gmp_complex numbers based on
bool complexNearZero(gmp_complex *c, int digits)
gmp_float operator*(const gmp_float &a, const gmp_float &b)
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)
gmp_float 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)
bool operator<(const gmp_float &a, const gmp_float &b)
gmp_float cos(const gmp_float &a)
gmp_float & operator-=(const gmp_float &a)
void nlNormalize(number &x, const coeffs r)
gmp_float operator-(const gmp_float &a, const gmp_float &b)
gmp_complex & operator/=(const gmp_complex &a)
bool operator>=(const gmp_float &a, const gmp_float &b)
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)
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...
bool operator>(const gmp_float &a, const gmp_float &b)
Rational pow(const Rational &a, int e)
gmp_float sin(const gmp_float &a)
bool operator<=(const gmp_float &a, const gmp_float &b)