summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-21 06:56:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-21 06:56:22 -0700
commite399295ee017de3fe490c4c952701c95baa019e9 (patch)
treef5f606edf36cae22f409bc3847619ba71034c6af
parentff8a6cce170ecb6c523b6c59a865946f402226b5 (diff)
downloadtxr-e399295ee017de3fe490c4c952701c95baa019e9.tar.gz
txr-e399295ee017de3fe490c4c952701c95baa019e9.tar.bz2
txr-e399295ee017de3fe490c4c952701c95baa019e9.zip
* arith.c (plus): Minor code simplification.
(minus): Floating point support. * mpi-patches/mpi-to-double (mp_to_double): Re-apply lost bugfix: index incremented instead of decremented. Didn't refresh patch last time, then did a make distclean.
-rw-r--r--ChangeLog9
-rw-r--r--arith.c129
-rw-r--r--mpi-patches/mpi-to-double10
3 files changed, 87 insertions, 61 deletions
diff --git a/ChangeLog b/ChangeLog
index d0d773da..2fe03180 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-03-21 Kaz Kylheku <kaz@kylheku.com>
+
+ * arith.c (plus): Minor code simplification.
+ (minus): Floating point support.
+
+ * mpi-patches/mpi-to-double (mp_to_double): Re-apply lost
+ bugfix: index incremented instead of decremented.
+ Didn't refresh patch last time, then did a make distclean.
+
2012-03-20 Kaz Kylheku <kaz@kylheku.com>
Regression fix: 1..3 scans incorrectly into 1. .3 tokens.
diff --git a/arith.c b/arith.c
index 09529b43..f2f033ea 100644
--- a/arith.c
+++ b/arith.c
@@ -294,10 +294,7 @@ tail:
return normalize(n);
}
case FLNUM:
- {
- cnum a = c_num(anum);
- return flo((double) a + c_flo(bnum));
- }
+ return flo((double) c_num(anum) + c_flo(bnum));
default:
break;
}
@@ -326,10 +323,7 @@ tail:
return normalize(n);
}
case FLNUM:
- {
- cnum b = c_num(bnum);
- return flo((double) b + c_flo(anum));
- }
+ return flo((double) c_num(bnum) + c_flo(anum));
default:
break;
}
@@ -388,10 +382,8 @@ char_range:
val minus(val anum, val bnum)
{
- int tag_a = tag(anum);
- int tag_b = tag(bnum);
-
- switch (TAG_PAIR(tag_a, tag_b)) {
+tail:
+ switch (TAG_PAIR(tag(anum), tag(bnum))) {
case TAG_PAIR(TAG_NUM, TAG_NUM):
case TAG_PAIR(TAG_CHR, TAG_CHR):
{
@@ -404,56 +396,81 @@ val minus(val anum, val bnum)
return num_fast(sum);
}
case TAG_PAIR(TAG_NUM, TAG_PTR):
- {
- val n;
- type_check(bnum, BGNUM);
- n = make_bignum();
- if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
- cnum a = c_num(anum);
- cnum ap = ABS(a);
- if (ap > 0)
- mp_sub_d(mp(bnum), ap, mp(n));
- else
- mp_add_d(mp(bnum), ap, mp(n));
- mp_neg(mp(n), mp(n));
- } else {
- mp_int tmp;
- mp_init(&tmp);
- mp_set_intptr(&tmp, c_num(anum));
- mp_sub(mp(bnum), &tmp, mp(n));
- mp_clear(&tmp);
+ switch (type(bnum)) {
+ case BGNUM:
+ {
+ val n;
+ n = make_bignum();
+ if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
+ cnum a = c_num(anum);
+ cnum ap = ABS(a);
+ if (ap > 0)
+ mp_sub_d(mp(bnum), ap, mp(n));
+ else
+ mp_add_d(mp(bnum), ap, mp(n));
+ mp_neg(mp(n), mp(n));
+ } else {
+ mp_int tmp;
+ mp_init(&tmp);
+ mp_set_intptr(&tmp, c_num(anum));
+ mp_sub(mp(bnum), &tmp, mp(n));
+ mp_clear(&tmp);
+ }
+ return normalize(n);
}
- return normalize(n);
+ case FLNUM:
+ return flo((double) c_num(anum) - c_flo(bnum));
+ default:
+ break;
}
case TAG_PAIR(TAG_PTR, TAG_NUM):
- {
- val n;
- type_check(anum, BGNUM);
- n = make_bignum();
- if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
- cnum b = c_num(bnum);
- cnum bp = ABS(b);
- if (b > 0)
- mp_sub_d(mp(anum), bp, mp(n));
- else
- mp_add_d(mp(anum), bp, mp(n));
- } else {
- mp_int tmp;
- mp_init(&tmp);
- mp_set_intptr(&tmp, c_num(bnum));
- mp_sub(mp(anum), &tmp, mp(n));
- mp_clear(&tmp);
+ switch (type(anum)) {
+ case BGNUM:
+ {
+ val n;
+ n = make_bignum();
+ if (sizeof (int_ptr_t) <= sizeof (mp_digit)) {
+ cnum b = c_num(bnum);
+ cnum bp = ABS(b);
+ if (b > 0)
+ mp_sub_d(mp(anum), bp, mp(n));
+ else
+ mp_add_d(mp(anum), bp, mp(n));
+ } else {
+ mp_int tmp;
+ mp_init(&tmp);
+ mp_set_intptr(&tmp, c_num(bnum));
+ mp_sub(mp(anum), &tmp, mp(n));
+ mp_clear(&tmp);
+ }
+ return normalize(n);
}
- return normalize(n);
+ case FLNUM:
+ return flo(c_flo(anum) - (double) c_num(bnum));
+ default:
+ break;
}
case TAG_PAIR(TAG_PTR, TAG_PTR):
- {
- val n;
- type_check(anum, BGNUM);
- type_check(bnum, BGNUM);
- n = make_bignum();
- mp_sub(mp(anum), mp(bnum), mp(n));
- return normalize(n);
+ switch (TYPE_PAIR(type(anum), type(bnum))) {
+ case TYPE_PAIR(BGNUM, BGNUM):
+ {
+ val n;
+ type_check(anum, BGNUM);
+ type_check(bnum, BGNUM);
+ n = make_bignum();
+ mp_sub(mp(anum), mp(bnum), mp(n));
+ return normalize(n);
+ }
+ case TYPE_PAIR(FLNUM, FLNUM):
+ return flo(c_flo(anum) - c_flo(bnum));
+ case TYPE_PAIR(BGNUM, FLNUM):
+ anum = flo_int(anum);
+ goto tail;
+ case TYPE_PAIR(FLNUM, BGNUM):
+ bnum = flo_int(bnum);
+ goto tail;
+ default:
+ break;
}
case TAG_PAIR(TAG_CHR, TAG_NUM):
{
diff --git a/mpi-patches/mpi-to-double b/mpi-patches/mpi-to-double
index 653d612c..608e9dc3 100644
--- a/mpi-patches/mpi-to-double
+++ b/mpi-patches/mpi-to-double
@@ -1,7 +1,7 @@
Index: mpi-1.8.6/mpi.c
===================================================================
---- mpi-1.8.6.orig/mpi.c 2012-03-20 20:23:46.604727758 -0700
-+++ mpi-1.8.6/mpi.c 2012-03-20 20:37:28.514792258 -0700
+--- mpi-1.8.6.orig/mpi.c 2012-03-20 22:20:10.242815758 -0700
++++ mpi-1.8.6/mpi.c 2012-03-21 06:48:36.401050757 -0700
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <string.h>
@@ -25,7 +25,7 @@ Index: mpi-1.8.6/mpi.c
+ if (!mult)
+ mult = pow(2.0, MP_DIGIT_BIT);
+
-+ for (ix = (int) used - 2; ix >= 0; ix++) {
++ for (ix = (int) used - 2; ix >= 0; ix--) {
+ out = out * mult;
+ out += (double) dp[ix];
+ }
@@ -42,8 +42,8 @@ Index: mpi-1.8.6/mpi.c
Index: mpi-1.8.6/mpi.h
===================================================================
---- mpi-1.8.6.orig/mpi.h 2012-03-20 20:23:39.184556258 -0700
-+++ mpi-1.8.6/mpi.h 2012-03-20 20:25:30.018865508 -0700
+--- mpi-1.8.6.orig/mpi.h 2012-03-20 22:20:09.994676258 -0700
++++ mpi-1.8.6/mpi.h 2012-03-20 22:20:10.498959758 -0700
@@ -187,6 +187,11 @@
#endif /* end MP_NUMTH */