genius r742 - in trunk: . src
- From: jirka svn gnome org
- To: svn-commits-list gnome org
- Subject: genius r742 - in trunk: . src
- Date: Fri, 27 Feb 2009 20:49:58 +0000 (UTC)
Author: jirka
Date: Fri Feb 27 20:49:58 2009
New Revision: 742
URL: http://svn.gnome.org/viewvc/genius?rev=742&view=rev
Log:
Fri Feb 27 14:42:12 2009 Jiri (George) Lebl <jirka 5z com>
* src/mpwrap.[ch], src/funclib.c: remove the dependence on the MPF
compat layer. Inline a few more functions. Implement mpwl_eql
to make comparisons of rationals quicker. Remove certain old
gmp/mpfr bug workarounds, a bit of cleanup
* src/matop.c: in the mul_sub_row, cache the tmp variable for
greater speed.
Modified:
trunk/ChangeLog
trunk/src/funclib.c
trunk/src/matop.c
trunk/src/mpwrap.c
trunk/src/mpwrap.h
Modified: trunk/src/funclib.c
==============================================================================
--- trunk/src/funclib.c (original)
+++ trunk/src/funclib.c Fri Feb 27 20:49:58 2009
@@ -1322,7 +1322,7 @@
MPW_MPF_REAL (num, a[0]->val.value, tmp);
- mpf_init (ret);
+ mpfr_init (ret);
mpfr_erf (ret, num, GMP_RNDN);
MPW_MPF_KILL (num, tmp);
@@ -1360,7 +1360,7 @@
MPW_MPF_REAL (num, a[0]->val.value, tmp);
- mpf_init (ret);
+ mpfr_init (ret);
mpfr_zeta (ret, num, GMP_RNDN);
MPW_MPF_KILL (num, tmp);
@@ -1397,7 +1397,7 @@
MPW_MPF_REAL (num, a[0]->val.value, tmp);
- mpf_init (ret);
+ mpfr_init (ret);
mpfr_gamma (ret, num, GMP_RNDN);
MPW_MPF_KILL (num, tmp);
Modified: trunk/src/matop.c
==============================================================================
--- trunk/src/matop.c (original)
+++ trunk/src/matop.c Fri Feb 27 20:49:58 2009
@@ -341,31 +341,37 @@
mul_sub_row (GelCtx *ctx, GelMatrixW *m, int row, mpw_t mul, int row2)
{
int i, w;
- mpw_t tmp;
+ static mpw_t tmp;
+ static gboolean tmp_inited = FALSE;
gboolean ret = TRUE;
/* no need for this, only used within gauss and matrix is already private
gel_matrixw_make_private(m);*/
- mpw_init(tmp);
+ if G_UNLIKELY ( ! tmp_inited) {
+ mpw_init(tmp);
+ tmp_inited = TRUE;
+ }
w = gel_matrixw_width(m);
for (i = 0; i < w; i++) {
GelETree *t = gel_matrixw_get_index(m,i,row);
if (t && ! mpw_zero_p (t->val.value)) {
GelETree *t2 = gel_matrixw_get_index(m,i,row2);
mpw_mul(tmp,t->val.value,mul);
- if(!t2) {
+ if (t2 == NULL) {
mpw_neg(tmp,tmp);
- gel_matrixw_set_index(m,i,row2) = t2 = gel_makenum_use(tmp);
+ t2 = gel_makenum_use(tmp);
+ gel_matrixw_set_index(m,i,row2) = t2;
mpw_init(tmp);
+ } else if ( ! mpw_is_complex_float (tmp) &&
+ mpw_symbolic_eql (t2->val.value, tmp)) {
+ gel_freetree (t2);
+ gel_matrixw_set_index(m,i,row2) = NULL;
} else {
- mpw_sub(t2->val.value,t2->val.value,tmp);
- if (mpw_exact_zero_p (t2->val.value)) {
- gel_freetree (t2);
- gel_matrixw_set_index(m,i,row2) = NULL;
- }
+ mpw_sub (t2->val.value,
+ t2->val.value, tmp);
}
- if (ctx->modulo != NULL) {
+ if (ctx->modulo != NULL && t2 != NULL) {
gel_mod_node (ctx, t2);
/* can't mod so we have a singular matrix / system */
if (t2 != NULL && t2->type != VALUE_NODE)
@@ -373,7 +379,6 @@
}
}
}
- mpw_clear(tmp);
return ret;
}
Modified: trunk/src/mpwrap.c
==============================================================================
--- trunk/src/mpwrap.c (original)
+++ trunk/src/mpwrap.c Fri Feb 27 20:49:58 2009
@@ -47,7 +47,7 @@
MpwErrorFunc errorout;
int error_num;
- int default_mpf_prec;
+ int default_mpfr_prec;
gboolean double_math; /* instead of gmp, use doubles */
gpointer data;
@@ -60,15 +60,15 @@
MpwRealNum *gel_zero = NULL;
MpwRealNum *gel_one = NULL;
-static int default_mpf_prec = 0;
+static int default_mpfr_prec = 0;
#define FREE_LIST_SIZE 1125
static __mpz_struct free_mpz[FREE_LIST_SIZE];
static __mpz_struct *free_mpz_top = free_mpz;
static __mpq_struct free_mpq[FREE_LIST_SIZE];
static __mpq_struct *free_mpq_top = free_mpq;
-static __mpfr_struct free_mpf[FREE_LIST_SIZE];
-static __mpfr_struct *free_mpf_top = free_mpf;
+static __mpfr_struct free_mpfr[FREE_LIST_SIZE];
+static __mpfr_struct *free_mpfr_top = free_mpfr;
#define GET_INIT_MPZ(THE_z) \
if (free_mpz_top == free_mpz) { \
@@ -102,18 +102,18 @@
free_mpq_top++; \
}
#define GET_INIT_MPF(THE_f) \
- if (free_mpf_top == free_mpf) { \
- mpf_init (THE_f); \
+ if (free_mpfr_top == free_mpfr) { \
+ mpfr_init (THE_f); \
} else { \
- free_mpf_top--; \
- memcpy (THE_f, free_mpf_top, sizeof (__mpfr_struct)); \
+ free_mpfr_top--; \
+ memcpy (THE_f, free_mpfr_top, sizeof (__mpfr_struct)); \
}
#define CLEAR_FREE_MPF(THE_f) \
- if (free_mpf_top == &free_mpf[FREE_LIST_SIZE-1]) { \
- mpf_clear (THE_f); \
+ if (free_mpfr_top == &free_mpfr[FREE_LIST_SIZE-1]) { \
+ mpfr_clear (THE_f); \
} else { \
- memcpy (free_mpf_top, THE_f, sizeof (__mpfr_struct)); \
- free_mpf_top++; \
+ memcpy (free_mpfr_top, THE_f, sizeof (__mpfr_struct)); \
+ free_mpfr_top++; \
}
#define MAKE_CPLX_OPS(THE_op,THE_r,THE_i) { \
@@ -131,8 +131,8 @@
}
#define BREAK_CPLX_OPS(THE_op,THE_r,THE_i) { \
if(rop==THE_op) { \
- mpwl_free(THE_i,TRUE); \
- mpwl_free(THE_r,TRUE); \
+ mpwl_clear(THE_i); \
+ mpwl_clear(THE_r); \
} \
}
@@ -170,7 +170,7 @@
#define DEALLOC_MPWL(n) { \
(n)->alloc.usage--; \
if((n)->alloc.usage==0) \
- mpwl_free((n),FALSE); \
+ mpwl_free((n)); \
}
#define ALLOC_MPWL(n) { \
(n)->alloc.usage++; \
@@ -179,7 +179,7 @@
if((n)->i != gel_zero) { \
(n)->i->alloc.usage--; \
if((n)->i->alloc.usage==0) \
- mpwl_free((n)->i,FALSE);\
+ mpwl_free((n)->i); \
(n)->i = gel_zero; \
gel_zero->alloc.usage++; \
} \
@@ -188,7 +188,7 @@
if((n)->r != gel_zero) { \
(n)->r->alloc.usage--; \
if((n)->r->alloc.usage==0) \
- mpwl_free((n)->r,FALSE); \
+ mpwl_free((n)->r); \
(n)->r = gel_zero; \
gel_zero->alloc.usage++; \
} \
@@ -262,11 +262,11 @@
/*make new type and clear the old one*/
static void mpwl_make_same_type(MpwRealNum *op1,MpwRealNum *op2);
-static void mpwl_clear(MpwRealNum *op);
+static inline void mpwl_clear(MpwRealNum *op);
-static void mpwl_init_type(MpwRealNum *op,int type);
+static inline void mpwl_init_type(MpwRealNum *op,int type);
-static void mpwl_free(MpwRealNum *op, int local);
+static inline void mpwl_free(MpwRealNum *op);
static inline int mpwl_sgn (MpwRealNum *op);
static inline int mpwl_zero_p (MpwRealNum *op);
@@ -361,7 +361,9 @@
static int mpwl_cmp_ui(MpwRealNum *op, unsigned long int i);
-static void mpwl_make_int(MpwRealNum *rop);
+static int mpwl_eql(MpwRealNum *op1, MpwRealNum *op2);
+
+static inline void mpwl_make_int(MpwRealNum *rop);
/*make number into a float, this might be neccessary for unprecise
calculations*/
@@ -552,16 +554,18 @@
GET_INIT_MPF (fval);
if (op->type == MPW_INTEGER) {
- mpf_set_z (fval, op->data.ival);
+ mpfr_set_z (fval, op->data.ival, GMP_RNDN);
CLEAR_FREE_MPZ (op->data.ival);
} else /* if(op->type==MPW_RATIONAL) */ {
- mpf_set_q (fval, op->data.rval);
+ mpfr_set_q (fval, op->data.rval, GMP_RNDN);
+#if 0
/* XXX: a hack!!
* get around a mpf_set_q bug*/
if (mpq_sgn (op->data.rval) < 0 &&
- mpf_sgn (fval) > 0) {
- mpf_neg (fval, fval);
+ mpfr_sgn (fval) > 0) {
+ mpfr_neg (fval, fval, GMP_RNDN);
}
+#endif
CLEAR_FREE_MPQ (op->data.rval);
}
op->type = MPW_FLOAT;
@@ -584,7 +588,7 @@
mpwl_make_type(op1,op2->type);
}
-static void
+static inline void
mpwl_clear (MpwRealNum *op)
{
if G_UNLIKELY (op == NULL)
@@ -606,7 +610,7 @@
}
}
-static void
+static inline void
mpwl_init_type(MpwRealNum *op,int type)
{
if G_UNLIKELY (op == NULL)
@@ -630,12 +634,14 @@
}
}
-static void
-mpwl_free(MpwRealNum *op, gboolean local)
+static inline void
+mpwl_free(MpwRealNum *op)
{
- if(!op) return;
+ if G_UNLIKELY (op == NULL)
+ return;
+
mpwl_clear(op);
- if(local) return;
+
/*FIXME: the 2000 should be settable*/
/*if we want to store this so that we don't allocate new one
each time, up to a limit of 2000, unless it was some local
@@ -654,7 +660,7 @@
mpwl_sgn(MpwRealNum *op)
{
switch(op->type) {
- case MPW_FLOAT: return mpf_sgn(op->data.fval);
+ case MPW_FLOAT: return mpfr_sgn(op->data.fval);
case MPW_RATIONAL: return mpq_sgn(op->data.rval);
case MPW_INTEGER: return mpz_sgn(op->data.ival);
}
@@ -688,6 +694,53 @@
}
}
+static gboolean
+mpwl_eql (MpwRealNum *op1, MpwRealNum *op2)
+{
+ int r=0;
+
+ if (op1->type == op2->type) {
+ switch(op1->type) {
+ case MPW_FLOAT:
+ return mpfr_equal_p (op1->data.fval,op2->data.fval);
+ case MPW_RATIONAL:
+ return mpq_equal (op1->data.rval,op2->data.rval);
+ case MPW_INTEGER:
+ return (mpz_cmp (op1->data.ival,op2->data.ival) == 0);
+ }
+ } else {
+ switch (MPWL_MAX_TYPE (op1, op2)) {
+ case MPW_FLOAT:
+ {
+ mpfr_ptr op1_f, op2_f;
+ mpfr_t op1_tmp, op2_tmp;
+ MPWL_MPF (op1_f, op1, op1_tmp);
+ MPWL_MPF (op2_f, op2, op2_tmp);
+ r = mpfr_equal_p (op1_f, op2_f);
+ MPWL_MPF_KILL (op1_f, op1_tmp);
+ MPWL_MPF_KILL (op2_f, op2_tmp);
+ }
+ break;
+ case MPW_RATIONAL:
+ {
+ mpq_ptr op1_q, op2_q;
+ mpq_t op1_tmp, op2_tmp;
+ MPWL_MPQ (op1_q, op1, op1_tmp);
+ MPWL_MPQ (op2_q, op2, op2_tmp);
+ r = mpq_equal (op1_q, op2_q);
+ MPWL_MPQ_KILL (op1_q, op1_tmp);
+ MPWL_MPQ_KILL (op2_q, op2_tmp);
+ }
+ break;
+ /*
+ case MPW_INTEGER:
+ return mpz_cmp(op1->data.ival,op2->data.ival);
+ */
+ }
+ }
+ return r;
+}
+
static int
mpwl_cmp(MpwRealNum *op1, MpwRealNum *op2)
{
@@ -696,7 +749,7 @@
if (op1->type == op2->type) {
switch(op1->type) {
case MPW_FLOAT:
- return mpf_cmp(op1->data.fval,op2->data.fval);
+ return mpfr_cmp(op1->data.fval,op2->data.fval);
case MPW_RATIONAL:
return mpq_cmp(op1->data.rval,op2->data.rval);
case MPW_INTEGER:
@@ -710,7 +763,7 @@
mpfr_t op1_tmp, op2_tmp;
MPWL_MPF (op1_f, op1, op1_tmp);
MPWL_MPF (op2_f, op2, op2_tmp);
- r = mpf_cmp (op1_f, op2_f);
+ r = mpfr_cmp (op1_f, op2_f);
MPWL_MPF_KILL (op1_f, op1_tmp);
MPWL_MPF_KILL (op2_f, op2_tmp);
}
@@ -739,7 +792,7 @@
mpwl_cmp_ui(MpwRealNum *op, unsigned long int i)
{
switch(op->type) {
- case MPW_FLOAT: return mpf_cmp_ui(op->data.fval,i);
+ case MPW_FLOAT: return mpfr_cmp_ui(op->data.fval,i);
case MPW_RATIONAL: return mpq_cmp_ui(op->data.rval,i,1);
case MPW_INTEGER: return mpz_cmp_ui(op->data.ival,i);
}
@@ -751,13 +804,13 @@
{
switch(rop->type) {
case MPW_FLOAT:
- mpf_set_d(rop->data.fval,d);
+ mpfr_set_d (rop->data.fval, d, GMP_RNDN);
break;
case MPW_RATIONAL:
case MPW_INTEGER:
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
- mpf_set_d(rop->data.fval,d);
+ mpfr_set_d (rop->data.fval, d, GMP_RNDN);
break;
}
}
@@ -818,7 +871,7 @@
else if(rop->type==op->type) {
switch(op->type) {
case MPW_FLOAT:
- mpf_set(rop->data.fval,op->data.fval);
+ mpfr_set (rop->data.fval, op->data.fval, GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_set(rop->data.rval,op->data.rval);
@@ -850,7 +903,9 @@
}
switch (op1->type) {
case MPW_FLOAT:
- mpf_add(rop->data.fval,op1->data.fval,op2->data.fval);
+ mpfr_add (rop->data.fval,
+ op1->data.fval, op2->data.fval,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_add(rop->data.rval,op1->data.rval,op2->data.rval);
@@ -929,7 +984,7 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_add_ui(rop->data.fval,op->data.fval,i);
+ mpfr_add_ui (rop->data.fval, op->data.fval, i, GMP_RNDN);
break;
case MPW_RATIONAL:
{
@@ -966,7 +1021,9 @@
}
switch(op1->type) {
case MPW_FLOAT:
- mpf_sub(rop->data.fval,op1->data.fval,op2->data.fval);
+ mpfr_sub (rop->data.fval,
+ op1->data.fval, op2->data.fval,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_sub(rop->data.rval,op1->data.rval,op2->data.rval);
@@ -1046,7 +1103,8 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_sub_ui(rop->data.fval,op->data.fval,i);
+ mpfr_sub_ui (rop->data.fval, op->data.fval, i,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
{
@@ -1078,7 +1136,8 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_ui_sub(rop->data.fval,i,op->data.fval);
+ mpfr_ui_sub (rop->data.fval, i, op->data.fval,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
{
@@ -1116,7 +1175,9 @@
}
switch(op1->type) {
case MPW_FLOAT:
- mpf_mul(rop->data.fval,op1->data.fval,op2->data.fval);
+ mpfr_mul (rop->data.fval,
+ op1->data.fval, op2->data.fval,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_mul(rop->data.rval,op1->data.rval,op2->data.rval);
@@ -1195,7 +1256,7 @@
}
switch(op->type) {
case MPW_FLOAT:
- mpf_mul_ui(rop->data.fval,op->data.fval,i);
+ mpfr_mul_ui (rop->data.fval, op->data.fval, i, GMP_RNDN);
break;
case MPW_RATIONAL:
mpz_mul_ui(mpq_numref(rop->data.rval),
@@ -1227,7 +1288,9 @@
}
switch(op1->type) {
case MPW_FLOAT:
- mpf_div(rop->data.fval,op1->data.fval,op2->data.fval);
+ mpfr_div (rop->data.fval,
+ op1->data.fval, op2->data.fval,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_div(rop->data.rval,op1->data.rval,op2->data.rval);
@@ -1248,7 +1311,7 @@
mpfr_t op1_tmp, op2_tmp;
MPWL_MPF (op1_f, op1, op1_tmp);
MPWL_MPF (op2_f, op2, op2_tmp);
- mpf_div (r.data.fval, op1_f, op2_f);
+ mpfr_div (r.data.fval, op1_f, op2_f, GMP_RNDN);
MPWL_MPF_KILL (op1_f, op1_tmp);
MPWL_MPF_KILL (op2_f, op2_tmp);
}
@@ -1292,7 +1355,8 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_div_ui(rop->data.fval,op->data.fval,i);
+ mpfr_div_ui (rop->data.fval, op->data.fval, i,
+ GMP_RNDN);
break;
case MPW_RATIONAL:
if(rop->type!=MPW_RATIONAL) {
@@ -1331,7 +1395,7 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_ui_div(rop->data.fval,i,op->data.fval);
+ mpfr_ui_div (rop->data.fval, i, op->data.fval, GMP_RNDN);
break;
case MPW_RATIONAL:
if(rop->type!=MPW_RATIONAL) {
@@ -1581,7 +1645,7 @@
switch(op->type) {
case MPW_FLOAT:
- mpf_neg(rop->data.fval,op->data.fval);
+ mpfr_neg (rop->data.fval, op->data.fval, GMP_RNDN);
break;
case MPW_RATIONAL:
mpq_neg(rop->data.rval,op->data.rval);
@@ -1833,10 +1897,10 @@
break;
case MPW_FLOAT:
mpwl_init_type(&r,MPW_FLOAT);
- mpf_pow_ui (r.data.fval, op1->data.fval, e);
+ mpfr_pow_ui (r.data.fval, op1->data.fval, e, GMP_RNDN);
if(reverse)
- mpf_ui_div(r.data.fval,1,r.data.fval);
+ mpfr_ui_div (r.data.fval, 1, r.data.fval, GMP_RNDN);
break;
}
mpwl_move(rop,&r);
@@ -1891,11 +1955,12 @@
break;
case MPW_FLOAT:
mpwl_init_type(&r,MPW_FLOAT);
- mpfr_pow_z(r.data.fval,op1->data.fval,
- op2->data.ival,GMP_RNDN);
+ mpfr_pow_z (r.data.fval, op1->data.fval,
+ op2->data.ival, GMP_RNDN);
if(reverse)
- mpf_ui_div(r.data.fval,1,r.data.fval);
+ mpfr_ui_div (r.data.fval, 1, r.data.fval,
+ GMP_RNDN);
break;
}
mpwl_move(rop,&r);
@@ -2093,7 +2158,7 @@
mpwl_init_type (&r, MPW_FLOAT);
MPWL_MPF (op_f, op, op_tmp);
- mpf_sqrt (r.data.fval, op_f);
+ mpfr_sqrt (r.data.fval, op_f, GMP_RNDN);
MPWL_MPF_KILL (op_f, op_tmp);
}
if (is_complex)
@@ -2309,16 +2374,18 @@
mpwl_init_type (rop, MPW_FLOAT);
}
- mpf_urandomb (rop->data.fval, rand_state, default_mpf_prec);
- if G_UNLIKELY (mpf_sgn (rop->data.fval) < 0) {
+ mpfr_urandomb (rop->data.fval, rand_state);
+#if 0
+ if G_UNLIKELY (mpfr_sgn (rop->data.fval) < 0) {
/* FIXME: GMP/MPFR bug */
- mpf_neg (rop->data.fval, rop->data.fval);
+ mpfr_neg (rop->data.fval, rop->data.fval, GMP_RNDN);
/* FIXME: WHAT THE HELL IS GOING ON! */
- if (mpf_cmp_ui (rop->data.fval, 1L) > 0) {
+ if (mpfr_cmp_ui (rop->data.fval, 1L) > 0) {
gel_errorout ("Can't recover from a GMP problem. Random function "
"is not returning values in [0,1)");
}
}
+#endif
}
static void
@@ -2359,7 +2426,7 @@
mpz_urandomm (rop->data.ival, rand_state, op->data.ival);
}
-static void
+static inline void
mpwl_make_int(MpwRealNum *rop)
{
switch(rop->type) {
@@ -2586,7 +2653,7 @@
mpwl_clear(rop);
mpwl_init_type(rop,MPW_FLOAT);
}
- mpf_set_str(rop->data.fval,s,base);
+ mpfr_set_str (rop->data.fval, s, base, GMP_RNDN);
if (old_locale != NULL) {
setlocale (LC_NUMERIC, old_locale);
@@ -2826,7 +2893,7 @@
mpfr_set_z(fr,num, GMP_RNDN);
p2=str_getstring_f(fr,max_digits,scientific_notation,postfix,
-1 /* chop */);
- mpf_clear(fr);
+ mpfr_clear(fr);
if(strlen(p2)>=strlen(p)) {
g_free(p2);
return p;
@@ -2964,12 +3031,12 @@
CLEAR_FREE_MPZ (tmp2);
}
if (max_digits > 0 && max_digits < digits) {
- mpf_init(fr);
- mpf_set_q(fr,num);
+ mpfr_init (fr);
+ mpfr_set_q (fr, num, GMP_RNDN);
p2=str_getstring_f(fr,max_digits,scientific_notation,
postfix,
float_chop);
- mpf_clear(fr);
+ mpfr_clear(fr);
if(strlen(p2)>=strlen(p)) {
g_free(p2);
return p;
@@ -3033,12 +3100,12 @@
switch(num->type) {
case MPW_RATIONAL:
if(results_as_floats) {
- mpf_init(fr);
- mpf_set_q(fr,num->data.rval);
+ mpfr_init (fr);
+ mpfr_set_q (fr, num->data.rval, GMP_RNDN);
p=str_getstring_f(fr,max_digits,
scientific_notation, postfix,
chop);
- mpf_clear(fr);
+ mpfr_clear(fr);
return p;
}
return str_getstring_q(num->data.rval,
@@ -3050,13 +3117,12 @@
chop);
case MPW_INTEGER:
if(results_as_floats) {
- mpf_init(fr);
- mpf_set_z(fr,num->data.ival);
+ mpfr_init_set_z (fr, num->data.ival, GMP_RNDN);
p=str_getstring_f(fr,max_digits,
scientific_notation,
postfix,
-1 /* never chop an integer */);
- mpf_clear(fr);
+ mpfr_clear(fr);
return p;
}
return str_getstring_z(num->data.ival,max_digits,
@@ -3079,7 +3145,7 @@
mpwl_zero_p ((rop)->i)) { \
(rop)->i->alloc.usage--; \
if ((rop)->i->alloc.usage==0) \
- mpwl_free ((rop)->i, FALSE); \
+ mpwl_free ((rop)->i); \
(rop)->i = gel_zero; \
gel_zero->alloc.usage ++; \
} \
@@ -3094,26 +3160,25 @@
mpw_set_default_prec (unsigned long int prec)
{
__mpfr_struct *p;
- mpf_set_default_prec (prec);
+ mpfr_set_default_prec (prec);
/* whack the mpf cache */
- for (p = free_mpf; p != free_mpf_top; p++) {
- mpf_clear (p);
+ for (p = free_mpfr; p != free_mpfr_top; p++) {
+ mpfr_clear (p);
}
- free_mpf_top = free_mpf;
+ free_mpfr_top = free_mpfr;
- default_mpf_prec = prec;
+ default_mpfr_prec = prec;
}
/*initialize a number*/
+#undef mpw_init
void
mpw_init (mpw_ptr op)
{
- op->r = gel_zero;
- gel_zero->alloc.usage++;
- op->i = gel_zero;
- gel_zero->alloc.usage++;
+ mpw_init_inline(op);
}
+#define mpw_init(op) mpw_init_inline(op)
void
mpw_init_set(mpw_ptr rop, mpw_ptr op)
@@ -3125,14 +3190,7 @@
mpw_uncomplex (rop);
}
-void
-mpw_init_set_no_uncomplex (mpw_ptr rop, mpw_ptr op)
-{
- rop->r = op->r;
- rop->r->alloc.usage++;
- rop->i = op->i;
- rop->i->alloc.usage++;
-}
+#undef mpw_init_set_no_uncomplex
/*clear memory held by number*/
void
@@ -3141,9 +3199,9 @@
op->r->alloc.usage--;
op->i->alloc.usage--;
if(op->r->alloc.usage==0)
- mpwl_free(op->r,FALSE);
+ mpwl_free (op->r);
if(op->i->alloc.usage==0)
- mpwl_free(op->i,FALSE);
+ mpwl_free (op->i);
}
/*make them the same type without loosing information*/
@@ -3207,7 +3265,7 @@
if(rop->r != gel_zero) {
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free (rop->r);
rop->r = gel_zero;
gel_zero->alloc.usage++;
}
@@ -3215,7 +3273,7 @@
if(rop->r != gel_one) {
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free (rop->r);
rop->r = gel_one;
gel_one->alloc.usage++;
}
@@ -3233,7 +3291,7 @@
if(rop->r != gel_zero) {
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free (rop->r);
rop->r = gel_zero;
gel_zero->alloc.usage++;
}
@@ -3241,7 +3299,7 @@
if(rop->r != gel_one) {
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free (rop->r);
rop->r = gel_one;
gel_one->alloc.usage++;
}
@@ -3257,7 +3315,7 @@
MAKE_REAL(rop);
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free(rop->r);
GET_NEW_REAL (rop->r);
rop->r->type = MPW_INTEGER;
rop->r->alloc.usage = 1;
@@ -3270,7 +3328,7 @@
MAKE_REAL(rop);
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free(rop->r);
GET_NEW_REAL (rop->r);
rop->r->type = MPW_RATIONAL;
rop->r->alloc.usage = 1;
@@ -3283,7 +3341,7 @@
MAKE_REAL(rop);
rop->r->alloc.usage--;
if(rop->r->alloc.usage==0)
- mpwl_free(rop->r,FALSE);
+ mpwl_free(rop->r);
GET_NEW_REAL (rop->r);
rop->r->type = MPW_FLOAT;
rop->r->alloc.usage = 1;
@@ -3394,7 +3452,7 @@
mpwl_mul(&t,op->i,op->i);
mpwl_add(rop->r,rop->r,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear(&t);
mpwl_sqrt(rop->r,rop->r);
@@ -3428,7 +3486,7 @@
mpwl_mul(&t,op->i,op->i);
mpwl_add(rop->r,rop->r,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear(&t);
MAKE_REAL (rop);
}
@@ -3617,8 +3675,8 @@
mpwl_add(rop->r,rop->r,&tr);
mpwl_add(rop->i,rop->i,&ti);
- mpwl_free(&tr,TRUE);
- mpwl_free(&ti,TRUE);
+ mpwl_clear(&tr);
+ mpwl_clear(&ti);
mpw_uncomplex(rop);
@@ -3718,8 +3776,8 @@
mpwl_div(rop->i,rop->i,&t2);
- mpwl_free(&t1,TRUE);
- mpwl_free(&t2,TRUE);
+ mpwl_clear(&t1);
+ mpwl_clear(&t2);
mpw_uncomplex(rop);
@@ -3813,8 +3871,8 @@
mpwl_div(rop->i,rop->i,&t2);
- mpwl_free(&t1,TRUE);
- mpwl_free(&t2,TRUE);
+ mpwl_clear (&t1);
+ mpwl_clear (&t2);
mpw_uncomplex(rop);
@@ -4102,8 +4160,8 @@
mpwl_set (&t2, op2->r);
if (mpwl_pow (&t, op1->i, op2->r)) {
- mpwl_free (&t2, TRUE);
- mpwl_free (&t, TRUE);
+ mpwl_clear (&t2);
+ mpwl_clear (&t);
goto backup_mpw_pow;
}
@@ -4137,8 +4195,8 @@
}
}
- mpwl_free (&t2, TRUE);
- mpwl_free (&t, TRUE);
+ mpwl_clear (&t2);
+ mpwl_clear (&t);
} else {
goto backup_mpw_pow;
}
@@ -4261,7 +4319,7 @@
mpwl_sin(&t,i);
mpwl_mul(rop->i,rop->i,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
mpw_uncomplex(rop);
@@ -4341,7 +4399,7 @@
mpw_uncomplex(rop);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
BREAK_CPLX_OPS(op,r,i);
}
@@ -4371,7 +4429,7 @@
mpwl_init_type (&t, MPW_FLOAT);
mpwl_ln2 (&t);
mpwl_div (rop->i, rop->i, &t);
- mpwl_free (&t,TRUE);
+ mpwl_clear (&t);
}
} else {
mpw_t two;
@@ -4400,7 +4458,7 @@
mpwl_init_type (&t, MPW_FLOAT);
mpwl_ln2 (&t);
mpwl_div (rop->i, rop->i, &t);
- mpwl_free (&t,TRUE);
+ mpwl_clear (&t);
return;
}
/* this is stupid, but simple to implement for now */
@@ -4438,7 +4496,7 @@
mpwl_set_d (&t, 10.0);
mpwl_ln (&t, &t);
mpwl_div (rop->i, rop->i, &t);
- mpwl_free (&t,TRUE);
+ mpwl_clear (&t);
}
} else {
mpw_t ten;
@@ -4469,7 +4527,7 @@
mpwl_set_d (&t, 10.0);
mpwl_ln (&t, &t);
mpwl_div (rop->i, rop->i, &t);
- mpwl_free (&t,TRUE);
+ mpwl_clear (&t);
return;
}
/* this is stupid, but simple to implement for now */
@@ -4519,7 +4577,7 @@
mpwl_sinh(&t,i);
mpwl_mul(rop->i,rop->i,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
mpw_uncomplex(rop);
@@ -4564,7 +4622,7 @@
mpwl_sinh(&t,i);
mpwl_mul(rop->i,rop->i,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
mpw_uncomplex(rop);
@@ -4608,7 +4666,7 @@
mpwl_sin(&t,i);
mpwl_mul(rop->i,rop->i,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
mpw_uncomplex(rop);
@@ -4652,7 +4710,7 @@
mpwl_sin(&t,i);
mpwl_mul(rop->i,rop->i,&t);
- mpwl_free(&t,TRUE);
+ mpwl_clear (&t);
mpw_uncomplex(rop);
@@ -4908,13 +4966,17 @@
gboolean
mpw_eql(mpw_ptr op1, mpw_ptr op2)
{
- return (mpwl_cmp(op1->r,op2->r)==0 && mpwl_cmp(op1->i,op2->i)==0);
+ if (MPW_IS_COMPLEX (op1) || MPW_IS_COMPLEX (op2))
+ return (mpwl_eql(op1->r,op2->r) && mpwl_eql(op1->i,op2->i));
+ else
+ return mpwl_eql(op1->r,op2->r);
}
gboolean
mpw_symbolic_eql(mpw_ptr op1, mpw_ptr op2)
{
- /* Here we're assuming that rationals of the form n/1 are now integers */
+ /* Here we're assuming that rationals of the form n/1 are
+ * now integers */
if (op1->r->type == op2->r->type &&
op1->i->type == op2->i->type)
return mpw_eql (op1, op2);
@@ -5373,17 +5435,6 @@
}
gboolean
-mpw_is_complex_integer(mpw_ptr op)
-{
- if (MPW_IS_COMPLEX (op)) {
- return op->r->type == MPW_INTEGER &&
- op->i->type == MPW_INTEGER;
- } else {
- return op->r->type == MPW_INTEGER;
- }
-}
-
-gboolean
mpw_is_rational(mpw_ptr op)
{
if G_UNLIKELY (MPW_IS_COMPLEX (op)) {
@@ -5395,17 +5446,6 @@
}
gboolean
-mpw_is_complex_rational_or_integer(mpw_ptr op)
-{
- if (MPW_IS_COMPLEX (op)) {
- return op->r->type <= MPW_RATIONAL &&
- op->i->type <= MPW_RATIONAL;
- } else {
- return op->r->type <= MPW_RATIONAL;
- }
-}
-
-gboolean
mpw_is_float(mpw_ptr op)
{
if G_UNLIKELY (MPW_IS_COMPLEX (op)) {
@@ -5416,17 +5456,6 @@
return op->r->type == MPW_FLOAT;
}
-gboolean
-mpw_is_complex_float(mpw_ptr op)
-{
- if (MPW_IS_COMPLEX (op)) {
- return op->r->type == MPW_FLOAT ||
- op->i->type == MPW_FLOAT;
- } else {
- return op->r->type == MPW_FLOAT;
- }
-}
-
void
mpw_im(mpw_ptr rop, mpw_ptr op)
{
Modified: trunk/src/mpwrap.h
==============================================================================
--- trunk/src/mpwrap.h (original)
+++ trunk/src/mpwrap.h Fri Feb 27 20:49:58 2009
@@ -30,8 +30,6 @@
/* FIXME: we may need the same as above */
#include <mpfr.h>
-/* FIXME: get rid of mpf usage altogether */
-#include <mpf2mpfr.h>
enum {
@@ -91,10 +89,27 @@
void mpw_set_default_prec(unsigned long int i);
/*initialize a number*/
-void mpw_init(mpw_ptr op);
void mpw_init_set(mpw_ptr rop,mpw_ptr op);
+
+/* Maybe it is overkill to try to keep bin compat? */
+void mpw_init(mpw_ptr op);
+static inline void
+mpw_init_inline (mpw_ptr op)
+{
+ op->r = gel_zero;
+ gel_zero->alloc.usage++;
+ op->i = gel_zero;
+ gel_zero->alloc.usage++;
+}
+#define mpw_init(op) mpw_init_inline(op)
+
/* don't try to decomplexify the number */
-void mpw_init_set_no_uncomplex (mpw_ptr rop, mpw_ptr op);
+#define mpw_init_set_no_uncomplex(rop,op) \
+{ (rop)->r = (op)->r; \
+ (rop)->r->alloc.usage++; \
+ (rop)->i = (op)->i; \
+ (rop)->i->alloc.usage++; }
+
/*clear memory held by number*/
void mpw_clear(mpw_ptr op);
@@ -285,12 +300,20 @@
gboolean mpw_is_complex(mpw_ptr op);
gboolean mpw_is_integer(mpw_ptr op);
-gboolean mpw_is_complex_integer(mpw_ptr op);
gboolean mpw_is_rational(mpw_ptr op);
-gboolean mpw_is_rational_or_integer(mpw_ptr op);
-gboolean mpw_is_complex_rational_or_integer(mpw_ptr op);
gboolean mpw_is_float(mpw_ptr op);
-gboolean mpw_is_complex_float(mpw_ptr op);
+
+#define mpw_is_complex_float(op) \
+ ( ((op)->r->type == MPW_FLOAT) || \
+ (MPW_IS_COMPLEX (op) && ((op)->i->type == MPW_FLOAT)) )
+
+#define mpw_is_complex_rational_or_integer(op) \
+ ( ((op)->r->type <= MPW_RATIONAL) && \
+ ( ! MPW_IS_COMPLEX (op) || ((op)->i->type <= MPW_RATIONAL)) )
+
+#define mpw_is_complex_integer(op) \
+ ( ((op)->r->type == MPW_INTEGER) && \
+ ( ! MPW_IS_COMPLEX (op) || ((op)->i->type == MPW_INTEGER)) )
void mpw_im(mpw_ptr rop, mpw_ptr op);
void mpw_re(mpw_ptr rop, mpw_ptr op);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]