[genius] Wed Dec 07 01:40:42 2011 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Wed Dec 07 01:40:42 2011 Jiri (George) Lebl <jirka 5z com>
- Date: Wed, 7 Dec 2011 07:40:59 +0000 (UTC)
commit f88fb97c691e63613052925e6ac98b724dae0627
Author: Jiri (George) Lebl <jirka 5z com>
Date: Wed Dec 7 01:40:51 2011 -0600
Wed Dec 07 01:40:42 2011 Jiri (George) Lebl <jirka 5z com>
* src/mpwrap.c: fix roots of negative numbers when numerator of power
is positive. Also fix exact roots when power is negative.
* src/geniustests.txt: add tests for above
ChangeLog | 7 ++++++
src/geniustests.txt | 9 ++++++++
src/mpwrap.c | 55 +++++++++++++++++++++++++++++++++++++++-----------
3 files changed, 59 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9748a71..5b91133 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Dec 07 01:40:42 2011 Jiri (George) Lebl <jirka 5z com>
+
+ * src/mpwrap.c: fix roots of negative numbers when numerator of power
+ is positive. Also fix exact roots when power is negative.
+
+ * src/geniustests.txt: add tests for above
+
Fri Nov 18 00:53:09 2011 Jiri (George) Lebl <jirka 5z com>
* src/symbolic.c: accept log instead of ln for natural log when doing
diff --git a/src/geniustests.txt b/src/geniustests.txt
index ff26a38..65698e8 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1081,6 +1081,15 @@ j=0;(for n=1 to 20 do (for d=1 to 20 do (if n!=(sum r in ColumnsOf(MacaulayRep(n
MacaulayRep(27,3) [6,4,1;3,2,1]
MacaulayBound(27,3) 46
MacaulayLowerOperator(27,3) 13
+(-8)^(1/3) -2
+(-1/8)^(1/3) -1/2
+(-2)^(1/3) -1.25992104989
+(-8)^(-1/3) -1/2
+(-1/8)^(-1/3) -2
+(-2)^(-1/3) -0.793700525984
+(-8)^(-2/3) 1/4
+(-1/8)^(-2/3) 4
+(-2)^(-2/3) 0.629960524947
load "nullspacetest.gel" true
load "longtest.gel" true
load "testprec.gel" true
diff --git a/src/mpwrap.c b/src/mpwrap.c
index 72758ac..363aa70 100644
--- a/src/mpwrap.c
+++ b/src/mpwrap.c
@@ -1815,12 +1815,25 @@ mpwl_pow_q(MpwRealNum *rop,MpwRealNum *op1,MpwRealNum *op2)
GET_INIT_MPZ (z);
if (mpz_root (z, op1->data.ival, den) != 0) {
- mympz_pow_z (z, z,
- mpq_numref (op2->data.rval));
- mpwl_clear (rop);
- rop->type = MPW_INTEGER;
- memcpy (rop->data.ival, z,
- sizeof (__mpz_struct));
+ mpz_ptr num = mpq_numref (op2->data.rval);
+ if (mpz_sgn (num) < 0) {
+ mpz_neg (num, num);
+ mympz_pow_z (z, z, num);
+ mpz_neg (num, num);
+ mpwl_clear (rop);
+ rop->type = MPW_RATIONAL;
+ mpq_init (rop->data.rval);
+ mpq_set_z (rop->data.rval, z);
+ mpq_inv (rop->data.rval,
+ rop->data.rval);
+ CLEAR_FREE_MPZ (z);
+ } else {
+ mympz_pow_z (z, z, num);
+ mpwl_clear (rop);
+ rop->type = MPW_INTEGER;
+ memcpy (rop->data.ival, z,
+ sizeof (__mpz_struct));
+ }
return FALSE;
}
@@ -1835,15 +1848,31 @@ mpwl_pow_q(MpwRealNum *rop,MpwRealNum *op1,MpwRealNum *op2)
mpz_root (mpq_denref (q),
mpq_denref (op1->data.rval),
den) != 0) {
- mympz_pow_z (mpq_numref (q), mpq_numref (q),
- mpq_numref (op2->data.rval));
- mympz_pow_z (mpq_denref (q), mpq_denref (q),
- mpq_numref (op2->data.rval));
+ mpz_ptr num = mpq_numref (op2->data.rval);
+ if (mpz_sgn (num) < 0) {
+ mpz_neg (num, num);
+ mympz_pow_z (mpq_numref (q),
+ mpq_numref (q),
+ num);
+ mympz_pow_z (mpq_denref (q),
+ mpq_denref (q),
+ num);
+ mpz_neg (num, num);
+ mpq_inv (q, q);
+ } else {
+ mympz_pow_z (mpq_numref (q),
+ mpq_numref (q),
+ num);
+ mympz_pow_z (mpq_denref (q),
+ mpq_denref (q),
+ num);
+ }
mpwl_clear (rop);
rop->type = MPW_RATIONAL;
memcpy (rop->data.rval, q,
sizeof (__mpq_struct));
- mpq_canonicalize (rop->data.rval);
+ // the below does mpq_canonicalize
+ mpwl_make_int (rop);
return FALSE;
}
@@ -1864,7 +1893,9 @@ mpwl_pow_q(MpwRealNum *rop,MpwRealNum *op1,MpwRealNum *op2)
mpfr_neg (op1_f, op1_f, GMP_RNDN);
mpfr_pow (r.data.fval, op1_f, op2_f, GMP_RNDN);
mpfr_neg (op1_f, op1_f, GMP_RNDN);
- mpfr_neg (r.data.fval, r.data.fval, GMP_RNDN);
+ if (mpz_odd_p (mpq_numref(op2->data.rval))) {
+ mpfr_neg (r.data.fval, r.data.fval, GMP_RNDN);
+ }
} else {
mpfr_pow (r.data.fval, op1_f, op2_f, GMP_RNDN);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]