33 #define SR_HDL(A) ((long)(A)) 34 #define SR_TO_INT(SR) (((long)SR) >> 2) 42 #define DEFPREC 20 // minimum number of digits (output operations) 63 size_t bits = 1 + (size_t) ((
float)digits * 3.5);
64 size_t rb = 1 + (size_t) ((
float)rest * 3.5);
67 mpf_set_default_prec( db );
82 if (*in ==
'-') { in++;
neg=
TRUE; }
84 if ((
s=strchr((
char *)in,
'E')) !=
NULL)
93 int len = strlen(in)+2;
94 char* c_in = (
char*)
omAlloc(len);
96 strcpy(&(c_in[1]), in);
98 if(mpf_set_str(
t, c_in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
103 if(mpf_set_str(
t, in, 10 )!=0)
WerrorS(
"syntax error in GMP float");
105 if (
neg) mpf_neg(
t,
t );
113 if (*in ==
'-') { in++;
neg=
TRUE; }
115 if ((
s=strchr(in,
'E')) !=
NULL)
122 if (E_found ||((
s=strchr(in,
'e')) !=
NULL))
124 if ((*(
s+1)!=
'+') && (*(
s+1)!=
'-'))
126 int len = strlen(in)+3;
127 char* c_in = (
char*)
omAlloc(len);
131 strcpy(&(c_in[1]), in);
137 char * ss=strchr(c_in,
'e');
138 memmove(ss+2,
s+1,strlen(
s+1));
141 mpf_set_str(
t, c_in, 10 );
150 int len = strlen(in)+2;
151 char* c_in = (
char*)
omAlloc(len);
153 strcpy(&(c_in[1]), in);
155 mpf_set_str(
t, c_in, 10 );
160 mpf_set_str(
t, in, 10 );
162 if (
neg) mpf_neg(
t,
t );
196 if (mpf_sgn(
t) != -(mpf_sgn(a.
t)))
201 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
206 mpf_add(
t,
t, a.
t );
208 mpf_set_prec(
diff->
t, 32);
217 if (mpf_sgn(
t) != mpf_sgn(a.
t))
222 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
t)==0))
227 mpf_sub(
t,
t, a.
t );
229 mpf_set_prec(
diff->
t, 32);
240 if(mpf_sgn(a.
t) != mpf_sgn(
b.t))
242 if((mpf_sgn(a.
t)==0) && (mpf_sgn(
b.t)==0))
255 return (mpf_sgn(
t ) == 0);
261 return (mpf_cmp_ui(
t , 1 ) == 0);
265 mpf_sub_ui(
diff->
t,
t, 1);
277 return (mpf_cmp_si(
t , -1 ) == 0);
281 mpf_add_ui(
diff->
t,
t, 1);
293 return mpf_cmp( a.
t,
b.t ) > 0;
299 return mpf_cmp( a.
t,
b.t ) < 0;
305 return mpf_cmp( a.
t,
b.t ) >= 0;
311 return mpf_cmp( a.
t,
b.t ) <= 0;
352 return (
sqrt( (a*a) + (
b*
b) ) );
366 a >
b ? tmp= a : tmp=
b;
429 WerrorS(
"Ground field not implemented!");
433 WerrorS(
"Ground field not implemented!");
474 WerrorS(
"Can not map from field C to field R!");
478 WerrorS(
"Ground field not implemented!");
490 int sign= (in[0] ==
'-') ? 1 : 0;
496 sign ? strcpy(csign,
"-") : strcpy(csign,
"+");
499 sign ? strcpy(csign,
"-") : strcpy(csign,
" ");
503 sign ? strcpy(csign,
"-") : strcpy(csign,
"");
507 if ( strlen(in) == 0 )
509 *
size= 2*
sizeof(char);
520 *
size= (strlen(in)+15+eexponent) *
sizeof(
char);
525 strncat(out,in+
sign,eeexponent);
534 memset(out+strlen(out),
'0',eexponent);
536 strcat(out,in+
sign+eeexponent);
543 sprintf(out,
"%s%s",csign,in+
sign);
548 *
size= (strlen(in)+2) *
sizeof(
char) + 10;
551 sprintf(out,
"%s%s",csign,in+
sign);
564 *
size= (strlen(in)+12+c) *
sizeof(
char) + 10;
586 insize= (oprec+2) *
sizeof(
char) + 10;
603 out= (
char*)
omAlloc( (strlen(nout)+1) *
sizeof(char) );
610 char *out= (
char*)
omAlloc( (1024) *
sizeof(char) );
611 sprintf(out,
"% .10f",(
double)r);
631 a.
r *
b.i + a.
i *
b.r);
637 (a.
i *
b.r - a.
r *
b.i) / d);
657 i =
r *
b.i +
i *
b.r;
670 r = (
r *
b.r +
i *
b.i) / d;
671 i = (
i *
b.r -
r *
b.i) / d;
707 const char * complex_parameter =
"I";
713 N = strlen(complex_parameter);
718 char *out,*in_imag,*in_real;
729 int len=(strlen(in_real)+strlen(in_imag)+7+
N)*
sizeof(
char);
733 sprintf(out,
"(%s%s%s*%s)",in_real,c.
imag().
sign()>=0?
"+":
"-",complex_parameter,in_imag);
737 sprintf(out,
"%s", complex_parameter);
739 sprintf(out,
"-%s", complex_parameter);
741 sprintf(out,
"(%s%s*%s)",c.
imag().
sign()>=0?
"":
"-", complex_parameter,in_imag);
746 int len=(strlen(in_real)+strlen(in_imag)+9) *
sizeof(
char);
750 sprintf(out,
"(%s%s%s)",in_real,c.
imag().
sign()>=0?
"+I*":
"-I*",in_imag);
752 sprintf(out,
"(%s%s)",c.
imag().
sign()>=0?
"I*":
"-I*",in_imag);
754 omFree( (
void *) in_real );
755 omFree( (
void *) in_imag );
770 if ( digits < 1 )
return true;
772 eps=
pow(10.0,(
int)digits);
780 return (c->
real() < eps && (c->
imag() < eps && c->
imag() > epsm));
782 return (c->
real() > epsm && (c->
imag() < eps && c->
imag() > epsm));
792 mpf_set_prec(*ar.
_mpfp(), 32);
793 mpf_set_prec(*ai.
_mpfp(), 32);
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)
const mpf_t * mpfp() const
bool operator<(const gmp_float &a, const gmp_float &b)
gmp_float cos(const gmp_float &a)
gmp_float numberFieldToFloat(number num, int cf)
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_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)